/** * @param int $max_entries Entries per sitemap. * * @return array */ public function get_index_links($max_entries) { global $wpdb; $post_types = get_post_types(array('public' => true)); $post_types = array_filter($post_types, array($this, 'is_valid_post_type')); $index = array(); foreach ($post_types as $post_type) { $count = $this->get_post_type_count($post_type); if ($count === 0) { continue; } $max_pages = $count > $max_entries ? (int) ceil($count / $max_entries) : 1; for ($i = 0; $i < $max_pages; $i++) { $count = $max_pages > 1 ? $i + 1 : ''; if (empty($count) || $count === $max_pages) { $date = WPSEO_Sitemaps::get_last_modified_gmt($post_type); } else { $sql = "\n\t\t\t\t\t\tSELECT post_modified_gmt\n\t\t\t\t\t\tFROM (\n\t\t\t\t\t\t\tSELECT @rownum:=@rownum+1 rownum, {$wpdb->posts}.post_modified_gmt\n\t\t\t\t\t\t\tFROM (SELECT @rownum:=0) r, {$wpdb->posts}\n\t\t\t\t\t\t\tWHERE post_status IN ('publish','inherit')\n\t\t\t\t\t\t\t\tAND post_type = %s\n\t\t\t\t\t\t\tORDER BY post_modified_gmt ASC\n\t\t\t\t\t\t) x\n\t\t\t\t\t\tWHERE rownum %%%d=0\n\t\t\t\t\t"; $all_dates = $wpdb->get_col($wpdb->prepare($sql, $post_type, $max_entries)); $date = $all_dates[$i]; } $index[] = array('loc' => WPSEO_Sitemaps_Router::get_base_url($post_type . '-sitemap' . $count . '.xml'), 'lastmod' => $date); } } return $index; }
/** * @param int $max_entries Entries per sitemap. * * @return array */ public function get_index_links($max_entries) { global $wpdb; $options = WPSEO_Options::get_all(); if ($options['disable-author'] || $options['disable_author_sitemap']) { return array(); } $users = get_users(array('who' => 'authors')); /** * Filter the authors, included in XML sitemap. * * @param array $users Array of user objects to filter. */ $users = apply_filters('wpseo_sitemap_exclude_author', $users); $users = wp_list_pluck($users, 'ID'); $count = count($users); $max_pages = $count > 0 ? 1 : 0; if ($count > $max_entries) { $max_pages = (int) ceil($count / $max_entries); } // Must use custom raw query because WP User Query does not support ordering by usermeta. // Retrieve the newest updated profile timestamp overall. // TODO order by usermeta supported since WP 3.7, update implementation? R. $date_query = "\n\t\t\tSELECT mt1.meta_value\n\t\t\tFROM {$wpdb->users}\n\t\t\t\tINNER JOIN {$wpdb->usermeta} ON ({$wpdb->users}.ID = {$wpdb->usermeta}.user_id)\n\t\t\t\tINNER JOIN {$wpdb->usermeta} AS mt1 ON ({$wpdb->users}.ID = mt1.user_id)\n\t\t\tWHERE 1=1\n\t\t\t\tAND (\n\t\t\t\t\t({$wpdb->usermeta}.meta_key = %s AND CAST({$wpdb->usermeta}.meta_value AS CHAR) != '0')\n\t\t\t\t\tAND mt1.meta_key = '_yoast_wpseo_profile_updated'\n\t\t\t\t)\n\t\t\tORDER BY mt1.meta_value\n\t\t"; $index = array(); for ($i = 0; $i < $max_pages; $i++) { $count = $max_pages > 1 ? $i + 1 : ''; if (empty($count) || $count === $max_pages) { $sql = $wpdb->prepare($date_query . ' DESC LIMIT 1', $wpdb->get_blog_prefix() . 'user_level'); // Retrieve the newest updated profile timestamp by an offset. } else { $sql = $wpdb->prepare($date_query . ' DESC LIMIT 1 OFFSET %d', $wpdb->get_blog_prefix() . 'user_level', $max_entries * ($i + 1) - 1); } $date = $wpdb->get_var($sql); $index[] = array('loc' => WPSEO_Sitemaps_Router::get_base_url('author-sitemap' . $count . '.xml'), 'lastmod' => '@' . $date); } return $index; }
/** * @param int $max_entries Entries per sitemap. * * @return array */ public function get_index_links($max_entries) { $options = WPSEO_Options::get_all(); if ($options['disable-author'] || $options['disable_author_sitemap']) { return array(); } // TODO Consider doing this less often / when necessary. R. $this->update_user_meta(); $has_exclude_filter = has_filter('wpseo_sitemap_exclude_author'); $query_arguments = array(); if (!$has_exclude_filter) { // We only need full users if legacy filter(s) hooked to exclusion logic. R. $query_arguments['fields'] = 'ID'; } $users = $this->get_users($query_arguments); if ($has_exclude_filter) { $users = $this->exclude_users($users); $users = wp_list_pluck($users, 'ID'); } if (empty($users)) { return array(); } $index = array(); $page = 1; $user_pages = array_chunk($users, $max_entries); if (count($user_pages) === 1) { $page = ''; } foreach ($user_pages as $users_page) { $user_id = array_shift($users_page); // Time descending, first user on page is most recently updated. $user = get_user_by('id', $user_id); $index[] = array('loc' => WPSEO_Sitemaps_Router::get_base_url('author-sitemap' . $page . '.xml'), 'lastmod' => '@' . $user->_yoast_wpseo_profile_updated); $page++; } return $index; }
/** * @param int $max_entries Entries per sitemap. * * @return array */ public function get_index_links($max_entries) { global $wpdb; $taxonomies = get_taxonomies(array('public' => true), 'objects'); if (empty($taxonomies)) { return array(); } $taxonomy_names = array_filter(array_keys($taxonomies), array($this, 'is_valid_taxonomy')); $taxonomies = array_intersect_key($taxonomies, array_flip($taxonomy_names)); // Retrieve all the taxonomies and their terms so we can do a proper count on them. /** * Filter the setting of excluding empty terms from the XML sitemap. * * @param boolean $exclude Defaults to true. * @param array $taxonomy_names Array of names for the taxonomies being processed. */ $hide_empty = apply_filters('wpseo_sitemap_exclude_empty_terms', true, $taxonomy_names) ? 'count != 0 AND' : ''; $sql = "\n\t\t\tSELECT taxonomy, term_id\n\t\t\tFROM {$wpdb->term_taxonomy}\n\t\t\tWHERE {$hide_empty} taxonomy IN ('" . implode("','", $taxonomy_names) . "');\n\t\t"; $all_taxonomy_terms = $wpdb->get_results($sql); $all_taxonomies = array(); foreach ($all_taxonomy_terms as $obj) { $all_taxonomies[$obj->taxonomy][] = $obj->term_id; } unset($hide_empty, $sql, $all_taxonomy_terms, $obj); $index = array(); foreach ($taxonomies as $tax_name => $tax) { if (!isset($all_taxonomies[$tax_name])) { // No eligible terms found. continue; } $steps = $max_entries; $count = isset($all_taxonomies[$tax_name]) ? count($all_taxonomies[$tax_name]) : 1; $n = $count > $max_entries ? (int) ceil($count / $max_entries) : 1; for ($i = 0; $i < $n; $i++) { $count = $n > 1 ? $i + 1 : ''; if (!is_array($tax->object_type) || count($tax->object_type) == 0) { continue; } if (empty($count) || $count == $n) { $date = WPSEO_Sitemaps::get_last_modified_gmt($tax->object_type); } else { $terms = array_splice($all_taxonomies[$tax_name], 0, $steps); if (!$terms) { continue; } $args = array('post_type' => $tax->object_type, 'tax_query' => array(array('taxonomy' => $tax_name, 'terms' => $terms)), 'orderby' => 'modified', 'order' => 'DESC'); $query = new WP_Query($args); if ($query->have_posts()) { $date = $query->posts[0]->post_modified_gmt; } else { $date = WPSEO_Sitemaps::get_last_modified_gmt($tax->object_type); } unset($terms, $args, $query); } $index[] = array('loc' => WPSEO_Sitemaps_Router::get_base_url($tax_name . '-sitemap' . $count . '.xml'), 'lastmod' => $date); } } return $index; }
<?php /** * @package WPSEO\Admin\Views */ if (!defined('WPSEO_VERSION')) { header('Status: 403 Forbidden'); header('HTTP/1.1 403 Forbidden'); exit; } echo '<h2>' . esc_html__('Your XML Sitemap', 'wordpress-seo') . '</h2>'; if ($options['enablexmlsitemap'] === true) { echo '<p>'; printf(esc_html__('You can find your XML Sitemap here: %sXML Sitemap%s', 'wordpress-seo'), '<a target="_blank" class="button" href="' . esc_url(WPSEO_Sitemaps_Router::get_base_url('sitemap_index.xml')) . '">', '</a>'); echo '<br/>'; echo '<br/>'; _e('You do <strong>not</strong> need to generate the XML sitemap, nor will it take up time to generate after publishing a post.', 'wordpress-seo'); echo '</p>'; } else { echo '<p>', __('Save your settings to activate your XML Sitemap.', 'wordpress-seo'), '</p>'; } echo '<h2>' . esc_html__('Entries per sitemap page', 'wordpress-seo') . '</h2>'; ?> <p> <?php printf(__('Please enter the maximum number of entries per sitemap page (defaults to %s, you might want to lower this to prevent memory issues on some installs):', 'wordpress-seo'), WPSEO_Options::get_default('wpseo_xml', 'entries-per-page')); ?> </p> <?php $yform->textinput('entries-per-page', __('Max entries per sitemap', 'wordpress-seo'));
/** * Notify search engines of the updated sitemap. * * @param string|null $url Optional URL to make the ping for. */ public static function ping_search_engines($url = null) { /** * Filter: 'wpseo_allow_xml_sitemap_ping' - Check if pinging is not allowed (allowed by default) * * @api boolean $allow_ping The boolean that is set to true by default. */ if (apply_filters('wpseo_allow_xml_sitemap_ping', true) === false) { return; } if ('0' === get_option('blog_public')) { // Don't ping if blog is not public. return; } if (empty($url)) { $url = urlencode(WPSEO_Sitemaps_Router::get_base_url('sitemap_index.xml')); } // Ping Google and Bing. wp_remote_get('http://www.google.com/webmasters/tools/ping?sitemap=' . $url, array('blocking' => false)); wp_remote_get('http://www.bing.com/ping?sitemap=' . $url, array('blocking' => false)); }
/** * Adds 'prev' and 'next' links to archives. * * @link http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html * @since 1.0.3 */ public function adjacent_rel_links() { // Don't do this for Genesis, as the way Genesis handles homepage functionality is different and causes issues sometimes. /** * Filter 'wpseo_genesis_force_adjacent_rel_home' - Allows devs to allow echoing rel="next" / rel="prev" by Yoast SEO on Genesis installs * * @api bool $unsigned Whether or not to rel=next / rel=prev */ if (is_home() && function_exists('genesis') && apply_filters('wpseo_genesis_force_adjacent_rel_home', false) === false) { return; } global $wp_query; if (!is_singular()) { $url = $this->canonical(false, true, true); if (is_string($url) && $url !== '') { $paged = get_query_var('paged'); if (0 == $paged) { $paged = 1; } if ($paged == 2) { $this->adjacent_rel_link('prev', $url, $paged - 1, true); } // Make sure to use index.php when needed, done after paged == 2 check so the prev links to homepage will not have index.php erroneously. if (is_front_page()) { $url = WPSEO_Sitemaps_Router::get_base_url(''); } if ($paged > 2) { $this->adjacent_rel_link('prev', $url, $paged - 1, true); } if ($paged < $wp_query->max_num_pages) { $this->adjacent_rel_link('next', $url, $paged + 1, true); } } } else { $numpages = 0; if (isset($wp_query->post->post_content)) { $numpages = substr_count($wp_query->post->post_content, '<!--nextpage-->') + 1; } if ($numpages > 1) { $page = get_query_var('page'); if (!$page) { $page = 1; } $url = get_permalink($wp_query->post->ID); // If the current page is the frontpage, pagination should use /base/. if ($this->is_home_static_page()) { $usebase = true; } else { $usebase = false; } if ($page > 1) { $this->adjacent_rel_link('prev', $url, $page - 1, $usebase, 'single_paged'); } if ($page < $numpages) { $this->adjacent_rel_link('next', $url, $page + 1, $usebase, 'single_paged'); } } } }
/** * @param int $max_entries Entries per sitemap. * * @return array */ public function get_index_links($max_entries) { $taxonomies = get_taxonomies(array('public' => true), 'objects'); if (empty($taxonomies)) { return array(); } $taxonomy_names = array_filter(array_keys($taxonomies), array($this, 'is_valid_taxonomy')); $taxonomies = array_intersect_key($taxonomies, array_flip($taxonomy_names)); // Retrieve all the taxonomies and their terms so we can do a proper count on them. /** * Filter the setting of excluding empty terms from the XML sitemap. * * @param boolean $exclude Defaults to true. * @param array $taxonomy_names Array of names for the taxonomies being processed. */ $hide_empty = apply_filters('wpseo_sitemap_exclude_empty_terms', true, $taxonomy_names); $all_taxonomies = array(); foreach ($taxonomy_names as $taxonomy_name) { $taxonomy_terms = get_terms($taxonomy_name, array('hide_empty' => $hide_empty, 'fields' => 'ids')); if (count($taxonomy_terms) > 0) { $all_taxonomies[$taxonomy_name] = $taxonomy_terms; } } $index = array(); foreach ($taxonomies as $tax_name => $tax) { if (!isset($all_taxonomies[$tax_name])) { // No eligible terms found. continue; } $total_count = isset($all_taxonomies[$tax_name]) ? count($all_taxonomies[$tax_name]) : 1; $max_pages = 1; if ($total_count > $max_entries) { $max_pages = (int) ceil($total_count / $max_entries); } $last_modified_gmt = WPSEO_Sitemaps::get_last_modified_gmt($tax->object_type); for ($page_counter = 0; $page_counter < $max_pages; $page_counter++) { $current_page = $max_pages > 1 ? $page_counter + 1 : ''; if (!is_array($tax->object_type) || count($tax->object_type) == 0) { continue; } $terms = array_splice($all_taxonomies[$tax_name], 0, $max_entries); if (!$terms) { continue; } $args = array('post_type' => $tax->object_type, 'tax_query' => array(array('taxonomy' => $tax_name, 'terms' => $terms)), 'orderby' => 'modified', 'order' => 'DESC', 'posts_per_page' => 1); $query = new WP_Query($args); if ($query->have_posts()) { $date = $query->posts[0]->post_modified_gmt; } else { $date = $last_modified_gmt; } $index[] = array('loc' => WPSEO_Sitemaps_Router::get_base_url($tax_name . '-sitemap' . $current_page . '.xml'), 'lastmod' => $date); } } return $index; }
/** * @param int $max_entries Entries per sitemap. * * @return array */ public function get_index_links($max_entries) { global $wpdb; $post_types = get_post_types(array('public' => true)); $post_types = array_filter($post_types, array($this, 'is_valid_post_type')); $last_modified_times = WPSEO_Sitemaps::get_last_modified_gmt($post_types, true); $index = array(); foreach ($post_types as $post_type) { $total_count = $this->get_post_type_count($post_type); if ($total_count === 0) { continue; } $max_pages = 1; if ($total_count > $max_entries) { $max_pages = (int) ceil($total_count / $max_entries); } $all_dates = array(); if ($max_pages > 1) { $sql = "\n\t\t\t\tSELECT post_modified_gmt\n\t\t\t\t FROM ( SELECT @rownum:=0 ) init \n\t\t\t\t JOIN {$wpdb->posts} USE INDEX( type_status_date )\n\t\t\t\t WHERE post_status IN ( 'publish', 'inherit' )\n\t\t\t\t AND post_type = %s\n\t\t\t\t AND ( @rownum:=@rownum+1 ) %% %d = 0\n\t\t\t\t ORDER BY post_modified_gmt ASC\n\t\t\t\t"; $all_dates = $wpdb->get_col($wpdb->prepare($sql, $post_type, $max_entries)); } for ($page_counter = 0; $page_counter < $max_pages; $page_counter++) { $current_page = $max_pages > 1 ? $page_counter + 1 : ''; $date = false; if (empty($current_page) || $current_page === $max_pages) { if (!empty($last_modified_times[$post_type])) { $date = $last_modified_times[$post_type]; } } else { $date = $all_dates[$page_counter]; } $index[] = array('loc' => WPSEO_Sitemaps_Router::get_base_url($post_type . '-sitemap' . $current_page . '.xml'), 'lastmod' => $date); } } return $index; }
/** * Create base URL for the sitemaps and applies filters * * @since 1.5.7 * * @deprecated * @see WPSEO_Sitemaps_Router::get_base_url() * * @param string $page page to append to the base URL. * * @return string base URL (incl page) for the sitemaps */ function wpseo_xml_sitemaps_base_url($page) { return WPSEO_Sitemaps_Router::get_base_url($page); }