Plugin Directory

Changeset 937300


Ignore:
Timestamp:
06/23/2014 06:04:11 PM (12 years ago)
Author:
arnee
Message:
  • Changed hook which is used for search engine pings
File:
1 edited

Legend:

Unmodified
Added
Removed
  • google-sitemap-generator/trunk/sitemap-loader.php

    r925789 r937300  
    2424     * @uses add_action Adds actions for admin menu, executing pings and handling robots.txt
    2525     * @uses add_filter Adds filtes for admin menu icon and contexual help
    26      * @uses GoogleSitemapGeneratorLoader::SetupRewriteHooks() Registeres the rewrite hooks
    2726     * @uses GoogleSitemapGeneratorLoader::CallShowPingResult() Shows the ping result on request
    28      * @uses GoogleSitemapGeneratorLoader::ActivateRewrite() Writes rewrite rules the first time
    2927     */
    3028    public static function Enable() {
     
    4543        add_action('sm_ping_daily', array(__CLASS__, 'CallSendPingDaily'), 10, 1);
    4644
    47         //Existing page was published
    48         add_action('publish_post', array(__CLASS__, 'SchedulePing'), 9999, 1);
    49         add_action('publish_page', array(__CLASS__, 'SchedulePing'), 9999, 1);
    50         add_action('delete_post', array(__CLASS__, 'SchedulePing'), 9999, 1);
    51         add_action('post_updated', array(__CLASS__, 'SchedulePing'), 9999, 1);
     45        //Post is somehow changed (also publish to publish (=edit) is fired)
     46        add_action('transition_post_status', array(__CLASS__, 'SchedulePingOnStatusChange'), 9999, 3);
    5247
    5348        //Robots.txt request
     
    7772     * @uses GoogleSitemapGeneratorLoader::RegisterQueryVars
    7873     * @uses GoogleSitemapGeneratorLoader::DoTemplateRedirect
    79      * @uses GoogleSitemapGeneratorLoader::KillFrontpageQuery
    8074     * @since 4.0
    8175     */
     
    8680        add_filter('template_redirect', array(__CLASS__, 'DoTemplateRedirect'), 1, 0);
    8781
    88         //add_filter('parse_request', array(__CLASS__, 'KillFrontpageQuery'), 1, 0);
    8982    }
    9083
     
    205198    }
    206199
    207     public static function KillFrontpageQuery() {
    208         //add_filter('posts_request', array('GoogleSitemapGeneratorLoader', 'KillFrontpagePosts'), 1000, 2);
    209     }
    210 
    211     public static function KillFrontpagePosts($sql, &$query) {
    212         // The main query is running on the front page
    213         // And the currently running query is that main query
    214         if(!empty($query->query_vars["xml_sitemap"])) {
    215             // We only want to do this once: remove the filter
    216             remove_filter('posts_request', array('GoogleSitemapGeneratorLoader', 'KillFrontpagePosts'), 1000, 2);
    217             // Kill the FOUND_ROWS() query too
    218             $query->query_vars['no_found_rows'] = true;
    219             //Workaround for preventing to fetch sticky posts
    220             $query->is_home = false;
    221             //Prevent sending of 404 (it would happen because we didn't find any posts). Setting is_404 to true skips that check.
    222             $query->is_404 = true;
    223 
    224             return "SELECT ID FROM {$GLOBALS['wpdb']->posts} WHERE 1=2"; // Kill the query doesnt work anymore. Now try to select no matching posts :(
    225         }
    226         return $sql;
    227     }
    228 
    229 
    230200    /**
    231201     * Registers the plugin in the admin menu system
     
    270240
    271241    /**
    272      * Schedules pinging the search engines
    273      *
    274      * @static
    275      *
    276      * @param $postID
    277      *
    278      * @return void
    279      */
    280     public static function SchedulePing($postID) {
    281         set_transient('sm_ping_post_id', $postID, 60);
    282         wp_schedule_single_event(time(), 'sm_ping');
     242     * @param $new_status string The new post status
     243     * @param $old_status string The old post status
     244     * @param $post WP_Post The post object
     245     */
     246    public static function SchedulePingOnStatusChange($new_status, $old_status, $post ) {
     247        if($new_status == 'publish') {
     248            set_transient('sm_ping_post_id', $post->ID, 120);
     249            wp_schedule_single_event(time() + 5, 'sm_ping');
     250        }
    283251    }
    284252
Note: See TracChangeset for help on using the changeset viewer.