Changeset 937300
- Timestamp:
- 06/23/2014 06:04:11 PM (12 years ago)
- File:
-
- 1 edited
-
google-sitemap-generator/trunk/sitemap-loader.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
google-sitemap-generator/trunk/sitemap-loader.php
r925789 r937300 24 24 * @uses add_action Adds actions for admin menu, executing pings and handling robots.txt 25 25 * @uses add_filter Adds filtes for admin menu icon and contexual help 26 * @uses GoogleSitemapGeneratorLoader::SetupRewriteHooks() Registeres the rewrite hooks27 26 * @uses GoogleSitemapGeneratorLoader::CallShowPingResult() Shows the ping result on request 28 * @uses GoogleSitemapGeneratorLoader::ActivateRewrite() Writes rewrite rules the first time29 27 */ 30 28 public static function Enable() { … … 45 43 add_action('sm_ping_daily', array(__CLASS__, 'CallSendPingDaily'), 10, 1); 46 44 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); 52 47 53 48 //Robots.txt request … … 77 72 * @uses GoogleSitemapGeneratorLoader::RegisterQueryVars 78 73 * @uses GoogleSitemapGeneratorLoader::DoTemplateRedirect 79 * @uses GoogleSitemapGeneratorLoader::KillFrontpageQuery80 74 * @since 4.0 81 75 */ … … 86 80 add_filter('template_redirect', array(__CLASS__, 'DoTemplateRedirect'), 1, 0); 87 81 88 //add_filter('parse_request', array(__CLASS__, 'KillFrontpageQuery'), 1, 0);89 82 } 90 83 … … 205 198 } 206 199 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 page213 // And the currently running query is that main query214 if(!empty($query->query_vars["xml_sitemap"])) {215 // We only want to do this once: remove the filter216 remove_filter('posts_request', array('GoogleSitemapGeneratorLoader', 'KillFrontpagePosts'), 1000, 2);217 // Kill the FOUND_ROWS() query too218 $query->query_vars['no_found_rows'] = true;219 //Workaround for preventing to fetch sticky posts220 $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 230 200 /** 231 201 * Registers the plugin in the admin menu system … … 270 240 271 241 /** 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 } 283 251 } 284 252
Note: See TracChangeset
for help on using the changeset viewer.