コード例 #1
1
 /**
  * Hooked into transition_post_status. Will initiate search engine pings
  * if the post is being published, is a post type that a sitemap is built for
  * and is a post that is included in sitemaps.
  *
  * @param string   $new_status New post status.
  * @param string   $old_status Old post status.
  * @param \WP_Post $post       Post object.
  */
 function status_transition($new_status, $old_status, $post)
 {
     if ($new_status != 'publish') {
         return;
     }
     wp_cache_delete('lastpostmodified:gmt:' . $post->post_type, 'timeinfo');
     // #17455.
     $options = WPSEO_Options::get_options(array('wpseo_xml', 'wpseo_titles'));
     if (isset($options['post_types-' . $post->post_type . '-not_in_sitemap']) && $options['post_types-' . $post->post_type . '-not_in_sitemap'] === true || $post->post_type === 'nav_menu_item') {
         return;
     }
     if (WP_CACHE) {
         wp_schedule_single_event(time() + 300, 'wpseo_hit_sitemap_index');
     }
     /**
      * 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;
     }
     // Allow the pinging to happen slightly after the hit sitemap index so the sitemap is fully regenerated when the ping happens.
     $excluded_posts = explode(',', $options['excluded-posts']);
     if (!in_array($post->ID, $excluded_posts)) {
         if (defined('YOAST_SEO_PING_IMMEDIATELY') && YOAST_SEO_PING_IMMEDIATELY) {
             wpseo_ping_search_engines();
         } else {
             wp_schedule_single_event(time() + 300, 'wpseo_ping_search_engines');
         }
     }
 }
コード例 #2
0
 /**
  * Hooked into transition_post_status. Will initiate search engine pings
  * if the post is being published, is a post type that a sitemap is built for
  * and is a post that is included in sitemaps.
  */
 function status_transition($new_status, $old_status, $post)
 {
     if ($new_status != 'publish') {
         return;
     }
     wp_cache_delete('lastpostmodified:gmt:' . $post->post_type, 'timeinfo');
     // #17455
     $options = WPSEO_Options::get_all();
     if (isset($options['post_types-' . $post->post_type . '-not_in_sitemap']) && $options['post_types-' . $post->post_type . '-not_in_sitemap'] === true) {
         return;
     }
     if (WP_CACHE) {
         wp_schedule_single_event(time() + 300, 'wpseo_hit_sitemap_index');
     }
     // Allow the pinging to happen slightly after the hit sitemap index so the sitemap is fully regenerated when the ping happens.
     if (WPSEO_Meta::get_value('sitemap-include', $post->ID) !== 'never') {
         if (defined('YOAST_SEO_PING_IMMEDIATELY') && YOAST_SEO_PING_IMMEDIATELY) {
             wpseo_ping_search_engines();
         } else {
             wp_schedule_single_event(time() + 300, 'wpseo_ping_search_engines');
         }
     }
 }
コード例 #3
0
 /**
  * Reindex the video info from posts
  *
  * @since 0.1
  *
  * @param $portion
  * @param $start
  */
 private function reindex($portion, $start)
 {
     require_once ABSPATH . 'wp-admin/includes/media.php';
     $options = get_option('wpseo_video');
     if (is_array($options['videositemap_posttypes']) && $options['videositemap_posttypes'] !== array()) {
         $args = array('post_type' => $options['videositemap_posttypes'], 'post_status' => 'publish', 'numberposts' => $portion, 'offset' => $start);
         if (!isset($_POST['force'])) {
             if (version_compare($GLOBALS['wp_version'], '3.5', '>=')) {
                 $args['meta_query'] = array('key' => '_yoast_wpseo_video_meta', 'compare' => 'NOT EXISTS');
             }
         }
         $post_count_total = 0;
         foreach ($options['videositemap_posttypes'] as $post_type) {
             $post_count_total += wp_count_posts($post_type)->publish;
         }
         $results = get_posts($args);
         $result_count = count($results);
         if (is_array($results) && $result_count > 0) {
             foreach ($results as $post) {
                 $this->update_video_post_meta($post, false);
                 flush();
             }
         }
     }
     // Get all the non-empty terms.
     add_filter('terms_clauses', array($this, 'filter_terms_clauses'));
     $terms = array();
     if (is_array($options['videositemap_taxonomies']) && $options['videositemap_taxonomies'] !== array()) {
         foreach ($options['videositemap_taxonomies'] as $val) {
             $new_terms = get_terms($val);
             if (is_array($new_terms)) {
                 $terms = array_merge($terms, $new_terms);
             }
         }
     }
     remove_filter('terms_clauses', array($this, 'filter_terms_clauses'));
     if (count($terms) > 0) {
         foreach ($terms as $term) {
             $this->update_video_term_meta($term, false);
             flush();
         }
     }
     // Ping the search engines with our updated XML sitemap, we ping with the index sitemap because
     // we don't know which video sitemap, or sitemaps, have been updated / added.
     wpseo_ping_search_engines();
     // Remove the admin notice
     delete_transient('video_seo_recommend_reindex');
 }