Ticket #2933: 2933.diff

File 2933.diff, 2.4 KB (added by Denis-de-Bernardy, 4 years ago)
Line 
1Index: wp-includes/comment.php
2===================================================================
3--- wp-includes/comment.php     (revision 11300)
4+++ wp-includes/comment.php     (working copy)
5@@ -1381,13 +1381,55 @@
6  */
7 function generic_ping($post_id = 0) {
8        $services = get_option('ping_sites');
9+       $update_services = false;
10+       
11+       $errors = get_transient('ping_errors');
12+       $update_errors = false;
13+       
14+       if ( false === $errors ) {
15+               $update_errors = true;
16+               $errors = array();
17+       }
18 
19        $services = explode("\n", $services);
20-       foreach ( (array) $services as $service ) {
21+       foreach ( (array) $services as $i => $service ) {
22                $service = trim($service);
23-               if ( '' != $service )
24-                       weblog_ping($service);
25+               if ( '' != $service ) {
26+                       if ( !isset($errors[$service]) )
27+                               $errors[$service] = array('count' => 0, 'time' => 0);
28+                       $success = weblog_ping($service);
29+                       if ( !$success ) {
30+                               if ( time() - $errors[$service]['time'] > 86400 ) { // count failures once per day at most
31+                                       $update_errors = true;
32+                                       $errors[$service]['time'] = time();
33+                                       $errors[$service]['count']++;
34+                                       // Pings have consistently failed for 14 seperate days
35+                                       if ( $errors[$services]['count'] > 14 ) {
36+                                               $update_services = true;
37+                                               unset($services[$i]);
38+                                       }
39+                               }
40+                       } elseif ( $errors[$service]['count'] ) {
41+                               // reset counter
42+                               $update_errors = true;
43+                               $errors[$service]['time'] = time();
44+                               $errors[$service]['count'] = 0;
45+                       }
46+               }
47        }
48+       
49+       if ( $update_services )
50+               update_option('ping_sites', implode("\n", $services));
51+       
52+       if ( $udpate_errors ) {
53+               // the user may remove services from the admin interface, so we filter out invalid ones here
54+               foreach ( array_keys($errors) as $service ) {
55+                       if ( !in_array($service, $services) )
56+                               unset($errors[$service]);
57+               }
58+               
59+               set_transient('ping_errors', $errors);
60+       }
61 
62        return $post_id;
63 }
64@@ -1531,6 +1573,7 @@
65  *
66  * @param string $server Host of blog to connect to.
67  * @param string $path Path to send the ping.
68+ * @return bool $success Whether the ping was successful
69  */
70 function weblog_ping($server = '', $path = '') {
71        global $wp_version;
72@@ -1546,6 +1589,8 @@
73        $home = trailingslashit( get_option('home') );
74        if ( !$client->query('weblogUpdates.extendedPing', get_option('blogname'), $home, get_bloginfo('rss2_url') ) ) // then try a normal ping
75                $client->query('weblogUpdates.ping', get_option('blogname'), $home);
76+       
77+       return !$client->isError();
78 }
79 
80 //