public static is_post_edit ( string $page ) : boolean | ||
$page | string | The page to check for the post edit page. |
리턴 | boolean | Whether or not the given page is the post edit page. |
/** * Class constructor */ function __construct() { global $pagenow; $this->options = WPSEO_Options::get_options(array('wpseo', 'wpseo_permalinks')); if (is_multisite()) { WPSEO_Options::maybe_set_multisite_defaults(false); } if ($this->options['stripcategorybase'] === true) { add_action('created_category', array($this, 'schedule_rewrite_flush')); add_action('edited_category', array($this, 'schedule_rewrite_flush')); add_action('delete_category', array($this, 'schedule_rewrite_flush')); } $this->admin_features = array('google_search_console' => new WPSEO_GSC(), 'dashboard_widget' => new Yoast_Dashboard_Widget()); if (WPSEO_Metabox::is_post_overview($pagenow) || WPSEO_Metabox::is_post_edit($pagenow)) { $this->admin_features['primary_category'] = new WPSEO_Primary_Term_Admin(); } if (filter_input(INPUT_GET, 'page') === 'wpseo_tools' && filter_input(INPUT_GET, 'tool') === null) { new WPSEO_Recalculate_Scores(); } // Needs the lower than default priority so other plugins can hook underneath it without issue. add_action('admin_menu', array($this, 'register_settings_page'), 5); add_action('network_admin_menu', array($this, 'register_network_settings_page')); add_filter('plugin_action_links_' . WPSEO_BASENAME, array($this, 'add_action_link'), 10, 2); add_action('admin_enqueue_scripts', array($this, 'config_page_scripts')); add_action('admin_enqueue_scripts', array($this, 'enqueue_global_style')); if ($this->options['cleanslugs'] === true) { add_filter('name_save_pre', array($this, 'remove_stopwords_from_slug'), 0); } add_filter('user_contactmethods', array($this, 'update_contactmethods'), 10, 1); add_action('after_switch_theme', array($this, 'switch_theme')); add_action('switch_theme', array($this, 'switch_theme')); add_filter('set-screen-option', array($this, 'save_bulk_edit_options'), 10, 3); add_action('admin_init', array('WPSEO_Plugin_Conflict', 'hook_check_for_plugin_conflicts'), 10, 1); add_action('admin_init', array($this, 'import_plugin_hooks')); add_filter('wpseo_submenu_pages', array($this, 'filter_settings_pages')); WPSEO_Sitemaps_Cache::register_clear_on_option_update('wpseo'); if (WPSEO_Utils::is_yoast_seo_page()) { add_action('admin_enqueue_scripts', array($this, 'enqueue_assets')); } if (WPSEO_Utils::is_api_available()) { $configuration = new WPSEO_Configuration_Page(); if (filter_input(INPUT_GET, 'page') === self::PAGE_IDENTIFIER) { $configuration->catch_configuration_request(); } } }
/** * Enqueues all the assets needed for the primary term interface * * @return void */ public function enqueue_assets() { global $pagenow; if (!WPSEO_Metabox::is_post_edit($pagenow)) { return; } $taxonomies = $this->get_primary_term_taxonomies(); // Only enqueue if there are taxonomies that need a primary term. if (empty($taxonomies)) { return; } $asset_manager = new WPSEO_Admin_Asset_Manager(); $asset_manager->enqueue_style('primary-category'); $asset_manager->enqueue_script('primary-category'); $taxonomies = array_map(array($this, 'map_taxonomies_for_js'), $taxonomies); $data = array('taxonomies' => $taxonomies); wp_localize_script(WPSEO_Admin_Asset_Manager::PREFIX . 'primary-category', 'wpseoPrimaryCategoryL10n', $data); }
/** * Adds an SEO admin bar menu with several options. If the current user is an admin he can also go straight to several settings menu's from here. */ function wpseo_admin_bar_menu() { // If the current user can't write posts, this is all of no use, so let's not output an admin menu. if (!current_user_can('edit_posts')) { return; } $options = WPSEO_Options::get_options(array('wpseo', 'wpseo_ms')); if ($options['enable_admin_bar_menu'] !== true) { return; } global $wp_admin_bar, $post; // Determine is user is admin or network admin. $user_is_admin_or_networkadmin = current_user_can('manage_options'); if (!$user_is_admin_or_networkadmin && is_multisite()) { $user_is_admin_or_networkadmin = $options['access'] === 'superadmin' && is_super_admin(); } $focuskw = ''; $score = ''; // By default, the top level menu item has no link. $seo_url = ''; // By default, make the no-link top level menu item focusable. $top_level_link_tabindex = '0'; $analysis_seo = new WPSEO_Metabox_Analysis_SEO(); $analysis_readability = new WPSEO_Metabox_Analysis_Readability(); if ((is_singular() || is_admin() && WPSEO_Metabox::is_post_edit($GLOBALS['pagenow'])) && isset($post) && is_object($post) && apply_filters('wpseo_use_page_analysis', true) === true) { $focuskw = WPSEO_Meta::get_value('focuskw', $post->ID); if ($analysis_seo->is_enabled()) { $score = wpseo_adminbar_seo_score(); } elseif ($analysis_readability->is_enabled()) { $score = wpseo_adminbar_content_score(); } } if (is_category() || is_tag() || WPSEO_Taxonomy::is_term_edit($GLOBALS['pagenow']) && !WPSEO_Taxonomy::is_term_overview($GLOBALS['pagenow']) || is_tax()) { if ($analysis_seo->is_enabled()) { $score = wpseo_tax_adminbar_seo_score(); } elseif ($analysis_readability->is_enabled()) { $score = wpseo_tax_adminbar_content_score(); } } // Never display notifications for network admin. $counter = ''; // Set the top level menu item content for admins and network admins. if ($user_is_admin_or_networkadmin) { // Link the top level menu item to the Yoast Dashboard page. $seo_url = get_admin_url(null, 'admin.php?page=' . WPSEO_Admin::PAGE_IDENTIFIER); // Since admins will get a real link, there's no need for a tabindex attribute. $top_level_link_tabindex = false; if ('' === $score) { // Notification information. $notification_center = Yoast_Notification_Center::get(); $notification_count = $notification_center->get_notification_count(); $new_notifications = $notification_center->get_new_notifications(); $new_notifications_count = count($new_notifications); if ($notification_count > 0) { // Always show Alerts page when clicking on the main link. /* translators: %s: number of notifications */ $counter_screen_reader_text = sprintf(_n('%s notification', '%s notifications', $notification_count, 'wordpress-seo'), number_format_i18n($notification_count)); $counter = sprintf(' <div class="wp-core-ui wp-ui-notification yoast-issue-counter"><span aria-hidden="true">%d</span><span class="screen-reader-text">%s</span></div>', $notification_count, $counter_screen_reader_text); } if ($new_notifications_count) { $notification = sprintf(_n('You have a new issue concerning your SEO!', 'You have %d new issues concerning your SEO!', $new_notifications_count, 'wordpress-seo'), $new_notifications_count); $counter .= '<div class="yoast-issue-added">' . $notification . '</div>'; } } } // Yoast Icon. $icon_svg = WPSEO_Utils::get_icon_svg(); $title = '<div id="yoast-ab-icon" class="ab-item yoast-logo svg" style="background-image: url(\'' . $icon_svg . '\');"><span class="screen-reader-text">' . __('SEO', 'wordpress-seo') . '</span></div>'; $wp_admin_bar->add_menu(array('id' => 'wpseo-menu', 'title' => $title . $score . $counter, 'href' => $seo_url, 'meta' => array('tabindex' => $top_level_link_tabindex))); if (!empty($notification_count)) { $wp_admin_bar->add_menu(array('parent' => 'wpseo-menu', 'id' => 'wpseo-notifications', 'title' => __('Notifications', 'wordpress-seo') . $counter, 'href' => $seo_url, 'meta' => array('tabindex' => $top_level_link_tabindex))); } $wp_admin_bar->add_menu(array('parent' => 'wpseo-menu', 'id' => 'wpseo-kwresearch', 'title' => __('Keyword Research', 'wordpress-seo'), 'meta' => array('tabindex' => '0'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-kwresearch', 'id' => 'wpseo-adwordsexternal', 'title' => __('AdWords External', 'wordpress-seo'), 'href' => 'http://adwords.google.com/keywordplanner', 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-kwresearch', 'id' => 'wpseo-googleinsights', 'title' => __('Google Trends', 'wordpress-seo'), 'href' => 'https://www.google.com/trends/explore#q=' . urlencode($focuskw), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-kwresearch', 'id' => 'wpseo-wordtracker', 'title' => __('SEO Book', 'wordpress-seo'), 'href' => 'http://tools.seobook.com/keyword-tools/seobook/?keyword=' . urlencode($focuskw), 'meta' => array('target' => '_blank'))); if (!is_admin()) { $url = WPSEO_Frontend::get_instance()->canonical(false); if (is_string($url)) { $wp_admin_bar->add_menu(array('parent' => 'wpseo-menu', 'id' => 'wpseo-analysis', 'title' => __('Analyze this page', 'wordpress-seo'), 'meta' => array('tabindex' => '0'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-inlinks-ose', 'title' => __('Check Inlinks (OSE)', 'wordpress-seo'), 'href' => '//moz.com/researchtools/ose/links?site=' . urlencode($url), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-kwdensity', 'title' => __('Check Keyword Density', 'wordpress-seo'), 'href' => 'http://www.zippy.co.uk/keyworddensity/index.php?url=' . urlencode($url) . '&keyword=' . urlencode($focuskw), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-cache', 'title' => __('Check Google Cache', 'wordpress-seo'), 'href' => '//webcache.googleusercontent.com/search?strip=1&q=cache:' . urlencode($url), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-header', 'title' => __('Check Headers', 'wordpress-seo'), 'href' => '//quixapp.com/headers/?r=' . urlencode($url), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-structureddata', 'title' => __('Google Structured Data Test', 'wordpress-seo'), 'href' => 'https://search.google.com/structured-data/testing-tool#url=' . urlencode($url), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-facebookdebug', 'title' => __('Facebook Debugger', 'wordpress-seo'), 'href' => '//developers.facebook.com/tools/debug/og/object?q=' . urlencode($url), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-pinterestvalidator', 'title' => __('Pinterest Rich Pins Validator', 'wordpress-seo'), 'href' => 'https://developers.pinterest.com/tools/url-debugger/?link=' . urlencode($url), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-htmlvalidation', 'title' => __('HTML Validator', 'wordpress-seo'), 'href' => '//validator.w3.org/check?uri=' . urlencode($url), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-cssvalidation', 'title' => __('CSS Validator', 'wordpress-seo'), 'href' => '//jigsaw.w3.org/css-validator/validator?uri=' . urlencode($url), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-pagespeed', 'title' => __('Google Page Speed Test', 'wordpress-seo'), 'href' => '//developers.google.com/speed/pagespeed/insights/?url=' . urlencode($url), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-microsoftedge', 'title' => __('Microsoft Edge Site Scan', 'wordpress-seo'), 'href' => 'https://developer.microsoft.com/en-us/microsoft-edge/tools/staticscan/?url=' . urlencode($url), 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-google-mobile-friendly', 'title' => __('Mobile-Friendly Test', 'wordpress-seo'), 'href' => 'https://www.google.com/webmasters/tools/mobile-friendly/?url=' . urlencode($url), 'meta' => array('target' => '_blank'))); } } // @todo: add links to bulk title and bulk description edit pages. if ($user_is_admin_or_networkadmin) { $wp_admin_bar->add_menu(array('parent' => 'wpseo-menu', 'id' => 'wpseo-settings', 'title' => __('SEO Settings', 'wordpress-seo'), 'meta' => array('tabindex' => '0'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-general', 'title' => __('Dashboard', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_dashboard'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-titles', 'title' => __('Titles & Metas', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_titles'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-social', 'title' => __('Social', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_social'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-xml', 'title' => __('XML Sitemaps', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_xml'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-wpseo-advanced', 'title' => __('Advanced', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_advanced'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-tools', 'title' => __('Tools', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_tools'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-search-console', 'title' => __('Search Console', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_search_console'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-licenses', 'title' => '<span style="color:#f18500">' . __('Extensions', 'wordpress-seo') . '</span>', 'href' => admin_url('admin.php?page=wpseo_licenses'))); } }
/** * Determine whether we should load the meta box class and if so, load it. */ private function load_meta_boxes() { $is_editor = WPSEO_Metabox::is_post_overview($this->pagenow) || WPSEO_Metabox::is_post_edit($this->pagenow); $is_inline_save = filter_input(INPUT_POST, 'action') === 'inline-save'; /** * Filter: 'wpseo_always_register_metaboxes_on_admin' - Allow developers to change whether * the WPSEO metaboxes are only registered on the typical pages (lean loading) or always * registered when in admin. * * @api bool Whether to always register the metaboxes or not. Defaults to false. */ if ($is_editor || $is_inline_save || apply_filters('wpseo_always_register_metaboxes_on_admin', false)) { $GLOBALS['wpseo_metabox'] = new WPSEO_Metabox(); $GLOBALS['wpseo_meta_columns'] = new WPSEO_Meta_Columns(); } }