devlab_menu_exists() ) { $top = add_menu_page( __( 'DevLab', 'devlab-image-alt' ), __( 'DevLab', 'devlab-image-alt' ), 'manage_options', 'devlab', array( $this, 'render_page' ), 'dashicons-shield-alt', 80 ); $this->owns_parent_menu = true; $this->screen_ids[] = (string) $top; } $this->screen_ids[] = (string) add_submenu_page( 'devlab', __( 'Image Alt', 'devlab-image-alt' ), __( 'Image Alt', 'devlab-image-alt' ), '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 shows this plugin's settings page. * * @param string $hook_suffix Current admin page hook suffix. * @return bool */ private function is_plugin_screen( $hook_suffix ) { return '' !== $hook_suffix && in_array( $hook_suffix, $this->screen_ids, true ); } /** * 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 ); } /** * Adds a "Settings" link to this plugin's row on the Plugins screen. * * @param string[] $links Existing action links. * @return string[] */ public function add_action_link( $links ) { $url = add_query_arg( 'page', self::PAGE_SLUG, admin_url( 'admin.php' ) ); array_unshift( $links, '' . esc_html__( 'Settings', 'devlab-image-alt' ) . '' ); return $links; } /** * 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; } wp_enqueue_style( 'devlab-alt-admin', DEVLAB_ALT_URL . 'assets/css/admin.css', array(), DEVLAB_ALT_VERSION ); wp_enqueue_script( 'devlab-alt-admin', DEVLAB_ALT_URL . 'assets/js/admin.js', array(), DEVLAB_ALT_VERSION, true ); if ( $this->notice_is_visible() ) { wp_localize_script( 'devlab-alt-admin', 'devlabAlt', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( self::NOTICE_NONCE ), ) ); } } /** * Builds a DevLab link with the campaign parameters. * * @param string $content Identifies which link was clicked (utm_content). * @return string Unescaped URL; escape with esc_url() on output. */ public function utm_url( $content ) { return add_query_arg( array( 'utm_source' => 'wporg', 'utm_medium' => 'plugin', 'utm_campaign' => DEVLAB_ALT_SLUG, 'utm_content' => $content, ), 'https://devlab.ia.br/store/' ); } /** * Prints the single, dismissible notice. It offers a free resource and 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_alt_settings = DevLab_ALT_Settings::get(); $devlab_alt_sources = DevLab_ALT_Settings::get_sources(); $devlab_alt_status = $this->describe_status( $devlab_alt_settings ); include DEVLAB_ALT_DIR . 'admin/views/settings-page.php'; } }