' . esc_html__( 'Settings', 'devlab-open-graph' ) . '' ); return $links; } /** * Adds the settings screen under the shared "DevLab" top-level menu, * creating that menu when no other DevLab plugin has done it yet. * * @return void */ public function register_menu() { if ( ! $this->devlab_menu_exists() ) { add_menu_page( __( 'DevLab', 'devlab-open-graph' ), __( 'DevLab', 'devlab-open-graph' ), 'manage_options', 'devlab', array( $this, 'render_page' ), 'dashicons-shield-alt', 80 ); $this->owns_parent_menu = true; } $this->hook_suffix = (string) add_submenu_page( 'devlab', __( 'Open Graph & Social Cards', 'devlab-open-graph' ), __( 'Open Graph', 'devlab-open-graph' ), 'manage_options', self::PAGE_SLUG, array( $this, 'render_page' ) ); } /** * Removes the duplicate "DevLab" sub-item that WordPress adds to a new * top-level menu. Runs after the sub-item exists, and only when this * plugin created the menu. * * @return void */ public function cleanup_parent_menu() { if ( $this->owns_parent_menu ) { remove_submenu_page( 'devlab', 'devlab' ); } } /** * Whether another DevLab plugin already registered the top-level menu. * * @return bool */ private function devlab_menu_exists() { global $menu; if ( ! is_array( $menu ) ) { return false; } foreach ( $menu as $item ) { if ( isset( $item[2] ) && 'devlab' === $item[2] ) { return true; } } return false; } /** * Whether the screen being displayed is this plugin's settings screen. * * When this plugin created the shared top-level menu, that menu's own * address shows the same screen, so it counts too. * * @param string $hook_suffix Current admin page hook suffix. * @return bool */ private function is_plugin_screen( $hook_suffix ) { if ( '' === $this->hook_suffix ) { return false; } if ( $this->hook_suffix === $hook_suffix ) { return true; } return $this->owns_parent_menu && 'toplevel_page_devlab' === $hook_suffix; } /** * Whether the one-time notice should be shown to the current user. * * @return bool */ private function notice_is_visible() { return current_user_can( 'manage_options' ) && ! get_user_meta( get_current_user_id(), self::NOTICE_META, true ); } /** * Loads the CSS and JS on this plugin's screen only. * * @param string $hook_suffix Current admin page hook suffix. * @return void */ public function enqueue_assets( $hook_suffix ) { if ( ! $this->is_plugin_screen( $hook_suffix ) ) { return; } // The media library modal powers the "Choose image" button. if ( current_user_can( 'upload_files' ) ) { wp_enqueue_media(); } wp_enqueue_style( 'devlab-og-admin', DEVLAB_OG_URL . 'assets/css/admin.css', array(), DEVLAB_OG_VERSION ); wp_enqueue_script( 'devlab-og-admin', DEVLAB_OG_URL . 'assets/js/admin.js', array(), DEVLAB_OG_VERSION, true ); wp_localize_script( 'devlab-og-admin', 'devlabOg', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( self::NOTICE_NONCE ), 'imageMime' => DevLab_OG_Image::allowed_mimes(), 'i18n' => array( 'chooseImage' => __( 'Choose the default image', 'devlab-open-graph' ), 'useImage' => __( 'Use this image', 'devlab-open-graph' ), ), ) ); } /** * Builds a DevLab link with the campaign parameters. * * @param string $content Identifies which link was clicked (utm_content). * @param string $path Optional path on devlab.ia.br, without a leading slash (for example "store"). * @return string Unescaped URL; escape with esc_url() on output. */ public function utm_url( $content, $path = '' ) { return add_query_arg( array( 'utm_source' => 'wporg', 'utm_medium' => 'plugin', 'utm_campaign' => DEVLAB_OG_SLUG, 'utm_content' => $content, ), 'https://devlab.ia.br/' . ltrim( $path, '/' ) ); } /** * Prints the single, dismissible notice. It is a short thank-you with a link * to the author's site, and it is limited to this plugin's own screen. * * @return void */ public function maybe_show_notice() { $screen = get_current_screen(); if ( ! $screen || ! $this->is_plugin_screen( $screen->id ) || ! $this->notice_is_visible() ) { return; } ?>

403 ) ); } $devlab_og_settings = DevLab_OG_Settings::get(); $devlab_og_seo_plugin = DevLab_OG_Compat::active_seo_plugin(); $devlab_og_can_upload = current_user_can( 'upload_files' ); $devlab_og_image = $devlab_og_settings['default_image'] ? DevLab_OG_Image::describe( $devlab_og_settings['default_image'] ) : array(); require DEVLAB_OG_DIR . 'admin/views/settings-page.php'; } }