| @@ -3,68 +3,49 @@ | ||
| 3 | 3 | ## fwp_hold_pings() and fwp_release_pings(): Outbound XML-RPC ping reform #### |
| 4 | 4 | ## ... 'coz it's rude to send 500 pings the first time your aggregator runs #### |
| 5 | 5 | ################################################################################ |
| 6 | 6 | |
| 7 | -global $fwp_held_ping; // Why declare it as global if it's not used anywhere else? (gwyneth 20230920) | |
| 7 | +global $fwp_held_ping; | |
| 8 | 8 | |
| 9 | -/** @var int|null Hold pings (or not yet, if NULL). */ | |
| 10 | -$fwp_held_ping = NULL; | |
| 9 | +$fwp_held_ping = NULL; // NULL: not holding pings yet | |
| 11 | 10 | |
| 12 | -function fwp_hold_pings() { | |
| 11 | +function fwp_hold_pings () { | |
| 13 | 12 | global $fwp_held_ping; |
| 14 | - if ( is_null ( $fwp_held_ping ) ) : | |
| 13 | + if (is_null($fwp_held_ping)): | |
| 15 | 14 | $fwp_held_ping = 0; // 0: ready to hold pings; none yet received |
| 16 | 15 | FeedWordPress::diagnostic( |
| 17 | 16 | 'syndicated_posts:do_pings', |
| 18 | - 'FeedWordPress is set up to hold pings, fwp_held_ping=' . json_encode( $fwp_held_ping ) | |
| 17 | + 'FeedWordPress is set up to hold pings, fwp_held_ping='.json_encode($fwp_held_ping) | |
| 19 | 18 | ); |
| 20 | 19 | endif; |
| 21 | -} /* function fwp_hold_pings() */ | |
| 20 | +} | |
| 22 | 21 | |
| 23 | -/** | |
| 24 | - * Attempts to schedule an immediate ping via the event scheduler, | |
| 25 | - * falling back to direct ping if scheduler isn't available. | |
| 26 | - * | |
| 27 | - * @uses wp_schedule_single_event() | |
| 28 | - * @uses generic_ping() | |
| 29 | - * @uses FeedWordPress::diagnostic() | |
| 30 | - * | |
| 31 | - * @global $fwp_held_ping | |
| 32 | - */ | |
| 33 | -function fwp_release_pings() { | |
| 22 | +function fwp_release_pings () { | |
| 34 | 23 | global $fwp_held_ping; |
| 35 | 24 | |
| 36 | 25 | $diag_message = null; |
| 37 | - if ( $fwp_held_ping ) : | |
| 38 | - if ( function_exists( 'wp_schedule_single_event') ) : | |
| 39 | - if ( wp_schedule_single_event( time(), 'do_pings' ) ) : | |
| 40 | - $diag_message = 'scheduled release of pings'; | |
| 41 | - else : | |
| 42 | - $diag_message = 'scheduling release of pings failed'; | |
| 43 | - endif; | |
| 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'; | |
| 44 | 30 | else : |
| 45 | - generic_ping( $fwp_held_ping ); | |
| 31 | + generic_ping($fwp_held_ping); | |
| 46 | 32 | $diag_message = 'released pings'; |
| 47 | 33 | endif; |
| 48 | 34 | endif; |
| 49 | - | |
| 35 | + | |
| 50 | 36 | $fwp_held_ping = NULL; // NULL: not holding pings anymore |
| 51 | - | |
| 52 | - if ( ! is_null( $diag_message ) ) : | |
| 37 | + | |
| 38 | + if (!is_null($diag_message)) : | |
| 53 | 39 | FeedWordPress::diagnostic( |
| 54 | 40 | 'syndicated_posts:do_pings', |
| 55 | - "FeedWordPress {$diag_message}, fwp_held_ping=" . json_encode( $fwp_held_ping ) // isn't this _always_ null? (gwyneth 20230919) | |
| 41 | + "FeedWordPress ${diag_message}, fwp_held_ping=".json_encode($fwp_held_ping) | |
| 56 | 42 | ); |
| 57 | 43 | endif; |
| 58 | -} /* function fwp_release_pings() */ | |
| 44 | +} | |
| 59 | 45 | |
| 60 | -/** | |
| 61 | - * Pings, unless held. | |
| 62 | - */ | |
| 63 | -function fwp_do_pings() { | |
| 64 | - global $fwp_held_ping, $post_id; | |
| 65 | - | |
| 66 | - if ( ! is_null( $fwp_held_ping ) and $post_id ) : // Defer until we're done updating | |
| 46 | +function fwp_do_pings () { | |
| 47 | + if (!is_null($fwp_held_ping) and $post_id) : // Defer until we're done updating | |
| 67 | 48 | $fwp_held_ping = $post_id; |
| 68 | 49 | |
| 69 | 50 | FeedWordPress::diagnostic( |
| 70 | 51 | 'syndicated_posts:do_pings', |
| @@ -70,45 +51,36 @@ | ||
| 70 | 51 | 'syndicated_posts:do_pings', |
| 71 | 52 | "FeedWordPress intercepted a ping event, fwp_held_ping=".json_encode($fwp_held_ping) |
| 72 | 53 | ); |
| 73 | 54 | |
| 74 | - elseif ( function_exists( 'do_all_pings' ) ) : | |
| 55 | + elseif (function_exists('do_all_pings')) : | |
| 75 | 56 | do_all_pings(); |
| 76 | 57 | else : |
| 77 | - generic_ping( $fwp_held_ping ); | |
| 58 | + generic_ping($fwp_held_ping); | |
| 78 | 59 | endif; |
| 79 | -} /* function fwp_do_pings() */ | |
| 60 | +} | |
| 80 | 61 | |
| 81 | -/** | |
| 82 | - * Pings post, using one or several of the possible methods, | |
| 83 | - * e.g. XMLRPC_REQUEST, APP_REQUEST. | |
| 84 | - * | |
| 85 | - * @param int $post_id Post being considered for pinging. | |
| 86 | - * | |
| 87 | - */ | |
| 88 | -function fwp_publish_post_hook( $post_id ) { | |
| 62 | +function fwp_publish_post_hook ($post_id) { | |
| 89 | 63 | global $fwp_held_ping; |
| 90 | 64 | |
| 91 | - if ( ! is_null( $fwp_held_ping ) ) : // Syndicated post. Don't mark with _pingme | |
| 92 | - if ( defined( 'XMLRPC_REQUEST' ) ) : | |
| 93 | - do_action( 'xmlrpc_publish_post', $post_id ); | |
| 94 | - endif; | |
| 95 | - if ( defined( 'APP_REQUEST' ) ) : | |
| 96 | - do_action( 'app_publish_post', $post_id ); | |
| 97 | - endif; | |
| 98 | - if ( defined( 'WP_IMPORTING' ) ) : | |
| 65 | + if (!is_null($fwp_held_ping)) : // Syndicated post. Don't mark with _pingme | |
| 66 | + if ( defined('XMLRPC_REQUEST') ) | |
| 67 | + do_action('xmlrpc_publish_post', $post_id); | |
| 68 | + if ( defined('APP_REQUEST') ) | |
| 69 | + do_action('app_publish_post', $post_id); | |
| 70 | + | |
| 71 | + if ( defined('WP_IMPORTING') ) | |
| 99 | 72 | return; |
| 100 | - endif; | |
| 101 | 73 | |
| 102 | 74 | // Defer sending out pings until we finish updating |
| 103 | 75 | $fwp_held_ping = $post_id; |
| 104 | - | |
| 76 | + | |
| 105 | 77 | FeedWordPress::diagnostic( |
| 106 | 78 | 'syndicated_posts:do_pings', |
| 107 | - "FeedWordPress intercepted a post event, fwp_held_ping=" . json_encode( $fwp_held_ping ) | |
| 79 | + "FeedWordPress intercepted a post event, fwp_held_ping=".json_encode($fwp_held_ping) | |
| 108 | 80 | ); |
| 109 | 81 | else : |
| 110 | - if ( function_exists( '_publish_post_hook' ) ) : // WordPress 2.3 | |
| 111 | - _publish_post_hook( $post_id ); | |
| 82 | + if (function_exists('_publish_post_hook')) : // WordPress 2.3 | |
| 83 | + _publish_post_hook($post_id); | |
| 112 | 84 | endif; |
| 113 | 85 | endif; |
| 114 | -} /* function fwp_publish_post_hook() */ | |
| 86 | +} | |