devlab_menu_exists() ) { $top = add_menu_page( __( 'DevLab', 'devlab-datemark' ), __( 'DevLab', 'devlab-datemark' ), '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', __( 'Datemark', 'devlab-datemark' ), __( 'Datemark', 'devlab-datemark' ), '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-datemark' ) . '' ); 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-lu-admin', DEVLAB_LU_URL . 'assets/css/admin.css', array(), DEVLAB_LU_VERSION ); // The line's own stylesheet, so the preview on this screen looks the // way it will look on the site. wp_enqueue_style( DevLab_LU_Render::STYLE_HANDLE, DEVLAB_LU_URL . 'assets/css/frontend.css', array(), DEVLAB_LU_VERSION ); wp_enqueue_script( 'devlab-lu-admin', DEVLAB_LU_URL . 'assets/js/admin.js', array(), DEVLAB_LU_VERSION, true ); if ( $this->notice_is_visible() ) { wp_localize_script( 'devlab-lu-admin', 'devlabLu', 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). * @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_LU_SLUG, 'utm_content' => $content, ), 'https://devlab.ia.br/' . $path ); } /** * Prints the single, dismissible notice. It is a short thank-you with a * link to the DevLab Store, 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; } ?>

labels->name; } } if ( empty( $names ) ) { return __( 'Automatic insertion is on, but no content type is selected, so no line is added yet.', 'devlab-datemark' ); } $list = implode( ', ', $names ); if ( DevLab_LU_Settings::POSITION_AFTER === $settings['position'] ) { return sprintf( /* translators: %s: comma-separated list of content types, for example "Posts, Pages". */ __( 'The line is added after the content of: %s. It only appears on items edited more than five minutes after they were published.', 'devlab-datemark' ), $list ); } return sprintf( /* translators: %s: comma-separated list of content types, for example "Posts, Pages". */ __( 'The line is added before the content of: %s. It only appears on items edited more than five minutes after they were published.', 'devlab-datemark' ), $list ); } /** * Renders the settings screen. * * @return void */ public function render_page() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You do not have permission to access this page.', 'devlab-datemark' ), '', array( 'response' => 403 ) ); } $devlab_lu_settings = DevLab_LU_Settings::get(); $devlab_lu_types = DevLab_LU_Settings::selectable_post_types(); $devlab_lu_status = $this->describe_status( $devlab_lu_settings, $devlab_lu_types ); // A sample line, built with the saved settings and the current moment, // so the effect of the label and the date format is visible. $devlab_lu_preview = DevLab_LU_Line::render( null, array( 'tag' => 'p', 'timestamp' => time(), ) ); include DEVLAB_LU_DIR . 'admin/views/settings-page.php'; } }