function yoast_seo_addon_import($post_id, $data, $import_options) { global $yoast_addon; // all fields except for slider and image fields $fields = array('_yoast_wpseo_focuskw', '_yoast_wpseo_title', '_yoast_wpseo_metadesc', '_yoast_wpseo_meta-robots-noindex', '_yoast_wpseo_meta-robots-nofollow', '_yoast_wpseo_meta-robots-adv', '_yoast_wpseo_sitemap-include', '_yoast_wpseo_sitemap-prio', '_yoast_wpseo_canonical', '_yoast_wpseo_redirect', '_yoast_wpseo_opengraph-title', '_yoast_wpseo_opengraph-description', '_yoast_wpseo_twitter-title', '_yoast_wpseo_twitter-description'); // image fields $image_fields = array('_yoast_wpseo_opengraph-image', '_yoast_wpseo_twitter-image'); $fields = array_merge($fields, $image_fields); // update everything in fields arrays foreach ($fields as $field) { if ($yoast_addon->can_update_meta($field, $import_options)) { if (in_array($field, $image_fields)) { if ($yoast_addon->can_update_image($import_options)) { $id = $data[$field]['attachment_id']; $url = wp_get_attachment_url($id); update_post_meta($post_id, $field, $url); } } else { update_post_meta($post_id, $field, $data[$field]); } } } // calculate _yoast_wpseo_linkdex if (class_exists('WPSEO_Metabox')) { wpseo_admin_init(); $seo = new WPSEO_Metabox(); $seo->calculate_results(get_post($post_id)); } }
/** * 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); }
public function test_save_postdata() { // create and go to post $post_id = $this->factory->post->create(); $this->go_to(get_permalink($post_id)); $post = get_post($post_id); // setup $GLOBALS['wpseo_admin'] = new WPSEO_Admin(); // vars $meta_fields = apply_filters('wpseo_save_metaboxes', array()); $meta_fields = array_merge($meta_fields, self::$class_instance->get_meta_field_defs('general', $post->post_type), self::$class_instance->get_meta_field_defs('advanced')); // set $_POST data to be saved foreach ($meta_fields as $key => $field) { // set text fields if ($field['type'] === 'text') { $_POST[WPSEO_Metabox::$form_prefix . $key] = 'text'; } elseif ($field['type'] === 'checkbox') { $_POST[WPSEO_Metabox::$form_prefix . $key] = 'on'; } } // call method that saves the $_POST data self::$class_instance->save_postdata($post->ID); // check if output matches $custom = get_post_custom($post->ID); foreach ($meta_fields as $key => $field) { if (!isset($custom[WPSEO_Metabox::$meta_prefix . $key][0])) { continue; } $value = $custom[WPSEO_Metabox::$meta_prefix . $key][0]; // set text fields if ($field['type'] === 'text') { $this->assertNotEmpty($value); } elseif ($field['type'] === 'checkbox') { $this->assertEquals($value, 'on'); } } }
/** * 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'))); } }
/** * Pass variables to js for use with the post-scraper * * @return array */ public function localize_post_scraper_script() { $post = $this->get_metabox_post(); $translations = $this->get_scraper_translations(); return array('translations' => $translations, 'keyword_usage' => $this->get_focus_keyword_usage(), 'search_url' => admin_url('edit.php?seo_kw_filter={keyword}'), 'post_edit_url' => admin_url('post.php?post={id}&action=edit'), 'base_url' => $this->get_base_url_for_js(), 'title_template' => WPSEO_Metabox::get_title_template($post), 'metadesc_template' => WPSEO_Metabox::get_metadesc_template($post), 'contentTab' => __('Content:', 'wordpress-seo'), 'metaDescriptionDate' => $this->get_metadesc_date($post), 'locale' => get_locale()); }
/** * Calculate the page analysis results for post. * * @todo [JRF => whomever] check whether the results of this method are always checked with is_wp_error() * @todo [JRF => whomever] check the usage of this method as it's quite intense/heavy, see if it's only * used when really necessary * @todo [JRF => whomever] see if we can get rid of the passing by reference of $results as it makes * the code obfuscated * * @param object $post Post to calculate the results for. * * @return array|WP_Error */ function calculate_results($post) { $options = WPSEO_Options::get_all(); if (!class_exists('DOMDocument')) { $result = new WP_Error('no-domdocument', sprintf(__("Your hosting environment does not support PHP's %sDocument Object Model%s.", 'wordpress-seo'), '<a href="http://php.net/manual/en/book.dom.php">', '</a>') . ' ' . __("To enjoy all the benefits of the page analysis feature, you'll need to (get your host to) install it.", 'wordpress-seo')); return $result; } if (!is_array($post) && !is_object($post)) { $result = new WP_Error('no-post', __('No post content to analyse.', 'wordpress-seo')); return $result; } elseif (self::get_value('focuskw', $post->ID) === '') { $result = new WP_Error('no-focuskw', sprintf(__('No focus keyword was set for this %s. If you do not set a focus keyword, no score can be calculated.', 'wordpress-seo'), $post->post_type)); self::set_value('linkdex', 0, $post->ID); return $result; } elseif (apply_filters('wpseo_use_page_analysis', true) !== true) { $result = new WP_Error('page-analysis-disabled', sprintf(__('Page Analysis has been disabled.', 'wordpress-seo'), $post->post_type)); return $result; } $results = array(); $job = array(); $sampleurl = $this->get_sample_permalink($post); $job['pageUrl'] = preg_replace('`%(?:post|page)name%`', $sampleurl[1], $sampleurl[0]); $job['pageSlug'] = urldecode($post->post_name); $job['keyword'] = self::get_value('focuskw'); $job['keyword_folded'] = $this->strip_separators_and_fold($job['keyword']); $job['post_id'] = $post->ID; $job['post_type'] = $post->post_type; $dom = new domDocument(); $dom->strictErrorChecking = false; $dom->preserveWhiteSpace = false; /** * Filter: 'wpseo_pre_analysis_post_content' - Make the post content filterable before calculating the page analysis * * @api string $post_content The post content * * @param object $post The post */ $post_content = apply_filters('wpseo_pre_analysis_post_content', $post->post_content, $post); // Check if the post content is not empty if (!empty($post_content)) { @$dom->loadHTML($post_content); } unset($post_content); $xpath = new DOMXPath($dom); // Check if this focus keyword has been used already. $this->check_double_focus_keyword($job, $results); // Keyword $this->score_keyword($job['keyword'], $results); // Title $title = self::get_value('title'); if ($title !== '') { $job['title'] = $title; } else { if (isset($options['title-' . $post->post_type]) && $options['title-' . $post->post_type] !== '') { $title_template = $options['title-' . $post->post_type]; } else { $title_template = '%%title%% - %%sitename%%'; } $job['title'] = wpseo_replace_vars($title_template, $post); } unset($title); $this->score_title($job, $results); // Meta description $description = ''; $desc_meta = self::get_value('metadesc'); if ($desc_meta !== '') { $description = $desc_meta; } elseif (isset($options['metadesc-' . $post->post_type]) && $options['metadesc-' . $post->post_type] !== '') { $description = wpseo_replace_vars($options['metadesc-' . $post->post_type], $post); } unset($desc_meta); self::$meta_length = apply_filters('wpseo_metadesc_length', self::$meta_length, $post); $this->score_description($job, $results, $description, self::$meta_length); unset($description); // Body $body = $this->get_body($post); $firstp = $this->get_first_paragraph($body); $this->score_body($job, $results, $body, $firstp); unset($firstp); // URL $this->score_url($job, $results); // Headings $headings = $this->get_headings($body); $this->score_headings($job, $results, $headings); unset($headings); // Images $imgs = array(); $imgs['count'] = substr_count($body, '<img'); $imgs = $this->get_images_alt_text($post->ID, $body, $imgs); // Check featured image if (function_exists('has_post_thumbnail') && has_post_thumbnail()) { $imgs['count'] += 1; if (empty($imgs['alts'])) { $imgs['alts'] = array(); } $imgs['alts'][] = $this->strtolower_utf8(get_post_meta(get_post_thumbnail_id($post->ID), '_wp_attachment_image_alt', true)); } $this->score_images_alt_text($job, $results, $imgs); unset($imgs); unset($body); // Anchors $anchors = $this->get_anchor_texts($xpath); $count = $this->get_anchor_count($xpath); $this->score_anchor_texts($job, $results, $anchors, $count); unset($anchors, $count, $dom); $results = apply_filters('wpseo_linkdex_results', $results, $job, $post); $this->aasort($results, 'val'); $overall = 0; $overall_max = 0; foreach ($results as $result) { $overall += $result['val']; $overall_max += 9; } if ($overall < 1) { $overall = 1; } $score = wpseo_calc(wpseo_calc($overall, '/', $overall_max), '*', 100, true); if (!is_wp_error($score)) { self::set_value('linkdex', absint($score), $post->ID); $results['total'] = $score; } return $results; }
/** * Calculate the page analysis results for post. * * @internal Unfortunately there isn't a filter available to hook into before returning the results * for get_post_meta(), get_post_custom() and the likes. That would have been the preferred solution. * * @see function calculate_results() in wordpress-seo\admin\class-metabox.php * @scope admin * @since 1.2.2 * * @param array $results * @param string $post_content * @param array $job, * @param WP_Post object $post Post to calculate the results for. * * @return array */ public static function calculate_results($results, $post_content, $job, $post) { $WPSEO_Metabox = new WPSEO_Metabox(); $dom = new domDocument(); $dom->strictErrorChecking = false; $dom->preserveWhiteSpace = false; // Check if the post content is not empty. if (!empty($post_content)) { @$dom->loadHTML($post_content); } unset($post_content); $xpath = new DOMXPath($dom); // Check if this focus keyword has been used already. $WPSEO_Metabox->check_double_focus_keyword($job, $results); // Keyword. $WPSEO_Metabox->score_keyword($job['keyword'], $results); // Title. $title = WPSEO_Meta::get_value('title', $post->ID); if ($title !== '') { $job['title'] = $title; } else { if (isset($options['title-' . $post->post_type]) && $options['title-' . $post->post_type] !== '') { $title_template = $options['title-' . $post->post_type]; } else { $title_template = '%%title%% - %%sitename%%'; } $job['title'] = wpseo_replace_vars($title_template, $post); } unset($title); $WPSEO_Metabox->score_title($job, $results); // Meta description. $description = ''; // $desc_meta = WPSEO_Meta::get_value( 'metadesc', $post->ID ); $desc_meta = WPGlobus_Core::text_filter(WPSEO_Meta::get_value('metadesc', $post->ID), WPGlobus::Config()->default_language); if ($desc_meta !== '') { $description = $desc_meta; } elseif (isset($options['metadesc-' . $post->post_type]) && $options['metadesc-' . $post->post_type] !== '') { $description = wpseo_replace_vars($options['metadesc-' . $post->post_type], $post); } unset($desc_meta); WPSEO_Meta::$meta_length = apply_filters('wpseo_metadesc_length', WPSEO_Meta::$meta_length, $post); $WPSEO_Metabox->score_description($job, $results, $description, WPSEO_Meta::$meta_length); unset($description); // Body. // $body = $WPSEO_Metabox->get_body( $post ); $body = WPGlobus_Core::text_filter($WPSEO_Metabox->get_body($post), WPGlobus::Config()->default_language); $firstp = $WPSEO_Metabox->get_first_paragraph($body); $WPSEO_Metabox->score_body($job, $results, $body, $firstp); unset($firstp); // URL. $WPSEO_Metabox->score_url($job, $results); // Headings. $headings = $WPSEO_Metabox->get_headings($body); $WPSEO_Metabox->score_headings($job, $results, $headings); unset($headings); // Images. $imgs = array(); $imgs['count'] = substr_count($body, '<img'); $imgs = $WPSEO_Metabox->get_images_alt_text($post->ID, $body, $imgs); // Check featured image. if (function_exists('has_post_thumbnail') && has_post_thumbnail()) { $imgs['count'] += 1; if (empty($imgs['alts'])) { $imgs['alts'] = array(); } $imgs['alts'][] = $WPSEO_Metabox->strtolower_utf8(get_post_meta(get_post_thumbnail_id($post->ID), '_wp_attachment_image_alt', true)); } $WPSEO_Metabox->score_images_alt_text($job, $results, $imgs); unset($imgs); unset($body); // Anchors. $anchors = $WPSEO_Metabox->get_anchor_texts($xpath); $count = $WPSEO_Metabox->get_anchor_count($xpath); $WPSEO_Metabox->score_anchor_texts($job, $results, $anchors, $count); unset($anchors, $count, $dom); return $results; }
/** * 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(); } }
/** * Get SEO score for post from WordPress SEO Plugin * * @param int $post_id * * @return string */ protected function get_wp_seo_score($post_id) { // Get seo score from WordPress SEO $score = WPSEO_Metabox::get_value('linkdex', $post_id); if ($score !== '') { $nr = $this->wpseo_calc($score, '/', 10, true); $score_label = $this->wpseo_translate_score($nr); unset($nr); } else { $score_label = 'na'; } return $score_label; }
/** * Get the post list table rows for the searched term. * * Mimics admin/edit.php without all the chrome elements. * * @since 1.2.0 * @todo Account for private status on media items? */ public static function ajax_get_posts_list_table() { global $hook_suffix, $pagenow, $post_type, $post_type_object, $per_page, $mode, $wp_query; if (!isset($_REQUEST['nonce']) || !wp_verify_nonce($_REQUEST['nonce'], 'bils-posts-list-table-instant-search')) { echo '<tr class="no-items bils-error"><td class="colspanchange">Invalid nonce.</td></tr>'; wp_die(); } $post_type = $_REQUEST['post_type']; $post_type_object = get_post_type_object($post_type); // Determine the orderby argument. if (isset($_REQUEST['orderby']) && !empty($_REQUEST['orderby'])) { $orderby = $_REQUEST['orderby']; } else { $orderby = $post_type_object->hierarchical ? 'title' : 'post_date'; } // Determine the order argument. if (isset($_REQUEST['order']) && !empty($_REQUEST['order'])) { $order = 'asc' == strtolower($_REQUEST['order']) ? 'asc' : 'desc'; } else { $order = $post_type_object->hierarchical ? 'asc' : 'desc'; } $args = array('s' => $_REQUEST['s'], 'post_type' => $post_type, 'post_status' => $_REQUEST['post_status'], 'orderby' => $orderby, 'order' => $order, 'posts_per_page' => 20); if ('attachment' == $post_type) { $args['post_status'] = 'inherit'; $args['post_mime_type'] = $_REQUEST['post_mime_type']; } // WordPress SEO compatibility. if (function_exists('wpseo_admin_init')) { $pagenow = 'edit.php'; wpseo_admin_init(); if (class_exists('WPSEO_Metabox')) { $wpseo_metabox = new WPSEO_Metabox(); $wpseo_metabox->setup_page_analysis(); } } set_current_screen($_REQUEST['screen']); // Posts 2 Posts column compatibility. do_action('load-edit.php'); add_filter('posts_search', array('Better_Internal_Link_Search', 'limit_search_to_title'), 10, 2); wp_edit_posts_query($args); if ('attachment' == $post_type) { $wp_list_table = _get_list_table('WP_Media_List_Table', array('screen' => $_REQUEST['screen'])); } else { $wp_list_table = _get_list_table('WP_Posts_List_Table', array('screen' => $_REQUEST['screen'])); } $wp_list_table->prepare_items(); $wp_list_table->display_rows_or_placeholder(); wp_die(); }
private static function meta($object_id, $meta_key, $meta_value) { $prefix = WPSEO_Meta::$meta_prefix; WPSEO_Metabox::translate_meta_boxes(); if (0 !== strpos($meta_key, $prefix)) { return; } $key = str_replace($prefix, '', $meta_key); foreach (WPSEO_Meta::$meta_fields as $tab => $fields) { if (isset($fields[$key])) { $field = $fields[$key]; break; } } if (!isset($field, $field['title'], $tab) || '' === $field['title']) { return; } $post = get_post($object_id); $post_type_label = get_post_type_labels(get_post_type_object($post->post_type))->singular_name; self::log(sprintf(__('Updated "%1$s" of "%2$s" %3$s', 'stream'), $field['title'], $post->post_title, $post_type_label), array('meta_key' => $meta_key, 'meta_value' => $meta_value, 'post_type' => $post->post_type), $object_id, 'wpseo_meta', 'updated'); }
function _initialize_yoast() { wpseo_init(); wpseo_admin_init(); wpseo_load_textdomain(); $options = WPSEO_Options::get_all(); new WPSEO_Metabox(); WPSEO_Metabox::translate_meta_boxes(); if ($options['opengraph'] === true || $options['twitter'] === true || $options['googleplus'] === true) { new WPSEO_Social_Admin(); WPSEO_Social_Admin::translate_meta_boxes(); } }
/** * Returns post in metabox context - fallback for Yoast SEO < 3.0 and News SEO > 2.2.5 * * @returns WP_Post */ protected function get_metabox_post() { if (is_callable('parent:get_metabox_post')) { return parent::get_metabox_post(); } if ($post = filter_input(INPUT_GET, 'post')) { $post_id = (int) WPSEO_Utils::validate_int($post); return get_post($post_id); } if (isset($GLOBALS['post'])) { return $GLOBALS['post']; } return array(); }