public function get_title_separator($separator) { if (class_exists('WPSEO_Option_Titles')) { $separator = wpseo_replace_vars('%%sep%%', array()); } return $separator; }
/** * Convert the given term into a analyzable object. * * @param mixed $item The term for which to build the analyzer data. * * @return array */ protected function item_to_response($item) { $focus_keyword = $this->get_focus_keyword($item); $title = str_replace(' %%page%% ', ' ', $this->get_title($item)); $meta = $this->get_meta_description($item); $description = $item->description; /** * Filter the term description for recalculation. * * @param string $description Content of the term. Modify to reflect front-end content. * @oaram WP_Term $item The term the description comes from. */ $description = apply_filters('wpseo_term_description_for_recalculation', $description, $item); return array('term_id' => $item->term_id, 'taxonomy' => $item->taxonomy, 'text' => $description, 'keyword' => $focus_keyword, 'url' => urldecode($item->slug), 'pageTitle' => apply_filters('wpseo_title', wpseo_replace_vars($title, $item, array('page'))), 'meta' => apply_filters('wpseo_metadesc', wpseo_replace_vars($meta, $item)), 'keyword_usage' => array($focus_keyword => WPSEO_Taxonomy_Meta::get_keyword_usage($focus_keyword, $item->term_id, $item->taxonomy))); }
/** * Map the posts to a response array * * @param WP_Post $item The post for which to build the analyzer data. * * @return array */ protected function item_to_response($item) { $focus_keyword = WPSEO_Meta::get_value('focuskw', $item->ID); $content = $item->post_content; /** * Filter the post content for use in the SEO score recalculation. * * @param string $content Content of the post. Modify to reflect front-end content. * @param WP_Post $item The Post object the content comes from. */ $content = apply_filters('wpseo_post_content_for_recalculation', $content, $item); // Apply shortcodes. $content = do_shortcode($content); return array('post_id' => $item->ID, 'text' => $content, 'keyword' => $focus_keyword, 'url' => urldecode($item->post_name), 'pageTitle' => apply_filters('wpseo_title', wpseo_replace_vars($this->get_title($item->ID, $item->post_type), $item)), 'meta' => apply_filters('wpseo_metadesc', wpseo_replace_vars($this->get_meta_description($item->ID, $item->post_type), $item)), 'keyword_usage' => array($focus_keyword => WPSEO_Meta::keyword_usage($focus_keyword, $item->ID))); }
/** * Output the Google+ specific title */ public function google_plus_title() { if (is_singular()) { $title = WPSEO_Meta::get_value('google-plus-title'); /** * Filter: 'wpseo_googleplus_title' - Allow developers to change the Google+ specific title * * @api string $title The title string */ $title = trim(apply_filters('wpseo_googleplus_title', $title)); if (is_string($title) && $title !== '') { $title = wpseo_replace_vars($title, get_post()); echo '<meta itemprop="name" content="', esc_attr($title), '">', "\n"; } } }
/** * @covers wpseo_replace_vars */ public function test_wpseo_replace_vars() { // create author $user_id = $this->factory->user->create(array('user_login' => 'User_Login', 'display_name' => 'User_Nicename')); // create post $post_id = $this->factory->post->create(array('post_title' => 'Post_Title', 'post_content' => 'Post_Content', 'post_excerpt' => 'Post_Excerpt', 'post_author' => $user_id, 'post_date' => date('Y-m-d H:i:s', strtotime('2000-01-01 2:30:00')))); // get post $post = get_post($post_id); $input = '%%title%% %%excerpt%% %%date%% %%name%%'; $expected = 'Post_Title Post_Excerpt ' . mysql2date(get_option('date_format'), $post->post_date, true) . ' User_Nicename'; $output = wpseo_replace_vars($input, (array) $post); $this->assertEquals($expected, $output); /* TODO - Test all Basic Variables - Test all Advanced Variables */ }
/** * Prepares the replace vars for localization. * * @return array replace vars */ private function get_replace_vars() { $post = $this->get_metabox_post(); $cached_replacement_vars = array(); $vars_to_cache = array('date', 'id', 'sitename', 'sitedesc', 'sep', 'page', 'currenttime', 'currentdate', 'currentday', 'currentmonth', 'currentyear'); foreach ($vars_to_cache as $var) { $cached_replacement_vars[$var] = wpseo_replace_vars('%%' . $var . '%%', $post); } return $cached_replacement_vars; }
/** * Outputs the meta description element or returns the description text. * * @param bool $echo Whether or not to echo the description. * @return string */ function metadesc($echo = true) { if (get_query_var('paged') && get_query_var('paged') > 1) { return; } global $post, $wp_query; $options = get_wpseo_options(); $metadesc = ''; if (is_singular()) { $metadesc = wpseo_get_value('metadesc'); if ($metadesc == '' || !$metadesc) { if (isset($options['metadesc-' . $post->post_type]) && $options['metadesc-' . $post->post_type] != '') { $metadesc = wpseo_replace_vars($options['metadesc-' . $post->post_type], (array) $post); } } } else { if (is_search()) { $metadesc = ''; } else { if ($this->is_home_posts_page() && isset($options['metadesc-home'])) { $metadesc = wpseo_replace_vars($options['metadesc-home'], array()); } else { if ($this->is_posts_page()) { $metadesc = wpseo_get_value('metadesc', get_option('page_for_posts')); if (($metadesc == '' || !$metadesc) && isset($options['metadesc-' . $post->post_type])) { $page = get_post(get_option('page_for_posts')); $metadesc = wpseo_replace_vars($options['metadesc-' . $post->post_type], (array) $page); } } else { if ($this->is_home_static_page()) { global $post; $metadesc = wpseo_get_value('metadesc'); if (($metadesc == '' || !$metadesc) && isset($options['metadesc-' . $post->post_type])) { $metadesc = wpseo_replace_vars($options['metadesc-' . $post->post_type], (array) $post); } } else { if (is_category() || is_tag() || is_tax()) { $term = $wp_query->get_queried_object(); $metadesc = wpseo_get_term_meta($term, $term->taxonomy, 'desc'); if (!$metadesc && isset($options['metadesc-' . $term->taxonomy])) { $metadesc = wpseo_replace_vars($options['metadesc-' . $term->taxonomy], (array) $term); } } else { if (is_author()) { $author_id = get_query_var('author'); $metadesc = get_the_author_meta('wpseo_metadesc', $author_id); if (!$metadesc && isset($options['metadesc-author'])) { $metadesc = wpseo_replace_vars($options['metadesc-author'], (array) $wp_query->get_queried_object()); } } else { if (function_exists('is_post_type_archive') && is_post_type_archive()) { $post_type = get_post_type(); if (isset($options['metadesc-ptarchive-' . $post_type]) && '' != $options['metadesc-ptarchive-' . $post_type]) { $metadesc = $options['metadesc-ptarchive-' . $post_type]; } } } } } } } } } $metadesc = apply_filters('wpseo_metadesc', trim($metadesc)); if ($echo) { if (!empty($metadesc)) { echo '<meta name="description" content="' . esc_attr(strip_tags(stripslashes($metadesc))) . '"/>' . "\n"; } else { if (current_user_can('manage_options') && is_singular()) { echo '<!-- ' . __('Admin only notice: this page doesn\'t show a meta description because it doesn\'t have one, either write it for this page specifically or go into the SEO -> Titles menu and set up a template.', 'wordpress-seo') . ' -->' . "\n"; } } } else { return $metadesc; } }
/** * Output the OpenGraph description, specific OG description first, if not, grab the meta description. * * @param bool $echo Whether to echo or return the description * * @return string $ogdesc */ public function description($echo = true) { $ogdesc = ''; if (is_front_page()) { $ogdesc = $this->options['og_frontpage_desc'] !== '' ? $this->options['og_frontpage_desc'] : $this->metadesc(false); } if (is_singular()) { $ogdesc = WPSEO_Meta::get_value('opengraph-description'); // Replace WP SEO Variables $ogdesc = wpseo_replace_vars($ogdesc, get_post()); // Use metadesc if $ogdesc is empty if ($ogdesc === '') { $ogdesc = $this->metadesc(false); } // og:description is still blank so grab it from get_the_excerpt() if (!is_string($ogdesc) || is_string($ogdesc) && $ogdesc === '') { $ogdesc = str_replace('[…]', '…', strip_tags(get_the_excerpt())); } } if (is_category() || is_tag() || is_tax()) { $ogdesc = trim(strip_tags(term_description())); } // Strip shortcodes if any $ogdesc = strip_shortcodes($ogdesc); /** * Filter: 'wpseo_opengraph_desc' - Allow changing the OpenGraph description * * @api string $ogdesc The description string. */ $ogdesc = apply_filters('wpseo_opengraph_desc', $ogdesc); if (is_string($ogdesc) && $ogdesc !== '') { if ($echo !== false) { $this->og_tag('og:description', $ogdesc); } } return $ogdesc; }
/** * Generates the meta description text. */ private function generate_metadesc() { global $post, $wp_query; $metadesc = ''; $metadesc_override = false; $post_type = ''; $template = ''; if (is_object($post) && (isset($post->post_type) && $post->post_type !== '')) { $post_type = $post->post_type; } if (is_singular()) { if ($metadesc === '' && $post_type !== '' && isset($this->options['metadesc-' . $post_type])) { $template = $this->options['metadesc-' . $post_type]; $term = $post; } $metadesc_override = WPSEO_Meta::get_value('metadesc'); } else { if (is_search()) { $metadesc = ''; } elseif ($this->is_home_posts_page()) { $template = $this->options['metadesc-home-wpseo']; $term = array(); if (empty($template)) { $template = get_bloginfo('description'); } } elseif ($this->is_posts_page()) { $metadesc = WPSEO_Meta::get_value('metadesc', get_option('page_for_posts')); if ($metadesc === '' && $post_type !== '' && isset($this->options['metadesc-' . $post_type])) { $page = get_post(get_option('page_for_posts')); $template = $this->options['metadesc-' . $post_type]; $term = $page; } } elseif ($this->is_home_static_page()) { $metadesc = WPSEO_Meta::get_value('metadesc'); if ($metadesc === '' && $post_type !== '' && isset($this->options['metadesc-' . $post_type])) { $template = $this->options['metadesc-' . $post_type]; } } elseif (is_category() || is_tag() || is_tax()) { $term = $wp_query->get_queried_object(); $metadesc_override = WPSEO_Taxonomy_Meta::get_term_meta($term, $term->taxonomy, 'desc'); if (is_object($term) && isset($term->taxonomy, $this->options['metadesc-tax-' . $term->taxonomy])) { $template = $this->options['metadesc-tax-' . $term->taxonomy]; } } elseif (is_author()) { $author_id = get_query_var('author'); $metadesc = get_the_author_meta('wpseo_metadesc', $author_id); if ((!is_string($metadesc) || $metadesc === '') && '' !== $this->options['metadesc-author-wpseo']) { $template = $this->options['metadesc-author-wpseo']; } } elseif (is_post_type_archive()) { $post_type = get_query_var('post_type'); if (is_array($post_type)) { $post_type = reset($post_type); } if (isset($this->options['metadesc-ptarchive-' . $post_type])) { $template = $this->options['metadesc-ptarchive-' . $post_type]; } } elseif (is_archive()) { $template = $this->options['metadesc-archive-wpseo']; } // If we're on a paginated page, and the template doesn't change for paginated pages, bail. if ((!is_string($metadesc) || $metadesc === '') && get_query_var('paged') && get_query_var('paged') > 1 && $template !== '') { if (strpos($template, '%%page') === false) { $metadesc = ''; } } } $post_data = $post; if (is_string($metadesc_override) && '' !== $metadesc_override) { $metadesc = $metadesc_override; if (isset($term)) { $post_data = $term; } } else { if ((!is_string($metadesc) || '' === $metadesc) && '' !== $template) { if (!isset($term)) { $term = $wp_query->get_queried_object(); } $metadesc = $template; $post_data = $term; } } $metadesc = wpseo_replace_vars($metadesc, $post_data); /** * Filter: 'wpseo_metadesc' - Allow changing the WP SEO meta description sentence. * * @api string $metadesc The description sentence. */ $this->metadesc = apply_filters('wpseo_metadesc', trim($metadesc)); }
/** * Used in the editor to replace vars for the snippet preview */ function wpseo_ajax_replace_vars() { check_ajax_referer('wpseo-replace-vars'); $post = get_post($_POST['post_id']); $omit = array('excerpt', 'excerpt_only', 'title'); echo wpseo_replace_vars(stripslashes($_POST['string']), $post, $omit); die; }
/** * Get a single sitemap line to output in the xml sitemap * * @param $val * @param $key * @param $xtra * * @return null|string */ private function get_single_sitemap_line($val, $key, $xtra) { $val = $this->clean_string($val); if (in_array($key, array('description', 'category', 'tag', 'title'))) { $val = ent2ncr(esc_html($val)); } if (!empty($val)) { return "\t\t\t<video:" . $key . $xtra . '>' . wpseo_replace_vars($val, array()) . '</video:' . $key . ">\n"; } return null; }
public function _meta_keywords() { $wpseo_front = null; if (isset($GLOBALS['wpseo_front'])) { $wpseo_front = $GLOBALS['wpseo_front']; } elseif (class_exists('WPSEO_Frontend') && method_exists('WPSEO_Frontend', 'get_instance')) { $wpseo_front = WPSEO_Frontend::get_instance(); } $current_action = $this->controller->get_current_action(); switch ($current_action) { case 'showlisting': global $post; $listing_id = get_query_var('listing') ? wpbdp_get_post_by_slug(get_query_var('listing'))->ID : wpbdp_getv($_GET, 'id', get_query_var('id')); $prev_post = $post; $post = get_post($listing_id); if (is_object($wpseo_front)) { $wpseo_front->metadesc(); $wpseo_front->metakeywords(); } $post = $prev_post; break; case 'browsecategory': case 'browsetag': if ($current_action == 'browsetag') { $term = get_term_by('slug', get_query_var('tag'), WPBDP_TAGS_TAX); } else { $term = get_term_by('slug', get_query_var('category'), WPBDP_CATEGORY_TAX); if (!$term && get_query_var('category_id')) { $term = get_term_by('id', get_query_var('category_id'), WPBDP_CATEGORY_TAX); } } if ($term) { $metadesc = method_exists('WPSEO_Taxonomy_Meta', 'get_term_meta') ? WPSEO_Taxonomy_Meta::get_term_meta($term, $term->taxonomy, 'desc') : wpseo_get_term_meta($term, $term->taxonomy, 'desc'); if (!$metadesc && is_object($wpseo_front) && isset($wpseo_front->options['metadesc-tax-' . $term->taxonomy])) { $metadesc = wpseo_replace_vars($wpseo_front->options['metadesc-tax-' . $term->taxonomy], (array) $term); } if ($metadesc) { echo '<meta name="description" content="' . esc_attr(strip_tags(stripslashes($metadesc))) . '"/>' . "\n"; } } break; case 'main': if (is_object($wpseo_front)) { $wpseo_front->metadesc(); $wpseo_front->metakeywords(); } break; default: break; } }
/** * Retrieve the page title. * * @param int $post_id Post to retrieve the title for. * * @return string */ private function page_title($post_id) { $fixed_title = WPSEO_Meta::get_value('title', $post_id); if ($fixed_title !== '') { return $fixed_title; } $post = get_post($post_id); $options = WPSEO_Options::get_option('wpseo_titles'); if (is_object($post) && (isset($options['title-' . $post->post_type]) && $options['title-' . $post->post_type] !== '')) { $title_template = $options['title-' . $post->post_type]; $title_template = str_replace(' %%page%% ', ' ', $title_template); return wpseo_replace_vars($title_template, $post); } return wpseo_replace_vars('%%title%%', $post); }
function ctfw_event_calendar_head_title($title, $sep, $seplocation) { global $post; $new_title = $title; // Theme supports this? $support = get_theme_support('ctfw-event-calendar-head-title'); if (!empty($support)) { // Arguments from theme support or default $args = isset($support[0]) ? $support[0] : array(); $args = wp_parse_args($args, array('page_template' => 'events-calendar.php')); // Only on event calendar page template if (is_page_template(CTFW_THEME_PAGE_TPL_DIR . '/' . $args['page_template'])) { $parts = array(); // Get month if (!empty($_GET['month'])) { /* translators: this is the PHP date format used for <title> on event calendar months */ $parts[] = date_i18n(_x('F Y', 'event calendar', 'church-theme-framework'), strtotime($_GET['month'])); } // Get category if (!empty($_GET['category'])) { // Get term from slug $category = get_term_by('slug', $_GET['category'], 'ctc_event_category'); // Get name if (!empty($category->name)) { $parts[] = wptexturize($category->name); } } // Combine parts if ($parts) { // Is Yoast SEO plugin active? $wpseo_separator = ''; if (function_exists('wpseo_replace_vars')) { $wpseo_separator = trim(wpseo_replace_vars('%%sep%%', array())); if (!empty($wpseo_separator)) { $wpseo_separator = ' ' . $wpseo_separator . ' '; } } // Get separator if ($wpseo_separator) { // use Yoast SEO plugin's separator if available $separator = $wpseo_separator; } else { // otherwise fall back to ' | ' WordPress default /* translators: separator for <title> content */ $separator = _x(' | ', 'head title', 'church-theme-framework'); } // Combine month and category into suffix $month_category = $separator . implode($separator, $parts); // separator at left $month_category_right = implode($separator, $parts) . $separator; // separator at right // Post title was found in <title> // Insert month and category after that (e.g. Monthly Calendar - Month - Category - Site Title) $post_title = isset($post->post_title) ? wptexturize($post->post_title) : ''; $post_title_esc = preg_quote($post_title); if (!empty($post_title) && preg_match('/' . $post_title_esc . preg_quote($separator) . '/', $title)) { $new_title = preg_replace('/(' . $post_title_esc . ')/', '$1' . $month_category, $title); } else { $site_title = get_bloginfo('name', 'display'); // wptexturize applied $site_title_esc = preg_quote($site_title); if (!empty($site_title)) { // Is site title found at end of title? // Insert month and category before that (e.g. Custom Title - Month - Category - Site Name) if (preg_match('/' . $site_title_esc . '$/', $title)) { $new_title = preg_replace('/(' . $site_title_esc . ')$/', $month_category_right . '$1', $title); } else { $new_title .= $month_category; } } } } } } return $new_title; }
/** * @covers WPSEO_Frontend::get_title_from_options */ public function test_get_title_from_options() { // should return an empty string $this->assertEmpty(self::$class_instance->get_title_from_options('__not-existing-index')); // create and go to post $post_id = $this->factory->post->create(); $this->go_to(get_permalink($post_id)); $var_source = (array) get_queried_object(); $expected_title = wpseo_replace_vars('%%title%% %%sep%% %%sitename%%', $var_source); $this->assertEquals($expected_title, self::$class_instance->get_title_from_options('__not-existing-index', $var_source)); // test with an option that exists $index = 'title-post'; $expected_title = wpseo_replace_vars(self::$class_instance->options[$index], $var_source); $this->assertEquals($expected_title, self::$class_instance->get_title_from_options($index, $var_source)); }
function output($post) { global $wpseo_metabox; $options = get_wpseo_options(); if (is_int($post)) { $post = get_post($post); } if (!$post) { return; } if (!class_exists('DOMDocument')) { $output = '<div class="wpseo_msg"><p><strong>' . __('Error') . ':</strong> ' . sprintf(__("your hosting environment does not support PHP's %sDocument Object Model%s."), '<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.") . '</p></div>'; return $output; } if (!wpseo_get_value('focuskw')) { $output = '<div class="wpseo_msg"><p><strong>' . __('Error') . ':</strong> ' . __("you have not specified a focus keyword, you'll have to enter one, then save or update this post, before this report works.") . '</p></div>'; return $output; } $output = '<div class="wpseo_msg"><p><strong>' . __('Note') . ':</strong> ' . __('to update this page analysis, save as draft or update and check this tab again') . '.</p></div>'; $results = ''; $job = array(); $sampleurl = get_sample_permalink($post->ID); $job["pageUrl"] = str_replace('%postname%', $sampleurl[1], $sampleurl[0]); $job["pageSlug"] = urldecode($post->post_name); $job["keyword"] = wpseo_get_value('focuskw'); $job["keyword_folded"] = $this->strip_separators_and_fold($job["keyword"]); $dom = new domDocument(); $dom->strictErrorChecking = false; $dom->preserveWhiteSpace = false; @$dom->loadHTML($post->post_content); $xpath = new DOMXPath($dom); $statistics = new TextStatistics(); // Keyword $this->ScoreKeyword($job, $results); // Title if (wpseo_get_value('title')) { $title = wpseo_get_value('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%%'; } $title = wpseo_replace_vars($title_template, (array) $post); } $this->ScoreTitle($job, $results, $title, $statistics); unset($title); // Meta description $description = ''; if (wpseo_get_value('metadesc')) { $description = wpseo_get_value('metadesc'); } else { if (isset($options['metadesc-' . $post->post_type]) && $options['metadesc-' . $post->post_type] != '') { $description = wpseo_replace_vars($options['metadesc-' . $post->post_type], (array) $post); } } $this->ScoreDescription($job, $results, $description, $wpseo_metabox->wpseo_meta_length, $statistics); unset($description); // Body $body = $this->GetBody($post); $firstp = $this->GetFirstParagraph($post); $this->ScoreBody($job, $results, $body, $firstp, $statistics); unset($body); unset($firstp); // URL $this->ScoreUrl($job, $results, $statistics); // Headings $headings = $this->GetHeadings($post->post_content); $this->ScoreHeadings($job, $results, $headings); unset($headings); // Images $alts = $this->GetImagesAltText($post->post_content); $imgs = $this->GetImageCount($dom, $xpath); $this->ScoreImagesAltText($job, $results, $alts, $imgs); unset($alts); unset($imgs); // Anchors $anchors = $this->GetAnchorTexts($dom, $xpath); $count = $this->GetAnchorCount($dom, $xpath); $this->ScoreAnchorTexts($job, $results, $anchors, $count); unset($anchors); unset($count); unset($dom); asort($results); $output .= '<table class="wpseoanalysis">'; foreach ($results as $result) { $scoreval = substr($result, 0, 1); switch ($scoreval) { case 1: case 2: case 3: $score = 'poor'; break; case 4: case 5: case 6: $score = 'ok'; break; case 7: case 8: case 9: $score = 'good'; break; } $analysis = substr($result, 2, strlen($result)); $output .= '<tr><td class="score"><img alt="' . $score . '" src="' . WPSEO_URL . 'images/score_' . $score . '.png"/></td><td>' . $analysis . '</td></tr>'; } $output .= '</table>'; $output .= '<hr/>'; $output .= '<p style="font-size: 13px;"><a href="http://yoa.st/linkdex"><img class="alignleft" style="margin: 0 10px 5px 0;" src="' . WPSEO_URL . 'images/linkdex-logo.png" alt="Linkdex"/></a>' . 'This page analysis brought to you by the collaboration of Yoast and <a href="http://yoa.st/linkdex">Linkdex</a>. <a href="http://yoa.st/linkdex">Linkdex</a> is an SEO suite that helps you optimize your site and offers you all the SEO tools you\'ll need. Yoast uses <a href="http://yoa.st/linkdex">Linkdex</a> and highly recommends you do too!' . '</p>'; unset($results); unset($job); return $output; }
/** * Getting the keywords * * @param WP_Post $post The post object with the values. * * @return string */ private function get_keywords($post) { $keywords = WPSEO_Meta::get_value('metakeywords', $post->ID); $option_meta_key = 'metakey-' . $post->post_type; if ($keywords === '' && (is_object($post) && (isset($this->options[$option_meta_key]) && $this->options[$option_meta_key] !== ''))) { $keywords = wpseo_replace_vars($this->options[$option_meta_key], $post); } return $keywords; }
function page_title($postid) { $fixed_title = wpseo_get_value('title', $postid); if ($fixed_title) { return $fixed_title; } else { $post = get_post($postid); $options = get_wpseo_options(); if (isset($options['title-' . $post->post_type]) && !empty($options['title-' . $post->post_type])) { return wpseo_replace_vars($options['title-' . $post->post_type], (array) $post); } else { return wpseo_replace_vars('%%title%%', (array) $post); } } }
/** * Used in the editor to replace vars for the snippet preview */ function wpseo_ajax_replace_vars() { global $post; check_ajax_referer('wpseo-replace-vars'); $post = get_post(intval(WPSEO_Utils::filter_input(INPUT_POST, 'post_id'))); $omit = array('excerpt', 'excerpt_only', 'title'); echo wpseo_replace_vars(stripslashes(WPSEO_Utils::filter_input(INPUT_POST, 'string')), $post, $omit); die; }
/** * Output the OpenGraph description, specific OG description first, if not, grab the meta description. * * @param bool $echo Whether to echo or return the description. * * @return string $ogdesc */ public function description($echo = true) { $ogdesc = ''; $frontend = WPSEO_Frontend::get_instance(); if (is_front_page()) { if (isset($this->options['og_frontpage_desc']) && $this->options['og_frontpage_desc'] !== '') { $ogdesc = wpseo_replace_vars($this->options['og_frontpage_desc'], null); } else { $ogdesc = $frontend->metadesc(false); } } $is_posts_page = $frontend->is_posts_page(); if (is_singular() || $is_posts_page) { $post_id = $is_posts_page ? get_option('page_for_posts') : get_the_ID(); $post = get_post($post_id); $ogdesc = WPSEO_Meta::get_value('opengraph-description', $post_id); // Replace Yoast SEO Variables. $ogdesc = wpseo_replace_vars($ogdesc, $post); // Use metadesc if $ogdesc is empty. if ($ogdesc === '') { $ogdesc = $frontend->metadesc(false); } // Tag og:description is still blank so grab it from get_the_excerpt(). if (!is_string($ogdesc) || is_string($ogdesc) && $ogdesc === '') { $ogdesc = str_replace('[…]', '…', strip_tags(get_the_excerpt())); } } if (is_category() || is_tag() || is_tax()) { $ogdesc = WPSEO_Taxonomy_Meta::get_meta_without_term('opengraph-description'); if ($ogdesc === '') { $ogdesc = $frontend->metadesc(false); } if ($ogdesc === '') { $ogdesc = trim(strip_tags(term_description())); } if ($ogdesc === '') { $ogdesc = WPSEO_Taxonomy_Meta::get_meta_without_term('desc'); } } // Strip shortcodes if any. $ogdesc = strip_shortcodes($ogdesc); /** * Filter: 'wpseo_opengraph_desc' - Allow changing the OpenGraph description * * @api string $ogdesc The description string. */ $ogdesc = trim(apply_filters('wpseo_opengraph_desc', $ogdesc)); if (is_string($ogdesc) && $ogdesc !== '') { if ($echo !== false) { $this->og_tag('og:description', $ogdesc); } } return $ogdesc; }
/** * Calculate the page analysis results for post. * * @param object $post Post to calculate the results for. * @return array */ function calculate_results($post) { $options = get_wpseo_options(); 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 (!wpseo_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)); wpseo_set_value('linkdex', 0, $post->ID); return $result; } $results = array(); $job = array(); $sampleurl = get_sample_permalink($post); $job["pageUrl"] = preg_replace('/%(post|page)name%/', $sampleurl[1], $sampleurl[0]); $job["pageSlug"] = urldecode($post->post_name); $job["keyword"] = trim(wpseo_get_value('focuskw')); $job["keyword_folded"] = $this->strip_separators_and_fold($job["keyword"]); $job["post_id"] = $post->ID; $dom = new domDocument(); $dom->strictErrorChecking = false; $dom->preserveWhiteSpace = false; @$dom->loadHTML($post->post_content); $xpath = new DOMXPath($dom); $statistics = new Yoast_TextStatistics(); // Check if this focus keyword has been used already. $this->check_double_focus_keyword($job, $results); // Keyword $this->score_keyword($job['keyword'], $results); // Title if (wpseo_get_value('title')) { $job['title'] = wpseo_get_value('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, (array) $post); } $this->score_title($job, $results, $statistics); // Meta description $description = ''; if (wpseo_get_value('metadesc')) { $description = wpseo_get_value('metadesc'); } else { if (isset($options['metadesc-' . $post->post_type]) && !empty($options['metadesc-' . $post->post_type])) { $description = wpseo_replace_vars($options['metadesc-' . $post->post_type], (array) $post); } } $meta_length = apply_filters('wpseo_metadesc_length', 156, $post); $this->score_description($job, $results, $description, $statistics, $meta_length); unset($description); // Body $body = $this->get_body($post); $firstp = $this->get_first_paragraph($post); $this->score_body($job, $results, $body, $firstp, $statistics); unset($body); unset($firstp); // URL $this->score_url($job, $results, $statistics); // Headings $headings = $this->get_headings($post->post_content); $this->score_headings($job, $results, $headings); unset($headings); // Images $imgs = array(); $imgs['count'] = substr_count($post->post_content, '<img'); $imgs = $this->get_images_alt_text($post, $imgs); $this->score_images_alt_text($job, $results, $imgs); unset($imgs); // 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 = round($overall / $overall_max * 100); wpseo_set_value('linkdex', absint($score), $post->ID); return $results; }
/** * Prepares the replace vars for localization. * * @return array replace vars */ private function get_replace_vars() { $post = $this->get_metabox_post(); $cached_replacement_vars = array(); $vars_to_cache = array('date', 'id', 'sitename', 'sitedesc', 'sep', 'page', 'currenttime', 'currentdate', 'currentday', 'currentmonth', 'currentyear'); foreach ($vars_to_cache as $var) { $cached_replacement_vars[$var] = wpseo_replace_vars('%%' . $var . '%%', $post); } // Merge custom replace variables with the WordPress ones. return array_merge($cached_replacement_vars, $this->get_custom_replace_vars($post)); }
/** * Output the OpenGraph description, specific OG description first, if not, grab the meta description. * * @param bool $echo Whether to echo or return the description * * @return string $ogdesc */ public function description($echo = true) { $ogdesc = ''; if (is_front_page()) { if (isset($this->options['og_frontpage_desc']) && $this->options['og_frontpage_desc'] !== '') { $ogdesc = wpseo_replace_vars($this->options['og_frontpage_desc'], null); } else { $ogdesc = WPSEO_Frontend::get_instance()->metadesc(false); } } if (is_singular()) { $ogdesc = WPSEO_Meta::get_value('opengraph-description'); // Replace WP SEO Variables $ogdesc = wpseo_replace_vars($ogdesc, get_post()); // Use metadesc if $ogdesc is empty if ($ogdesc === '') { $ogdesc = WPSEO_Frontend::get_instance()->metadesc(false); } // og:description is still blank so grab it from get_the_excerpt() if (!is_string($ogdesc) || is_string($ogdesc) && $ogdesc === '') { $ogdesc = str_replace('[…]', '…', strip_tags(get_the_excerpt())); } } if (is_category() || is_tag() || is_tax()) { $ogdesc = WPSEO_Frontend::get_instance()->metadesc(false); if ('' == $ogdesc) { $ogdesc = trim(strip_tags(term_description())); } if ('' == $ogdesc) { $term = $GLOBALS['wp_query']->get_queried_object(); $ogdesc = WPSEO_Taxonomy_Meta::get_term_meta($term, $term->taxonomy, 'desc'); } } // Strip shortcodes if any $ogdesc = strip_shortcodes($ogdesc); /** * Filter: 'wpseo_opengraph_desc' - Allow changing the OpenGraph description * * @api string $ogdesc The description string. */ $ogdesc = trim(apply_filters('wpseo_opengraph_desc', $ogdesc)); if (is_string($ogdesc) && $ogdesc !== '') { if ($echo !== false) { $this->og_tag('og:description', $ogdesc); } } return $ogdesc; }
/** * Used in the editor to replace vars for the snippet preview */ function wpseo_ajax_replace_vars() { global $post; check_ajax_referer('wpseo-replace-vars'); $post = get_post(intval(filter_input(INPUT_POST, 'post_id'))); global $wp_query; $wp_query->queried_object = $post; $wp_query->queried_object_id = $post->ID; $omit = array('excerpt', 'excerpt_only', 'title'); echo wpseo_replace_vars(stripslashes(filter_input(INPUT_POST, 'string')), $post, $omit); die; }
/** * 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; }
/** * @param WP_Post $post The post for which to build the analyzer data. * * @return array */ private function post_to_response(WP_Post $post) { $focus_keyword = WPSEO_Meta::get_value('focuskw', $post->ID); return array('post_id' => $post->ID, 'text' => $post->post_content, 'keyword' => $focus_keyword, 'url' => urldecode($post->post_name), 'pageTitle' => apply_filters('wpseo_title', wpseo_replace_vars($this->get_title($post->ID, $post->post_type), $post)), 'meta' => apply_filters('wpseo_metadesc', wpseo_replace_vars($this->get_meta_description($post->ID, $post->post_type), $post)), 'keyword_usage' => array($focus_keyword => WPSEO_Meta::keyword_usage($focus_keyword, $post->ID))); }
private function title() { global $post, $wp_query; if (empty($post) && is_singular()) { $post = $wp_query->get_queried_object(); } $options = get_wpseo_options(); if (is_home() && 'posts' == get_option('show_on_front')) { if (isset($options['title-home']) && $options['title-home'] != '') { $title = wpseo_replace_vars($options['title-home'], array()); } else { $title = get_bloginfo('name'); } } else { if (is_home() && 'posts' != get_option('show_on_front')) { // For some reason, in some instances is_home returns true for the front page when page_for_posts is not set. if (get_option('page_for_posts') == 0) { $post = get_post(get_option('page_on_front')); } else { $post = get_post(get_option('page_for_posts')); } $fixed_title = wpseo_get_value('title'); if ($fixed_title) { $title = $fixed_title; } else { if (isset($options['title-' . $post->post_type]) && !empty($options['title-' . $post->post_type])) { $title = wpseo_replace_vars($options['title-' . $post->post_type], (array) $post); } else { $title = get_bloginfo('name'); } } } else { if (is_singular()) { $fixed_title = wpseo_get_value('title'); if ($fixed_title) { $title = $fixed_title; } else { if (isset($options['title-' . $post->post_type]) && !empty($options['title-' . $post->post_type])) { $title = wpseo_replace_vars($options['title-' . $post->post_type], (array) $post); } else { $title = get_the_title(); $title = apply_filters('single_post_title', $title); } } } else { if (is_category() || is_tag() || is_tax()) { $term = $wp_query->get_queried_object(); $title = trim(wpseo_get_term_meta($term, $term->taxonomy, 'title')); if (!$title || empty($title)) { if (isset($options['title-' . $term->taxonomy]) && !empty($options['title-' . $term->taxonomy])) { $title = wpseo_replace_vars($options['title-' . $term->taxonomy], (array) $term); } else { if (is_category()) { $title = single_cat_title('', false); } else { if (is_tag()) { $title = single_tag_title('', false); } else { if (is_tax()) { if (function_exists('single_term_title')) { $title = single_term_title('', false); } else { $term = $wp_query->get_queried_object(); $title = $term->name; } } } } } } } else { if (is_search()) { if (isset($options['title-search']) && !empty($options['title-search'])) { $title = wpseo_replace_vars($options['title-search'], (array) $wp_query->get_queried_object()); } else { $title = __('Search for "') . get_search_query() . '"'; } } else { if (is_author()) { $author_id = get_query_var('author'); $title = get_the_author_meta('wpseo_title', $author_id); if (empty($title)) { if (isset($options['title-author']) && !empty($options['title-author'])) { $title = wpseo_replace_vars($options['title-author'], array()); } else { $title = get_the_author_meta('display_name', $author_id); } } } else { if (is_post_type_archive()) { $post_type = get_post_type(); if (isset($options['title-ptarchive-' . $post_type]) && '' != $options['title-ptarchive-' . $post_type]) { return $options['title-ptarchive-' . $post_type]; } else { $post_type_obj = get_post_type_object($post_type); $title = $post_type_obj->labels->menu_name; } } else { if (is_archive()) { if (isset($options['title-archive']) && !empty($options['title-archive'])) { $title = wpseo_replace_vars($options['title-archive'], array('post_title' => $title)); } else { if (is_month()) { $title = single_month_title(' ', false) . ' ' . __('Archives'); } else { if (is_year()) { $title = get_query_var('year') . ' ' . __('Archives'); } } } } else { if (is_404()) { if (isset($options['title-404']) && !empty($options['title-404'])) { $title = wpseo_replace_vars($options['title-404'], array('post_title' => $title)); } else { $title = __('Page not found'); } } } } } } } } } } echo "<meta property='og:title' content='" . esc_attr(strip_tags(stripslashes($title))) . "'/>\n"; }
/** * Prepares the replace vars for localization. * * @return array replace vars. */ private function get_replace_vars() { $term_id = filter_input(INPUT_GET, 'tag_ID'); $term = get_term_by('id', $term_id, $this->get_taxonomy()); $cached_replacement_vars = array(); $vars_to_cache = array('date', 'id', 'sitename', 'sitedesc', 'sep', 'page', 'currenttime', 'currentdate', 'currentday', 'currentmonth', 'currentyear', 'term_title', 'term_description', 'category_description', 'tag_description', 'searchphrase'); foreach ($vars_to_cache as $var) { $cached_replacement_vars[$var] = wpseo_replace_vars('%%' . $var . '%%', $term); } return $cached_replacement_vars; }
/** * Outputs the meta description element or returns the description text. * * @param bool $echo Whether or not to echo the description. * * @return string */ public function metadesc($echo = true) { if (get_query_var('paged') && get_query_var('paged') > 1) { return ''; } global $post, $wp_query; $metadesc = ''; $post_type = ''; if (is_object($post) && (isset($post->post_type) && $post->post_type !== '')) { $post_type = $post->post_type; } if (is_singular()) { $metadesc = WPSEO_Meta::get_value('metadesc'); if ($metadesc === '' && $post_type !== '' && (isset($this->options['metadesc-' . $post_type]) && $this->options['metadesc-' . $post_type] !== '')) { $metadesc = wpseo_replace_vars($this->options['metadesc-' . $post_type], (array) $post); } } else { if (is_search()) { $metadesc = ''; } elseif ($this->is_home_posts_page() && $this->options['metadesc-home-wpseo'] !== '') { $metadesc = wpseo_replace_vars($this->options['metadesc-home-wpseo'], array()); } elseif ($this->is_posts_page()) { $metadesc = WPSEO_Meta::get_value('metadesc', get_option('page_for_posts')); if ($metadesc === '' && $post_type !== '' && (isset($this->options['metadesc-' . $post_type]) && $this->options['metadesc-' . $post_type] !== '')) { $page = get_post(get_option('page_for_posts')); $metadesc = wpseo_replace_vars($this->options['metadesc-' . $post_type], (array) $page); } } elseif ($this->is_home_static_page()) { $metadesc = WPSEO_Meta::get_value('metadesc'); if ($metadesc === '' && $post_type !== '' && (isset($this->options['metadesc-' . $post_type]) && $this->options['metadesc-' . $post_type] !== '')) { $metadesc = wpseo_replace_vars($this->options['metadesc-' . $post_type], (array) $post); } } elseif (is_category() || is_tag() || is_tax()) { $term = $wp_query->get_queried_object(); $metadesc = WPSEO_Taxonomy_Meta::get_term_meta($term, $term->taxonomy, 'desc'); if ((!is_string($metadesc) || $metadesc === '') && (is_object($term) && isset($term->taxonomy) && (isset($this->options['metadesc-tax-' . $term->taxonomy]) && $this->options['metadesc-tax-' . $term->taxonomy] !== ''))) { $metadesc = wpseo_replace_vars($this->options['metadesc-tax-' . $term->taxonomy], (array) $term); } } elseif (is_author()) { $author_id = get_query_var('author'); $metadesc = get_the_author_meta('wpseo_metadesc', $author_id); if (!$metadesc && $this->options['metadesc-author-wpseo'] !== '') { $metadesc = wpseo_replace_vars($this->options['metadesc-author-wpseo'], (array) $wp_query->get_queried_object()); } } elseif (is_post_type_archive()) { $post_type = get_query_var('post_type'); if (is_array($post_type)) { $post_type = reset($post_type); } if (isset($this->options['metadesc-ptarchive-' . $post_type]) && $this->options['metadesc-ptarchive-' . $post_type] !== '') { $metadesc = wpseo_replace_vars($this->options['metadesc-ptarchive-' . $post_type], (array) $wp_query->get_queried_object()); } } elseif (is_archive()) { if ($this->options['metadesc-archive-wpseo'] !== '') { $metadesc = wpseo_replace_vars($this->options['metadesc-archive-wpseo'], (array) $wp_query->get_queried_object()); } } } /** * Filter: 'wpseo_metadesc' - Allow changing the WP SEO meta description sentence. * * @api string $metadesc The description sentence. */ $metadesc = apply_filters('wpseo_metadesc', trim($metadesc)); if ($echo !== false) { if (is_string($metadesc) && $metadesc !== '') { echo '<meta name="description" content="' . esc_attr(strip_tags(stripslashes($metadesc))) . '"/>' . "\n"; } elseif (current_user_can('manage_options') && is_singular()) { echo '<!-- ' . __('Admin only notice: this page doesn\'t show a meta description because it doesn\'t have one, either write it for this page specifically or go into the SEO -> Titles menu and set up a template.', 'wordpress-seo') . ' -->' . "\n"; } } else { return $metadesc; } }
/** * 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; }