PluginProbe
FeedWordPress / trunk
FeedWordPress vtrunk
trunk 0.8 0.9 0.91 0.95 0.96 0.97 0.98 0.981 0.99 0.991 0.992 0.993 2008.1030 2008.1101 2008.1105 2008.1214 2009.0612 2009.0613 2009.0618 2009.0707 2009.1111 2009.1112 2010.0127 2010.0528 All 65 releases
feedwordpress / feedwordpress.pings.functions.php

feedwordpress.pings.functions.php in FeedWordPress trunk, at feedwordpress.pings.functions.php

115 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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; // Why declare it as global if it's not used anywhere else? (gwyneth 20230920)
8
9 /** @var int|null Hold pings (or not yet, if NULL). */
10 $fwp_held_ping = NULL;
11
12 function fwp_hold_pings() {
13 global $fwp_held_ping;
14 if ( is_null ( $fwp_held_ping ) ) :
15 $fwp_held_ping = 0; // 0: ready to hold pings; none yet received
16 FeedWordPress::diagnostic(
17 'syndicated_posts:do_pings',
18 'FeedWordPress is set up to hold pings, fwp_held_ping=' . json_encode( $fwp_held_ping )
19 );
20 endif;
21 } /* function fwp_hold_pings() */
22
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() {
34 global $fwp_held_ping;
35
36 $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;
44 else :
45 generic_ping( $fwp_held_ping );
46 $diag_message = 'released pings';
47 endif;
48 endif;
49
50 $fwp_held_ping = NULL; // NULL: not holding pings anymore
51
52 if ( ! is_null( $diag_message ) ) :
53 FeedWordPress::diagnostic(
54 'syndicated_posts:do_pings',
55 "FeedWordPress {$diag_message}, fwp_held_ping=" . json_encode( $fwp_held_ping ) // isn't this _always_ null? (gwyneth 20230919)
56 );
57 endif;
58 } /* function fwp_release_pings() */
59
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
67 $fwp_held_ping = $post_id;
68
69 FeedWordPress::diagnostic(
70 'syndicated_posts:do_pings',
71 "FeedWordPress intercepted a ping event, fwp_held_ping=".json_encode($fwp_held_ping)
72 );
73
74 elseif ( function_exists( 'do_all_pings' ) ) :
75 do_all_pings();
76 else :
77 generic_ping( $fwp_held_ping );
78 endif;
79 } /* function fwp_do_pings() */
80
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 ) {
89 global $fwp_held_ping;
90
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' ) ) :
99 return;
100 endif;
101
102 // Defer sending out pings until we finish updating
103 $fwp_held_ping = $post_id;
104
105 FeedWordPress::diagnostic(
106 'syndicated_posts:do_pings',
107 "FeedWordPress intercepted a post event, fwp_held_ping=" . json_encode( $fwp_held_ping )
108 );
109 else :
110 if ( function_exists( '_publish_post_hook' ) ) : // WordPress 2.3
111 _publish_post_hook( $post_id );
112 endif;
113 endif;
114 } /* function fwp_publish_post_hook() */
115