function wpseo_metadesc($metadesc)
 {
     if (empty($metadesc)) {
         $tax_metadesc = WPSEO_Taxonomy_Meta::get_term_meta($this->term, $this->term->taxonomy, 'desc');
         if (!empty($tax_metadesc)) {
             return $tax_metadesc;
         }
     }
     return $metadesc;
 }
예제 #2
0
 /**
  * Show the SEO inputs for term.
  *
  * @param object $term Term to show the edit boxes for.
  */
 function term_seo_form($term)
 {
     global $wpseo_taxonomy;
     $tax_meta = WPSEO_Taxonomy_Meta::get_term_meta((int) $term->term_id, $term->taxonomy);
     echo '<h2>' . __('Local SEO Settings', 'yoast-local-seo') . '</h2>';
     echo '<table class="form-table wpseo-local-taxonomy-form">';
     echo '<tr class="form-field">';
     echo '<th scope="row">';
     echo '<label class="textinput" for="show_route_label">' . __('Custom marker', 'yoast-local-seo') . ':</label>';
     echo '</th>';
     echo '<td>';
     echo '<img src="' . (isset($tax_meta['wpseo_local_custom_marker']) ? wp_get_attachment_url($tax_meta['wpseo_local_custom_marker']) : '') . '" id="custom_marker" />';
     echo '<button class="set_custom_images button">' . __('Set custom marker image', 'yoast-local-seo') . '</button>';
     echo '<p class="description">' . __('A custom marker can be set per category. If no marker is set here, the global marker will be used.', 'yoast-local-seo') . '</p>';
     if (isset($tax_meta['wpseo_local_custom_marker']) && '' != $tax_meta['wpseo_local_custom_marker']) {
         echo '<br /><button id="remove_marker">' . __('Remove marker', 'yoast-local-seo') . '</button>';
     }
     echo '<input type="hidden" id="hidden_custom_marker" name="wpseo_local_custom_marker" value="' . (isset($tax_meta['wpseo_local_custom_marker']) && $tax_meta['wpseo_local_custom_marker'] !== '' ? $tax_meta['wpseo_local_custom_marker'] : '') . '">';
     //$wpseo_taxonomy->form_row( 'wpseo_local_custom_marker', '', '', $tax_meta, 'upload' );
     echo '</td>';
     echo '</tr>';
     echo '</table>';
 }
예제 #3
0
 public function getTitle()
 {
     if ($this->title_is_loaded === false) {
         $this->title_is_loaded = true;
         if ($this->post_loaded || $this->category_loaded) {
             $this->loadTheQuery();
             ob_start();
             $object = $GLOBALS['wp_query']->get_queried_object();
             if (function_exists('get_plugin_data') !== true) {
                 require_once $this->wordpress_location . '/wp-admin/includes/plugin.php';
             }
             if (file_exists($this->wordpress_location . '/wp-content/plugins/wordpress-seo/wp-seo.php') === true) {
                 $arDataWpSeo = get_plugin_data($this->wordpress_location . '/wp-content/plugins/wordpress-seo/wp-seo.php');
                 if (isset($arDataWpSeo['Version']) === true) {
                     $isRecentWpSeoVersion = version_compare($arDataWpSeo['Version'], '1.5.0', '>=');
                     if ($isRecentWpSeoVersion === false) {
                         if ($this->post_loaded) {
                             if (function_exists('wpseo_get_value')) {
                                 $titleSeo = wpseo_get_value('title', $object->ID);
                             }
                         } elseif ($this->category_loaded) {
                             if (function_exists('wpseo_get_term_meta')) {
                                 $titleSeo = wpseo_get_term_meta($object, $object->taxonomy, 'title');
                             }
                         }
                     } else {
                         if ($this->post_loaded) {
                             if (method_exists('\\WPSEO_Meta', 'get_value')) {
                                 $titleSeo = \WPSEO_Meta::get_value('title', $object->ID);
                             }
                         } elseif ($this->category_loaded) {
                             if (method_exists('\\WPSEO_Taxonomy_Meta', 'get_term_meta')) {
                                 $titleSeo = \WPSEO_Taxonomy_Meta::get_term_meta($object, $object->taxonomy, 'title');
                             }
                         }
                     }
                 }
             }
             if (isset($titleSeo) === true) {
                 echo $titleSeo;
             } else {
                 the_title();
             }
             $this->title = ob_get_clean();
         }
     }
     return $this->title;
 }
/**
 * Returns the Content score element for the adminbar.
 *
 * @return string
 */
function wpseo_tax_adminbar_content_score()
{
    $rating = 0;
    if (is_tax() || is_category() || is_tag()) {
        $rating = WPSEO_Taxonomy_Meta::get_meta_without_term('content_score');
    }
    return wpseo_adminbar_score($rating);
}
예제 #5
0
/**
 * Retrieve a taxonomy term's meta value.
 *
 * @deprecated 1.5.0
 * @deprecated use WPSEO_Taxonomy_Meta::get_term_meta()
 * @see        WPSEO_Taxonomy_Meta::get_term_meta()
 *
 * @param string|object $term     term to get the meta value for
 * @param string        $taxonomy name of the taxonomy to which the term is attached
 * @param string        $meta     meta value to get
 *
 * @return void
 */
function wpseo_get_term_meta($term, $taxonomy, $meta)
{
    _deprecated_function(__FUNCTION__, 'WPSEO 1.5.0', 'WPSEO_Taxonomy_Meta::get_term_meta()');
    WPSEO_Taxonomy_Meta::get_term_meta($term, $taxonomy, $meta);
}
 /**
  * Get set of sitemap link data.
  *
  * @param string $type         Sitemap type.
  * @param int    $max_entries  Entries per sitemap.
  * @param int    $current_page Current page of the sitemap.
  *
  * @return array
  */
 public function get_sitemap_links($type, $max_entries, $current_page)
 {
     global $wpdb;
     $links = array();
     $taxonomy = get_taxonomy($type);
     if ($taxonomy === false || !$this->is_valid_taxonomy($taxonomy->name) || !$taxonomy->public) {
         return $links;
     }
     $options = $this->get_options();
     $steps = $max_entries;
     $offset = $current_page > 1 ? ($current_page - 1) * $max_entries : 0;
     /** This filter is documented in inc/sitemaps/class-taxonomy-sitemap-provider.php */
     $hide_empty = apply_filters('wpseo_sitemap_exclude_empty_terms', true, $taxonomy);
     $terms = get_terms($taxonomy->name, array('hide_empty' => $hide_empty));
     $terms = array_splice($terms, $offset, $steps);
     if (empty($terms)) {
         $terms = array();
     }
     // Grab last modified date.
     $sql = "\n\t\t\tSELECT MAX(p.post_modified_gmt) AS lastmod\n\t\t\tFROM\t{$wpdb->posts} AS p\n\t\t\tINNER JOIN {$wpdb->term_relationships} AS term_rel\n\t\t\t\tON\t\tterm_rel.object_id = p.ID\n\t\t\tINNER JOIN {$wpdb->term_taxonomy} AS term_tax\n\t\t\t\tON\t\tterm_tax.term_taxonomy_id = term_rel.term_taxonomy_id\n\t\t\t\tAND\t\tterm_tax.taxonomy = %s\n\t\t\t\tAND\t\tterm_tax.term_id = %d\n\t\t\tWHERE\tp.post_status IN ('publish','inherit')\n\t\t\t\tAND\t\tp.post_password = ''\n\t\t";
     foreach ($terms as $term) {
         $url = array();
         $tax_noindex = WPSEO_Taxonomy_Meta::get_term_meta($term, $term->taxonomy, 'noindex');
         $tax_sitemap_inc = WPSEO_Taxonomy_Meta::get_term_meta($term, $term->taxonomy, 'sitemap_include');
         if ($tax_noindex === 'noindex' && $tax_sitemap_inc !== 'always') {
             continue;
         }
         if ($tax_sitemap_inc === 'never') {
             continue;
         }
         $url['loc'] = WPSEO_Taxonomy_Meta::get_term_meta($term, $term->taxonomy, 'canonical');
         if (!is_string($url['loc']) || $url['loc'] === '') {
             $url['loc'] = get_term_link($term, $term->taxonomy);
             if ($options['trailingslash'] === true) {
                 $url['loc'] = trailingslashit($url['loc']);
             }
         }
         $url['mod'] = $wpdb->get_var($wpdb->prepare($sql, $term->taxonomy, $term->term_id));
         $url['images'] = $this->get_image_parser()->get_term_images($term);
         // Deprecated, kept for backwards data compat. R.
         $url['chf'] = 'daily';
         $url['pri'] = 1;
         /** This filter is documented at inc/sitemaps/class-post-type-sitemap-provider.php */
         $url = apply_filters('wpseo_sitemap_entry', $url, 'term', $term);
         if (!empty($url)) {
             $links[] = $url;
         }
     }
     return $links;
 }
 /**
  * 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));
 }
 /**
  * Check and, if applicable, update video details for a term description
  *
  * @since 1.3
  *
  * @param object  $term The term to check the description and possibly update the video details for.
  * @param boolean $echo Whether or not to echo the performed actions.
  *
  * @return mixed $vid The video array that was just stored, or "none" if nothing was stored
  *                    or false if not applicable.
  */
 public function update_video_term_meta($term, $echo = false)
 {
     $options = array_merge(WPSEO_Options::get_all(), get_option('wpseo_video'));
     if (!is_array($options['videositemap_taxonomies']) || $options['videositemap_taxonomies'] === array()) {
         return false;
     }
     if (!in_array($term->taxonomy, $options['videositemap_taxonomies'])) {
         return false;
     }
     $tax_meta = get_option('wpseo_taxonomy_meta');
     $old_vid = array();
     if (!isset($_POST['force'])) {
         if (isset($tax_meta[$term->taxonomy]['_video'][$term->term_id])) {
             $old_vid = $tax_meta[$term->taxonomy]['_video'][$term->term_id];
         }
     }
     $vid = array();
     $title = WPSEO_Taxonomy_Meta::get_term_meta($term->term_id, $term->taxonomy, 'wpseo_title');
     if (empty($title) && isset($options['title-' . $term->taxonomy]) && $options['title-' . $term->taxonomy] !== '') {
         $title = wpseo_replace_vars($options['title-' . $term->taxonomy], (array) $term);
     }
     if (empty($title)) {
         $title = $term->name;
     }
     $vid['title'] = htmlspecialchars($title);
     $vid['description'] = WPSEO_Taxonomy_Meta::get_term_meta($term->term_id, $term->taxonomy, 'wpseo_metadesc');
     if (!$vid['description']) {
         $vid['description'] = esc_attr(preg_replace('`\\s+`', ' ', wp_html_excerpt($this->strip_shortcodes(get_term_field('description', $term->term_id, $term->taxonomy)), 300)));
     }
     $vid['publication_date'] = date('Y-m-d\\TH:i:s+00:00');
     // concatenate genesis intro text and term description to index the videos for both
     $genesis_term_meta = get_option('genesis-term-meta');
     $content = '';
     if (isset($genesis_term_meta[$term->term_id]['intro_text']) && $genesis_term_meta[$term->term_id]['intro_text']) {
         $content .= $genesis_term_meta[$term->term_id]['intro_text'];
     }
     $content .= "\n" . $term->description;
     $content = stripslashes($content);
     $vid = $this->index_content($content, $vid, $old_vid, null);
     if ($vid != 'none') {
         $tax_meta[$term->taxonomy]['_video'][$term->term_id] = $vid;
         // Don't bother with the complete tax meta validation
         $tax_meta['wpseo_already_validated'] = true;
         update_option('wpseo_taxonomy_meta', $tax_meta);
         if ($echo) {
             $link = get_term_link($term);
             if (!is_wp_error($link)) {
                 echo 'Updated <a href="' . esc_url($link) . '">' . esc_html($vid['title']) . '</a> - ' . esc_html($vid['type']) . '<br/>';
             }
         }
     }
     return $vid;
 }
예제 #9
0
 /**
  * Update the taxonomy meta data on save.
  *
  * @param int    $term_id  ID of the term to save data for.
  * @param int    $tt_id    The taxonomy_term_id for the term.
  * @param string $taxonomy The taxonomy the term belongs to.
  */
 public function update_term($term_id, $tt_id, $taxonomy)
 {
     /* Create post array with only our values */
     $new_meta_data = array();
     foreach (WPSEO_Taxonomy_Meta::$defaults_per_term as $key => $default) {
         if ($posted_value = filter_input(INPUT_POST, $key)) {
             $new_meta_data[$key] = $posted_value;
         }
     }
     unset($key, $default);
     // Saving the values.
     WPSEO_Taxonomy_Meta::set_values($term_id, $taxonomy, $new_meta_data);
 }
예제 #10
0
 /**
  * @return bool
  */
 private function taxonomy_image_output()
 {
     foreach (array('twitter-image', 'opengraph-image') as $tag) {
         $img = WPSEO_Taxonomy_Meta::get_meta_without_term($tag);
         if ($img !== '') {
             $this->image_output($img);
             return true;
         }
     }
     return false;
 }
예제 #11
0
/**
 * Retrieves the keyword for the keyword doubles of the termpages.
 */
function ajax_get_term_keyword_usage()
{
    $post_id = filter_input(INPUT_POST, 'post_id');
    $keyword = filter_input(INPUT_POST, 'keyword');
    $taxonomy = filter_input(INPUT_POST, 'taxonomy');
    if (!current_user_can('edit_terms')) {
        die('-1');
    }
    $usage = WPSEO_Taxonomy_Meta::get_keyword_usage($keyword, $post_id, $taxonomy);
    // Normalize the result so it it the same as the post keyword usage AJAX request.
    $usage = $usage[$keyword];
    wp_die(WPSEO_Utils::json_encode($usage));
}
예제 #12
0
/**
 * Get the custom marker from categories or general Local SEO settings.
 *
 * @param $post_id Int the post id
 * @param $taxonomy String The taxonomy name from the location category
 */
function wpseo_local_get_custom_marker($post_id = null, $taxonomy = '')
{
    $custom_marker = '';
    if (!empty($post_id) && !empty($taxonomy)) {
        $terms = wp_get_object_terms($post_id, $taxonomy, array('fields' => 'ids'));
        $terms = apply_filters('wpseo_local_custom_marker_order', $terms);
        if (!empty($terms)) {
            foreach ($terms as $term_id) {
                $tax_meta = WPSEO_Taxonomy_Meta::get_term_meta((int) $term_id, $taxonomy);
                if (isset($tax_meta['wpseo_local_custom_marker']) && !empty($tax_meta['wpseo_local_custom_marker'])) {
                    $custom_marker = wp_get_attachment_url($tax_meta['wpseo_local_custom_marker']);
                }
                break;
            }
        }
    } else {
        $options = get_option('wpseo_local');
        if (isset($options['custom_marker']) && intval($options['custom_marker'])) {
            $custom_marker = wp_get_attachment_url($options['custom_marker']);
        }
    }
    return $custom_marker;
}
예제 #13
0
 /**
  * Returns the meta value for the given $meta_key.
  *
  * @param string $meta_key The target key that will be fetched.
  *
  * @return string
  */
 private function get_meta_value($meta_key)
 {
     if (is_singular()) {
         return WPSEO_Meta::get_value($meta_key);
     }
     if (is_category() || is_tag() || is_tax()) {
         return WPSEO_Taxonomy_Meta::get_meta_without_term($meta_key);
     }
     return '';
 }
예제 #14
0
/**
 * Retrieves the keyword for the keyword doubles of the termpages.
 */
function ajax_get_term_keyword_usage()
{
    $post_id = filter_input(INPUT_POST, 'post_id');
    $keyword = filter_input(INPUT_POST, 'keyword');
    $taxonomy = filter_input(INPUT_POST, 'taxonomy');
    wp_die(WPSEO_Utils::json_encode(WPSEO_Taxonomy_Meta::get_keyword_usage($keyword, $post_id, $taxonomy)));
}
 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;
     }
 }
예제 #16
0
 /**
  * Pass variables to js for use with the term-scraper
  *
  * @return array
  */
 public function localize_term_scraper_script()
 {
     $translations = $this->get_scraper_translations();
     $term_id = filter_input(INPUT_GET, 'tag_ID');
     $term = get_term_by('id', $term_id, $this->get_taxonomy());
     $focuskw = WPSEO_Taxonomy_Meta::get_term_meta($term, $term->taxonomy, 'focuskw');
     $taxonomy = get_taxonomy($term->taxonomy);
     $options = WPSEO_Options::get_all();
     $base_url = home_url('/', null);
     if (!$options['stripcategorybase']) {
         $base_url = trailingslashit($base_url . $taxonomy->rewrite['slug']);
     }
     return array('translations' => $translations, 'base_url' => $base_url, 'taxonomy' => $term->taxonomy, 'keyword_usage' => WPSEO_Taxonomy_Meta::get_keyword_usage($focuskw, $term->term_id, $term->taxonomy), 'search_url' => admin_url('edit-tags.php?taxonomy=' . $term->taxonomy . '&seo_kw_filter={keyword}'), 'post_edit_url' => admin_url('edit-tags.php?action=edit&taxonomy=' . $term->taxonomy . '&tag_ID={id}'), 'title_template' => WPSEO_Taxonomy::get_title_template($term), 'metadesc_template' => WPSEO_Taxonomy::get_metadesc_template($term), 'contentTab' => __('Content:', 'wordpress-seo'));
 }
예제 #17
0
 /**
  * Update the taxonomy meta data on save.
  *
  * @param int    $term_id  ID of the term to save data for.
  * @param int    $tt_id    The taxonomy_term_id for the term.
  * @param string $taxonomy The taxonomy the term belongs to.
  */
 public function update_term($term_id, $tt_id, $taxonomy)
 {
     /* Create post array with only our values */
     $new_meta_data = array();
     foreach (WPSEO_Taxonomy_Meta::$defaults_per_term as $key => $default) {
         if ($posted_value = filter_input(INPUT_POST, $key)) {
             $new_meta_data[$key] = $posted_value;
         }
         // If analysis is disabled remove that analysis score value from the DB.
         if ($this->is_meta_value_disabled($key)) {
             $new_meta_data[$key] = '';
         }
     }
     unset($key, $default);
     // Saving the values.
     WPSEO_Taxonomy_Meta::set_values($term_id, $taxonomy, $new_meta_data);
 }
 public function enrich_defaults()
 {
     $extra_defaults_per_term = apply_filters('wpseo_add_extra_taxmeta_term_defaults', array());
     if (is_array($extra_defaults_per_term)) {
         self::$defaults_per_term = array_merge($extra_defaults_per_term, self::$defaults_per_term);
     }
 }
 /**
  * Returns the focus keyword if this is set, otherwise it will give the term name.
  *
  * @param stdClass|WP_Term $term The current term.
  *
  * @return string
  */
 private function get_focus_keyword($term)
 {
     if ($focus_keyword = WPSEO_Taxonomy_Meta::get_term_meta('focuskw', $term->term_id, $term->taxonomy)) {
         return $focus_keyword;
     }
     return $term->name;
 }
예제 #20
0
 /**
  * Update the taxonomy meta data on save.
  *
  * @param int    $term_id  ID of the term to save data for
  * @param int    $tt_id    The taxonomy_term_id for the term.
  * @param string $taxonomy The taxonomy the term belongs to.
  */
 function update_term($term_id, $tt_id, $taxonomy)
 {
     $tax_meta = get_option('wpseo_taxonomy_meta');
     /* Create post array with only our values */
     $new_meta_data = array();
     foreach (WPSEO_Taxonomy_Meta::$defaults_per_term as $key => $default) {
         if (isset($_POST[$key])) {
             $new_meta_data[$key] = $_POST[$key];
         }
     }
     /* Validate the post values */
     $old = WPSEO_Taxonomy_Meta::get_term_meta($term_id, $taxonomy);
     $clean = WPSEO_Taxonomy_Meta::validate_term_meta_data($new_meta_data, $old);
     /* Add/remove the result to/from the original option value */
     if ($clean !== array()) {
         $tax_meta[$taxonomy][$term_id] = $clean;
     } else {
         unset($tax_meta[$taxonomy][$term_id]);
         if (isset($tax_meta[$taxonomy]) && $tax_meta[$taxonomy] === array()) {
             unset($tax_meta[$taxonomy]);
         }
     }
     // Prevent complete array validation
     $tax_meta['wpseo_already_validated'] = true;
     update_option('wpseo_taxonomy_meta', $tax_meta);
 }
 /**
  * @param stdClass $term The current term.
  */
 public function __construct($term)
 {
     $this->tax_meta = WPSEO_Taxonomy_Meta::get_term_meta((int) $term->term_id, $term->taxonomy);
 }
예제 #22
0
 /**
  * Build a sub-sitemap for a specific taxonomy -- example.com/tax-sitemap.xml
  *
  * @param string $taxonomy Registered taxonomy's slug
  */
 function build_tax_map($taxonomy)
 {
     if (isset($this->options['taxonomies-' . $taxonomy->name . '-not_in_sitemap']) && $this->options['taxonomies-' . $taxonomy->name . '-not_in_sitemap'] === true || in_array($taxonomy, array('link_category', 'nav_menu', 'post_format')) || apply_filters('wpseo_sitemap_exclude_taxonomy', false, $taxonomy->name)) {
         $this->bad_sitemap = true;
         return;
     }
     global $wpdb;
     $output = '';
     $steps = $this->max_entries;
     $n = (int) $this->n;
     $offset = $n > 1 ? ($n - 1) * $this->max_entries : 0;
     /**
      * Filter: 'wpseo_sitemap_exclude_empty_terms' - Allow people to include empty terms in sitemap
      *
      * @api bool $hide_empty Whether or not to hide empty terms, defaults to true.
      *
      * @param object $taxonomy The taxonomy we're getting terms for.
      */
     $hide_empty = apply_filters('wpseo_sitemap_exclude_empty_terms', true, $taxonomy);
     $terms = get_terms($taxonomy->name, array('hide_empty' => $hide_empty));
     $terms = array_splice($terms, $offset, $steps);
     if (is_array($terms) && $terms !== array()) {
         foreach ($terms as $c) {
             $url = array();
             $tax_noindex = WPSEO_Taxonomy_Meta::get_term_meta($c, $c->taxonomy, 'noindex');
             $tax_sitemap_inc = WPSEO_Taxonomy_Meta::get_term_meta($c, $c->taxonomy, 'sitemap_include');
             if (is_string($tax_noindex) && $tax_noindex === 'noindex' && (!is_string($tax_sitemap_inc) || $tax_sitemap_inc !== 'always')) {
                 continue;
             }
             if ($tax_sitemap_inc === 'never') {
                 continue;
             }
             $url['loc'] = WPSEO_Taxonomy_Meta::get_term_meta($c, $c->taxonomy, 'canonical');
             if (!is_string($url['loc']) || $url['loc'] === '') {
                 $url['loc'] = get_term_link($c, $c->taxonomy);
                 if ($this->options['trailingslash'] === true) {
                     $url['loc'] = trailingslashit($url['loc']);
                 }
             }
             if ($c->count > 10) {
                 $url['pri'] = 0.6;
             } else {
                 if ($c->count > 3) {
                     $url['pri'] = 0.4;
                 } else {
                     $url['pri'] = 0.2;
                 }
             }
             // Grab last modified date
             $sql = $wpdb->prepare("\n\t\t\t\t\t\tSELECT MAX(p.post_modified_gmt) AS lastmod\n\t\t\t\t\t\tFROM\t{$wpdb->posts} AS p\n\t\t\t\t\t\tINNER JOIN {$wpdb->term_relationships} AS term_rel\n\t\t\t\t\t\t\tON\t\tterm_rel.object_id = p.ID\n\t\t\t\t\t\tINNER JOIN {$wpdb->term_taxonomy} AS term_tax\n\t\t\t\t\t\t\tON\t\tterm_tax.term_taxonomy_id = term_rel.term_taxonomy_id\n\t\t\t\t\t\t\tAND\t\tterm_tax.taxonomy = %s\n\t\t\t\t\t\t\tAND\t\tterm_tax.term_id = %d\n\t\t\t\t\t\tWHERE\tp.post_status IN ('publish','inherit')\n\t\t\t\t\t\t\tAND\t\tp.post_password = ''", $c->taxonomy, $c->term_id);
             $url['mod'] = $wpdb->get_var($sql);
             $url['chf'] = $this->filter_frequency($c->taxonomy . '_term', 'weekly', $url['loc']);
             // Use this filter to adjust the entry before it gets added to the sitemap
             $url = apply_filters('wpseo_sitemap_entry', $url, 'term', $c);
             if (is_array($url) && $url !== array()) {
                 $output .= $this->sitemap_url($url);
             }
         }
     }
     $this->sitemap = '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ';
     $this->sitemap .= 'xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" ';
     $this->sitemap .= 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
     // Only add $ouput != empty
     if (!empty($output)) {
         $this->sitemap .= $output;
     }
     $this->sitemap .= '</urlset>';
 }
 /**
  * Counting the number of given keyword used for other term than given term_id
  *
  * @return array
  */
 private function get_focus_keyword_usage()
 {
     $focuskw = WPSEO_Taxonomy_Meta::get_term_meta($this->term, $this->term->taxonomy, 'focuskw');
     return WPSEO_Taxonomy_Meta::get_keyword_usage($focuskw, $this->term->term_id, $this->term->taxonomy);
 }
예제 #24
0
 /**
  * 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('[&hellip;]', '&hellip;', 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;
 }
예제 #25
0
/**
 * Retrieves the keyword for the keyword doubles of the termpages.
 */
function ajax_get_term_keyword_usage()
{
    $post_id = filter_input(INPUT_POST, 'post_id');
    $keyword = filter_input(INPUT_POST, 'keyword');
    $taxonomyName = filter_input(INPUT_POST, 'taxonomy');
    $taxonomy = get_taxonomy($taxonomyName);
    if (!$taxonomy) {
        wp_die(0);
    }
    if (!current_user_can($taxonomy->cap->edit_terms)) {
        wp_die(-1);
    }
    $usage = WPSEO_Taxonomy_Meta::get_keyword_usage($keyword, $post_id, $taxonomyName);
    // Normalize the result so it it the same as the post keyword usage AJAX request.
    $usage = $usage[$keyword];
    wp_die(wp_json_encode($usage));
}
 /**
  * Retrieve link url and text based on term object
  *
  * @param	object	$term	Term object
  *
  * @return	array	$link	Array of link text and url
  */
 private function get_link_info_for_term($term)
 {
     $link = array();
     $bctitle = WPSEO_Taxonomy_Meta::get_term_meta($term, $term->taxonomy, 'bctitle');
     if (!is_string($bctitle) || $bctitle === '') {
         $bctitle = $term->name;
     }
     $link['url'] = get_term_link($term);
     $link['text'] = $bctitle;
     return $link;
 }
예제 #27
0
 /**
  * Check if taxonomy has an image and add this image
  */
 private function get_opengraph_image_taxonomy()
 {
     if (($ogimg = WPSEO_Taxonomy_Meta::get_meta_without_term('opengraph-image')) !== '') {
         $this->add_image($ogimg);
     }
 }
예제 #28
0
 /**
  * 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;
     }
 }
예제 #29
0
 /**
  * Get the meta description for given post
  *
  * @param stdClass|WP_Term $term The term object.
  *
  * @return bool|string
  */
 private function get_meta_description($term)
 {
     $meta_description = WPSEO_Taxonomy_Meta::get_term_meta($term->term_id, $term->taxonomy, 'desc');
     if ('' !== $meta_description) {
         return $meta_description;
     }
     $default_from_options = $this->default_from_options('metadesc-tax', $term->taxonomy);
     if (false !== $default_from_options) {
         return $default_from_options;
     }
     return '';
 }