| 1 |
<?php |
| 2 |
################################################################################ |
| 3 |
## fwp_hold_pings() and fwp_release_pings(): Outbound XML-RPC ping reform #### |
| 4 |
## ... 'coz it's rude to send 500 pings the first time your aggregator runs #### |
| 5 |
################################################################################ |
| 6 |
|
| 7 |
global $fwp_held_ping; |
| 8 |
|
| 9 |
$fwp_held_ping = NULL; // NULL: not holding pings yet |
| 10 |
|
| 11 |
function fwp_hold_pings () { |
| 12 |
global $fwp_held_ping; |
| 13 |
if (is_null($fwp_held_ping)): |
| 14 |
$fwp_held_ping = 0; // 0: ready to hold pings; none yet received |
| 15 |
FeedWordPress::diagnostic( |
| 16 |
'syndicated_posts:do_pings', |
| 17 |
'FeedWordPress is set up to hold pings, fwp_held_ping='.json_encode($fwp_held_ping) |
| 18 |
); |
| 19 |
endif; |
| 20 |
} |
| 21 |
|
| 22 |
function fwp_release_pings () { |
| 23 |
global $fwp_held_ping; |
| 24 |
|
| 25 |
$diag_message = null; |
| 26 |
if ($fwp_held_ping): |
| 27 |
if (function_exists('wp_schedule_single_event')) : |
| 28 |
wp_schedule_single_event(time(), 'do_pings'); |
| 29 |
$diag_message = 'scheduled release of pings'; |
| 30 |
else : |
| 31 |
generic_ping($fwp_held_ping); |
| 32 |
$diag_message = 'released pings'; |
| 33 |
endif; |
| 34 |
endif; |
| 35 |
|
| 36 |
$fwp_held_ping = NULL; // NULL: not holding pings anymore |
| 37 |
|
| 38 |
if (!is_null($diag_message)) : |
| 39 |
FeedWordPress::diagnostic( |
| 40 |
'syndicated_posts:do_pings', |
| 41 |
"FeedWordPress ${diag_message}, fwp_held_ping=".json_encode($fwp_held_ping) |
| 42 |
); |
| 43 |
endif; |
| 44 |
} |
| 45 |
|
| 46 |
function fwp_do_pings () { |
| 47 |
global $fwp_held_ping; |
| 48 |
|
| 49 |
if (!is_null($fwp_held_ping) and $post_id) : // Defer until we're done updating |
| 50 |
$fwp_held_ping = $post_id; |
| 51 |
|
| 52 |
FeedWordPress::diagnostic( |
| 53 |
'syndicated_posts:do_pings', |
| 54 |
"FeedWordPress intercepted a ping event, fwp_held_ping=".json_encode($fwp_held_ping) |
| 55 |
); |
| 56 |
|
| 57 |
elseif (function_exists('do_all_pings')) : |
| 58 |
do_all_pings(); |
| 59 |
else : |
| 60 |
generic_ping($fwp_held_ping); |
| 61 |
endif; |
| 62 |
} |
| 63 |
|
| 64 |
function fwp_publish_post_hook ($post_id) { |
| 65 |
global $fwp_held_ping; |
| 66 |
|
| 67 |
if (!is_null($fwp_held_ping)) : // Syndicated post. Don't mark with _pingme |
| 68 |
if ( defined('XMLRPC_REQUEST') ) |
| 69 |
do_action('xmlrpc_publish_post', $post_id); |
| 70 |
if ( defined('APP_REQUEST') ) |
| 71 |
do_action('app_publish_post', $post_id); |
| 72 |
|
| 73 |
if ( defined('WP_IMPORTING') ) |
| 74 |
return; |
| 75 |
|
| 76 |
// Defer sending out pings until we finish updating |
| 77 |
$fwp_held_ping = $post_id; |
| 78 |
|
| 79 |
FeedWordPress::diagnostic( |
| 80 |
'syndicated_posts:do_pings', |
| 81 |
"FeedWordPress intercepted a post event, fwp_held_ping=".json_encode($fwp_held_ping) |
| 82 |
); |
| 83 |
else : |
| 84 |
if (function_exists('_publish_post_hook')) : // WordPress 2.3 |
| 85 |
_publish_post_hook($post_id); |
| 86 |
endif; |
| 87 |
endif; |
| 88 |
} |
| 89 |
|