function wpc_disable_yoast_notifications() { if (is_plugin_active('wordpress-seo/wp-seo.php')) { remove_action('admin_notices', array(Yoast_Notification_Center::get(), 'display_notifications')); remove_action('all_admin_notices', array(Yoast_Notification_Center::get(), 'display_notifications')); } }
/** * Show a notice when the website is not indexable */ public function show_notice() { if ($this->should_show_notice()) { $notice = sprintf(__('%1$sYour homepage cannot be indexed by search engines%2$s. This is very bad for SEO and should be fixed.', 'wordpress-seo'), '<a href="http://yoa.st/onpageindexerror" target="_blank">', '</a>'); Yoast_Notification_Center::get()->add_notification(new Yoast_Notification($notice, array('type' => 'error yoast-dismissible', 'id' => 'wpseo-dismiss-onpageorg', 'nonce' => wp_create_nonce('wpseo-dismiss-onpageorg')))); } }
/** * Singleton getter * * @return Yoast_Notification_Center */ public static function get() { if (null == self::$instance) { self::$instance = new self(); } return self::$instance; }
/** * Creates notification with given $message * * This method will also apply filter for $notification_type to determine if notification has to be shown * * @param string $message * @param string $notification_type * @param string $id */ protected function create_notification($message, $notification_type, $id) { $show_notification = true; $show_notification = apply_filters('wpseo_enable_notification_' . $this->watch_type . '_' . $notification_type, $show_notification); if ($show_notification) { // Add the message to the notifications center. Yoast_Notification_Center::get()->add_notification(new Yoast_Notification($message, array('type' => 'updated', 'id' => $id))); } }
/** * Show a notice when the website is not indexable */ public function show_notice() { $notification = $this->get_indexability_notification(); $notification_center = Yoast_Notification_Center::get(); if ($this->should_show_notice()) { $notification_center->add_notification($notification); } else { $notification_center->remove_notification($notification); } }
/** * Redirect first time or just upgraded users to the about screen. */ public function after_update_notice() { if (current_user_can('manage_options') && !$this->seen_about()) { if (filter_input(INPUT_GET, 'intro') === '1') { update_user_meta(get_current_user_id(), 'wpseo_seen_about_version', WPSEO_VERSION); return; } $info_message = sprintf(__('WordPress SEO by Yoast has been updated to version %1$s. %2$sClick here%3$s to find out what\'s new!', 'wordpress-seo'), WPSEO_VERSION, '<a href="' . admin_url('admin.php?page=wpseo_dashboard&intro=1') . '">', '</a>'); $notification_options = array('type' => 'updated', 'id' => 'wpseo-dismiss-about', 'nonce' => wp_create_nonce('wpseo-dismiss-about')); Yoast_Notification_Center::get()->add_notification(new Yoast_Notification($info_message, $notification_options)); } }
/** * Offer to create a redirect from the term that is about to get deleted * * @param $term_id */ public function detect_term_delete($term_id) { global $wpdb; // Get the term and taxonomy from the term_taxonomy table $term_row = $wpdb->get_row($wpdb->prepare("SELECT `term_id`, `taxonomy` FROM `" . $wpdb->term_taxonomy . "` WHERE `term_taxonomy_id` = %d ", $term_id)); // Check result if (null != $term_row) { // Get the URL $url = parse_url(get_term_link(get_term($term_row->term_id, $term_row->taxonomy), $term_row->taxonomy)); $url = $url['path']; // Format the message $message = sprintf(__("WordPress SEO Premium detected that you deleted a term. <a href='%s'>Click here to create a redirect from the old term URL</a>.", 'wordpress-seo'), 'javascript:wpseo_create_redirect("' . urlencode($url) . '", "' . wp_create_nonce('wpseo-redirects-ajax-security') . '");'); // Add the message to the notifications center Yoast_Notification_Center::get()->add_notification(new Yoast_Notification($message)); } }
/** * Removes the notification from the notification center. */ private function remove_notification() { $notification_center = Yoast_Notification_Center::get(); $notification_center->remove_notification(self::get_notification()); }
/** * Clear the notification for a plugin * * @param string $plugin_file Clear the optional notification for this plugin. */ protected function clear_error($plugin_file) { $identifier = $this->get_notification_identifier($plugin_file); $notification_center = Yoast_Notification_Center::get(); $notification = $notification_center->get_notification_by_id('wpseo-conflict-' . $identifier); if ($notification) { $notification_center->remove_notification($notification); } }
function disable_yoast_notifications() { if (class_exists('Yoast')) { remove_action('admin_notices', array(Yoast_Notification_Center::get(), 'display_notifications')); remove_action('all_admin_notices', array(Yoast_Notification_Center::get(), 'display_notifications')); } }
/** * Register the menu item and its sub menu's. * * @global array $submenu used to change the label on the first item. */ function register_settings_page() { if (WPSEO_Utils::grant_access() !== true) { return; } // Base 64 encoded SVG image. $icon_svg = WPSEO_Utils::get_icon_svg(); $manage_options_cap = $this->get_manage_options_cap(); $notification_center = Yoast_Notification_Center::get(); $notification_count = $notification_center->get_notification_count(); // Add main page. /* 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('<span class="update-plugins count-%1$d"><span class="plugin-count" aria-hidden="true">%1$d</span><span class="screen-reader-text">%2$s</span></span>', $notification_count, $counter_screen_reader_text); $admin_page = add_menu_page('Yoast SEO: ' . __('Dashboard', 'wordpress-seo'), __('SEO', 'wordpress-seo') . ' ' . $counter, $manage_options_cap, self::PAGE_IDENTIFIER, array($this, 'load_page'), $icon_svg, '99.31337'); // Sub menu pages. $submenu_pages = array(array(self::PAGE_IDENTIFIER, '', __('General', 'wordpress-seo'), $manage_options_cap, self::PAGE_IDENTIFIER, array($this, 'load_page'), null), array(self::PAGE_IDENTIFIER, '', __('Titles & Metas', 'wordpress-seo'), $manage_options_cap, 'wpseo_titles', array($this, 'load_page')), array(self::PAGE_IDENTIFIER, '', __('Social', 'wordpress-seo'), $manage_options_cap, 'wpseo_social', array($this, 'load_page'), null), array(self::PAGE_IDENTIFIER, '', __('XML Sitemaps', 'wordpress-seo'), $manage_options_cap, 'wpseo_xml', array($this, 'load_page'), null), array(self::PAGE_IDENTIFIER, '', __('Advanced', 'wordpress-seo'), $manage_options_cap, 'wpseo_advanced', array($this, 'load_page'), null), array(self::PAGE_IDENTIFIER, '', __('Tools', 'wordpress-seo'), $manage_options_cap, 'wpseo_tools', array($this, 'load_page'), null), array(self::PAGE_IDENTIFIER, '', __('Search Console', 'wordpress-seo'), $manage_options_cap, 'wpseo_search_console', array($this->admin_features['google_search_console'], 'display'), array(array($this->admin_features['google_search_console'], 'set_help'))), array(self::PAGE_IDENTIFIER, '', __('Go Premium', 'wordpress-seo') . ' ' . $this->get_premium_indicator(), $manage_options_cap, 'wpseo_licenses', array($this, 'load_page'), null)); // Allow submenu pages manipulation. $submenu_pages = apply_filters('wpseo_submenu_pages', $submenu_pages); // Loop through submenu pages and add them. if (count($submenu_pages)) { foreach ($submenu_pages as $submenu_page) { $page_title = $submenu_page[2] . ' - Yoast SEO'; // We cannot use $submenu_page[1] because add-ons define that, so hard-code this value. if ('wpseo_licenses' === $submenu_page[4]) { $page_title = __('Premium', 'wordpress-seo') . ' - Yoast SEO'; } // Add submenu page. $admin_page = add_submenu_page($submenu_page[0], $page_title, $submenu_page[2], $submenu_page[3], $submenu_page[4], $submenu_page[5]); // Check if we need to hook. if (isset($submenu_page[6]) && (is_array($submenu_page[6]) && $submenu_page[6] !== array())) { foreach ($submenu_page[6] as $submenu_page_action) { add_action('load-' . $admin_page, $submenu_page_action); } } } } global $submenu; if (isset($submenu[self::PAGE_IDENTIFIER]) && current_user_can($manage_options_cap)) { $submenu[self::PAGE_IDENTIFIER][0][0] = __('Dashboard', 'wordpress-seo'); } }
/** * 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'))); } }
/** * 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; } global $wp_admin_bar, $post; $admin_menu = current_user_can('manage_options'); if (!$admin_menu && is_multisite()) { $options = get_site_option('wpseo_ms'); $admin_menu = $options['access'] === 'superadmin' && is_super_admin(); } $focuskw = ''; $score = ''; $seo_url = ''; if ((is_singular() || is_admin() && in_array($GLOBALS['pagenow'], array('post.php', 'post-new.php'), true)) && isset($post) && is_object($post) && apply_filters('wpseo_use_page_analysis', true) === true) { $focuskw = WPSEO_Meta::get_value('focuskw', $post->ID); $score = '<div class="' . esc_attr('wpseo-score-icon') . ' adminbar-seo-score"></div>'; $seo_url = get_edit_post_link($post->ID); } if (WPSEO_Taxonomy::is_term_edit($GLOBALS['pagenow'])) { $score = '<div class="' . esc_attr('wpseo-score-icon') . ' adminbar-seo-score"></div>'; $seo_url = get_edit_tag_link(filter_input(INPUT_GET, 'tag_ID'), 'category'); } // Never display notifications for network admin. $counter = ''; if ($admin_menu) { $seo_url = get_admin_url(null, 'admin.php?page=' . WPSEO_Admin::PAGE_IDENTIFIER); 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. $counter = sprintf(' <div class="wp-core-ui wp-ui-notification yoast-issue-counter">%d</div>', $notification_count); } 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 . '\');"></div>'; $wp_admin_bar->add_menu(array('id' => 'wpseo-menu', 'title' => $title . $score . $counter, 'href' => $seo_url)); $wp_admin_bar->add_menu(array('parent' => 'wpseo-menu', 'id' => 'wpseo-kwresearch', 'title' => __('Keyword Research', 'wordpress-seo'), '#')); $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 Insights', 'wordpress-seo'), 'href' => 'http://www.google.com/insights/search/#q=' . urlencode($focuskw) . '&cmpt=q', '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'), '#')); $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' => '//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-richsnippets', 'title' => __('Check Rich Snippets', 'wordpress-seo'), 'href' => '//www.google.com/webmasters/tools/richsnippets?q=' . 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' => '//developers.pinterest.com/rich_pins/validator/?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-modernie', 'title' => __('Modern IE Site Scan', 'wordpress-seo'), 'href' => '//www.modern.ie/en-us/report#' . 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 ($admin_menu) { $wp_admin_bar->add_menu(array('parent' => 'wpseo-menu', 'id' => 'wpseo-settings', 'title' => __('SEO Settings', 'wordpress-seo'))); $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-general', 'title' => __('General', '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'))); } }
/** * Wraps for notifications center class. */ function load_yoast_notifications() { // Init Yoast_Notification_Center class. Yoast_Notification_Center::get(); }
/** * Shows a notice to the user if they have Google Analytics for WordPress 5.4.3 installed because it causes an error * on the google search console page. */ public function ga_compatibility_notice() { if (defined('GAWP_VERSION') && '5.4.3' === GAWP_VERSION) { $info_message = sprintf(__('%1$s detected you are using version %2$s of %3$s, please update to the latest version to prevent compatibility issues.', 'ymbeseo'), 'Yoast SEO', '5.4.3', 'Google Analytics by Yoast'); $notification_options = array('type' => 'error'); Yoast_Notification_Center::get()->add_notification(new Yoast_Notification($info_message, $notification_options)); } }
/** * Setting an error on the screen * * @param string $plugin_section * @param string $readable_plugin_section This is the value for the translation */ protected function set_error($plugin_section, $readable_plugin_section) { $plugins_as_string = $this->get_conflicting_plugins_as_string($plugin_section); $error_message = sprintf(__('The following plugins might cause (%1s) issues with Yoast WordPress SEO: %2s', 'wordpress-seo'), $readable_plugin_section, $plugins_as_string); // Add the message to the notifications center Yoast_Notification_Center::get()->add_notification(new Yoast_Notification($error_message, 'error')); }
/** * Register the menu item and its sub menu's. * * @global array $submenu used to change the label on the first item. */ function register_settings_page() { if (WPSEO_Utils::grant_access() !== true) { return; } // Base 64 encoded SVG image. $icon_svg = WPSEO_Utils::get_icon_svg(); $manage_options_cap = $this->get_manage_options_cap(); $notification_center = Yoast_Notification_Center::get(); $notification_count = $notification_center->get_notification_count(); // Add main page. $counter = sprintf('<span class="update-plugins count-%1$d"><span class="plugin-count">%1$d</span></span>', $notification_count); $admin_page = add_menu_page('Yoast SEO: ' . __('Dashboard', 'wordpress-seo'), __('SEO', 'wordpress-seo') . ' ' . $counter, $manage_options_cap, self::PAGE_IDENTIFIER, array($this, 'load_page'), $icon_svg, '99.31337'); // Sub menu pages. $submenu_pages = array(array(self::PAGE_IDENTIFIER, '', __('General', 'wordpress-seo'), $manage_options_cap, self::PAGE_IDENTIFIER, array($this, 'load_page'), null), array(self::PAGE_IDENTIFIER, '', __('Titles & Metas', 'wordpress-seo'), $manage_options_cap, 'wpseo_titles', array($this, 'load_page')), array(self::PAGE_IDENTIFIER, '', __('Social', 'wordpress-seo'), $manage_options_cap, 'wpseo_social', array($this, 'load_page'), null), array(self::PAGE_IDENTIFIER, '', __('XML Sitemaps', 'wordpress-seo'), $manage_options_cap, 'wpseo_xml', array($this, 'load_page'), null), array(self::PAGE_IDENTIFIER, '', __('Advanced', 'wordpress-seo'), $manage_options_cap, 'wpseo_advanced', array($this, 'load_page'), null), array(self::PAGE_IDENTIFIER, '', __('Tools', 'wordpress-seo'), $manage_options_cap, 'wpseo_tools', array($this, 'load_page'), null), array(self::PAGE_IDENTIFIER, '', __('Search Console', 'wordpress-seo'), $manage_options_cap, 'wpseo_search_console', array($this->admin_features['google_search_console'], 'display'), array(array($this->admin_features['google_search_console'], 'set_help'))), array(self::PAGE_IDENTIFIER, '', '<span style="color:#f18500">' . __('Extensions', 'wordpress-seo') . '</span>', $manage_options_cap, 'wpseo_licenses', array($this, 'load_page'), null)); // Allow submenu pages manipulation. $submenu_pages = apply_filters('wpseo_submenu_pages', $submenu_pages); // Loop through submenu pages and add them. if (count($submenu_pages)) { foreach ($submenu_pages as $submenu_page) { // Add submenu page. $admin_page = add_submenu_page($submenu_page[0], $submenu_page[2] . ' - Yoast SEO', $submenu_page[2], $submenu_page[3], $submenu_page[4], $submenu_page[5]); // Check if we need to hook. if (isset($submenu_page[6]) && (is_array($submenu_page[6]) && $submenu_page[6] !== array())) { foreach ($submenu_page[6] as $submenu_page_action) { add_action('load-' . $admin_page, $submenu_page_action); } } } } global $submenu; if (isset($submenu[self::PAGE_IDENTIFIER]) && current_user_can($manage_options_cap)) { $submenu[self::PAGE_IDENTIFIER][0][0] = __('Dashboard', 'wordpress-seo'); } }
/** * Filter out any dismissed notifications * * @param Yoast_Notification $notification Notification to test. * * @return bool */ private static function filter_dismissed_alerts(Yoast_Notification $notification) { return Yoast_Notification_Center::is_notification_dismissed($notification); }
/** * Adds a notification to the notification center. */ protected function remove_notification() { $notification_center = Yoast_Notification_Center::get(); $notification_center->remove_notification($this->get_notification()); }
/** * Setting an error on the screen * * @param string $plugin_section * @param string $readable_plugin_section This is the value for the translation. */ protected function set_error($plugin_section, $readable_plugin_section) { $plugins_as_string = $this->get_conflicting_plugins_as_string($plugin_section); $error_message = '<h3>' . __('Warning!', 'wordpress-seo') . '</h3>'; /* translators: %1$s: 'Facebook & Open Graph' plugin name(s) of possibly conflicting plugin(s), %2$s to Yoast SEO */ $error_message .= '<p>' . sprintf(__('The %1$s plugin(s) might cause issues when used in conjunction with %2$s.', 'wordpress-seo'), $plugins_as_string, 'Yoast SEO') . '</p>'; $error_message .= sprintf($readable_plugin_section, 'Yoast SEO', $plugins_as_string) . '<br/><br/>'; $error_message .= '<p><strong>' . __('Recommended solution', 'wordpress-seo') . '</strong><br/>'; /* translators: %1$s: 'Facebook & Open Graph' plugin name(s) of possibly conflicting plugin(s). %2$s to Yoast SEO */ $error_message .= sprintf(__('We recommend you deactivate %1$s and have another look at your %2$s configuration using the button above.', 'wordpress-seo'), $plugins_as_string, 'Yoast SEO') . '</p>'; foreach ($this->active_plugins[$plugin_section] as $plugin_file) { /* translators: %s: 'Facebook' plugin name of possibly conflicting plugin */ $error_message .= '<a target="_blank" class="button-primary" href="' . wp_nonce_url('plugins.php?action=deactivate&plugin=' . $plugin_file . '&plugin_status=all', 'deactivate-plugin_' . $plugin_file) . '">' . sprintf(__('Deactivate %s', 'wordpress-seo'), WPSEO_Utils::get_plugin_name($plugin_file)) . '</a> '; } /* translators: %1$s expands to Yoast SEO */ $error_message .= '<p class="alignright"><small>' . sprintf(__('This warning is generated by %1$s.', 'wordpress-seo'), 'Yoast SEO') . '</small></p><div class="clear"></div>'; // Add the message to the notifications center. Yoast_Notification_Center::get()->add_notification(new Yoast_Notification($error_message, array('type' => 'error yoast-dismissible', 'id' => 'wpseo-dismiss-plugin-conflict', 'nonce' => wp_create_nonce('dismiss-plugin-conflict'), 'data_json' => array('section' => $plugin_section, 'plugins' => $this->active_plugins[$plugin_section])))); }
/** * Adding notification to the yoast notification center * * @param string $message * @param string $type */ private function add_notification($message, $type) { Yoast_Notification_Center::get()->add_notification(new Yoast_Notification($message, array('type' => $type))); }
/** * Setting an error on the screen * * @param string $plugin_section * @param string $readable_plugin_section This is the value for the translation */ protected function set_error($plugin_section, $readable_plugin_section) { $plugins_as_string = $this->get_conflicting_plugins_as_string($plugin_section); $error_message = '<h3>' . __('Warning!', 'wordpress-seo') . '</h3>'; /* translators: %s: 'Facebook & Open Graph' plugin name(s) of possibly conflicting plugin(s) */ $error_message .= '<p>' . sprintf(__('The %s plugin(s) might cause issues when used in conjunction with Yoast WordPress SEO.', 'wordpress-seo'), $plugins_as_string) . '</p>'; $error_message .= sprintf($readable_plugin_section, $plugins_as_string) . '<br/><br/>'; $error_message .= '<p><strong>' . __('Recommended solution', 'wordpress-seo') . '</strong><br/>'; /* translators: %s: 'Facebook & Open Graph' plugin name(s) of possibly conflicting plugin(s) */ $error_message .= sprintf(__('We recommend you deactivate %s and have another look at your WordPress SEO configuration using the button above.', 'wordpress-seo'), $plugins_as_string) . '</p>'; foreach ($this->active_plugins[$plugin_section] as $plugin_file) { /* translators: %s: 'Facebook' plugin name of possibly conflicting plugin */ $error_message .= '<a target="_blank" class="button-primary" href="' . wp_nonce_url('plugins.php?action=deactivate&plugin=' . $plugin_file . '&plugin_status=all', 'deactivate-plugin_' . $plugin_file) . '">' . sprintf(__('Deactivate %s', 'wordpress-seo'), $this->get_plugin_name($plugin_file)) . '</a> '; } $error_message .= '<p class="alignright"><small>' . __('This warning is generated by WordPress SEO by Yoast.', 'wordpress-seo') . '</small></p><div class="clear"></div>'; // Add the message to the notifications center Yoast_Notification_Center::get()->add_notification(new Yoast_Notification($error_message, 'error')); }
/** * Verifies nonce if additional parameters have been sent. * * Shows an error notification if the nonce check fails. */ private function verify_nonce() { if ($this->should_verify_nonce() && !wp_verify_nonce(filter_input(INPUT_GET, 'nonce'), 'bulk-editor-table')) { Yoast_Notification_Center::get()->add_notification(new Yoast_Notification(__('You are not allowed to access this page.', 'ymbeseo'), array('type' => 'error'))); Yoast_Notification_Center::get()->display_notifications(); die; } }
/** * Shows the notice for recalculating the post. the Notice will only be shown if the user hasn't dismissed it before. */ public function recalculate_notice() { // Just a return, because we want to temporary disable this notice (#3998). return; if (filter_input(INPUT_GET, 'recalculate') === '1') { update_option('wpseo_dismiss_recalculate', '1'); return; } $can_access = is_multisite() ? WPSEO_Utils::grant_access() : current_user_can('manage_options'); if ($can_access && !$this->is_site_notice_dismissed('wpseo_dismiss_recalculate')) { Yoast_Notification_Center::get()->add_notification(new Yoast_Notification(sprintf(__('We\'ve updated our SEO score algorithm. %1$sClick here to recalculate the SEO scores%2$s for all posts and pages.', 'wordpress-seo'), '<a href="' . admin_url('admin.php?page=wpseo_tools&recalculate=1') . '">', '</a>'), array('type' => 'updated yoast-dismissible', 'id' => 'wpseo-dismiss-recalculate', 'nonce' => wp_create_nonce('wpseo-dismiss-recalculate')))); } }
/** * Offer to create a redirect from the post that is about to get deleted * * @param $post_id */ public function detect_post_delete($post_id) { // Get the post $post = get_post($post_id); // No revisions please if ($post->post_status != 'inherit') { // Get the right URL $url = parse_url(get_permalink($post_id)); $url = $url['path']; // If $url is not a single /, there may be the option to create a redirect if ($url !== '/') { // Message should only be shown if there isn't already a redirect if (!$this->check_if_redirect_exists($url)) { // Format the message $message = sprintf(__("WordPress SEO Premium detected that you deleted a post. <a href='%s'>Click here to create a redirect from the old post URL</a>.", 'wordpress-seo'), 'javascript:wpseo_create_redirect("' . urlencode($url) . '", "' . wp_create_nonce('wpseo-redirects-ajax-security') . '");'); // Add the message to the notifications center Yoast_Notification_Center::get()->add_notification(new Yoast_Notification($message)); } } } }
/** * Adding notice that the api libs has the wrong version * * @param string $notice Message string. */ private function incompatible_api_libs($notice) { Yoast_Notification_Center::get()->add_notification(new Yoast_Notification($notice, array('type' => 'error'))); }