Ticket #38202: 38202.2.diff
File 38202.2.diff, 9.6 KB (added by , 9 years ago) |
---|
-
src/wp-includes/comment.php
diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index 861ad6b..44a72a9 100644
a b function do_all_pings() { 2308 2308 * Perform trackbacks. 2309 2309 * 2310 2310 * @since 1.5.0 2311 * @since 4.7.0 2311 2312 * 2312 2313 * @global wpdb $wpdb WordPress database abstraction object. 2313 2314 * 2314 * @param int $post_id PostID to do trackbacks on.2315 * @param int|WP_Post $post Post Object or ID to do trackbacks on. 2315 2316 */ 2316 function do_trackbacks( $post_id) {2317 function do_trackbacks( $post ) { 2317 2318 global $wpdb; 2319 $post = get_post( $post ); 2320 if ( ! $post ) { 2321 return false; 2322 } 2318 2323 2319 $post = get_post( $post_id ); 2320 $to_ping = get_to_ping($post_id); 2321 $pinged = get_pung($post_id); 2324 $to_ping = get_to_ping( $post ); 2325 $pinged = get_pung( $post ); 2322 2326 if ( empty($to_ping) ) { 2323 $wpdb->update($wpdb->posts, array('to_ping' => ''), array('ID' => $post _id) );2327 $wpdb->update($wpdb->posts, array('to_ping' => ''), array('ID' => $post->ID) ); 2324 2328 return; 2325 2329 } 2326 2330 … … function do_trackbacks($post_id) { 2343 2347 foreach ( (array) $to_ping as $tb_ping ) { 2344 2348 $tb_ping = trim($tb_ping); 2345 2349 if ( !in_array($tb_ping, $pinged) ) { 2346 trackback($tb_ping, $post_title, $excerpt, $post _id);2350 trackback($tb_ping, $post_title, $excerpt, $post->ID); 2347 2351 $pinged[] = $tb_ping; 2348 2352 } else { 2349 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $tb_ping, $post_id) ); 2353 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, 2354 '')) WHERE ID = %d", $tb_ping, $post->ID) ); 2350 2355 } 2351 2356 } 2352 2357 } … … function generic_ping( $post_id = 0 ) { 2378 2383 * 2379 2384 * @since 0.71 2380 2385 * 2381 * @param string $content Post content to check for links. 2382 * @param int $post_ID PostID.2386 * @param string $content Post content to check for links. If empty will retrieve from post. 2387 * @param int|WP_Post $post Post Object or ID. 2383 2388 */ 2384 function pingback($content, $post _ID) {2389 function pingback($content, $post) { 2385 2390 include_once( ABSPATH . WPINC . '/class-IXR.php' ); 2386 2391 include_once( ABSPATH . WPINC . '/class-wp-http-ixr-client.php' ); 2387 2392 2388 2393 // original code by Mort (http://mort.mine.nu:8080) 2389 2394 $post_links = array(); 2390 2395 2391 $pung = get_pung($post_ID); 2396 $post = get_post( $post ); 2397 if ( ! $post ) { 2398 return false; 2399 } 2400 2401 $pung = get_pung( $post ); 2402 2403 if ( empty( $content ) ) { 2404 $content = $post->post_content; 2405 } 2392 2406 2393 2407 // Step 1 2394 2408 // Parsing the post, external links (if any) are stored in the $post_links array … … function pingback($content, $post_ID) { 2404 2418 // We don't wanna ping first and second types, even if they have a valid <link/> 2405 2419 2406 2420 foreach ( (array) $post_links_temp as $link_test ) : 2407 if ( !in_array($link_test, $pung) && (url_to_postid($link_test) != $post _ID) // If we haven't pung it already and it isn't a link to itself2421 if ( !in_array($link_test, $pung) && (url_to_postid($link_test) != $post->ID) // If we haven't pung it already and it isn't a link to itself 2408 2422 && !is_local_attachment($link_test) ) : // Also, let's never ping local attachments. 2409 2423 if ( $test = @parse_url($link_test) ) { 2410 2424 if ( isset($test['query']) ) … … function pingback($content, $post_ID) { 2425 2439 * @param array &$pung Whether a link has already been pinged, passed by reference. 2426 2440 * @param int $post_ID The post ID. 2427 2441 */ 2428 do_action_ref_array( 'pre_ping', array( &$post_links, &$pung, $post _ID ) );2442 do_action_ref_array( 'pre_ping', array( &$post_links, &$pung, $post->ID ) ); 2429 2443 2430 2444 foreach ( (array) $post_links as $pagelinkedto ) { 2431 2445 $pingback_server_url = discover_pingback_server_uri( $pagelinkedto ); … … function pingback($content, $post_ID) { 2433 2447 if ( $pingback_server_url ) { 2434 2448 @ set_time_limit( 60 ); 2435 2449 // Now, the RPC call 2436 $pagelinkedfrom = get_permalink( $post_ID);2450 $pagelinkedfrom = get_permalink( $post ); 2437 2451 2438 2452 // using a timeout of 3 seconds should be enough to cover slow servers 2439 2453 $client = new WP_HTTP_IXR_Client($pingback_server_url); … … function pingback($content, $post_ID) { 2455 2469 $client->debug = false; 2456 2470 2457 2471 if ( $client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || ( isset($client->error->code) && 48 == $client->error->code ) ) // Already registered 2458 add_ping( $post _ID, $pagelinkedto );2472 add_ping( $post, $pagelinkedto ); 2459 2473 } 2460 2474 } 2461 2475 } -
src/wp-includes/post.php
diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index c02108e..a19af05 100644
a b function wp_transition_post_status( $new_status, $old_status, $post ) { 3909 3909 * 3910 3910 * @since 1.5.0 3911 3911 * 3912 * @since 4.7.0 Support Post Object and Allow for Array 3913 * 3912 3914 * @global wpdb $wpdb WordPress database abstraction object. 3913 3915 * 3914 * @param int $post_id PostID.3915 * @param string $uri Ping URI.3916 * @param int|WP_Post $post Post Object or ID. 3917 * @param string|array $uri Ping URI or array of URIs. 3916 3918 * @return int|false How many rows were updated. 3917 3919 */ 3918 function add_ping( $post _id, $uri ) {3920 function add_ping( $post, $uri ) { 3919 3921 global $wpdb; 3920 $pung = $wpdb->get_var( $wpdb->prepare( "SELECT pinged FROM $wpdb->posts WHERE ID = %d", $post_id )); 3921 $pung = trim($pung); 3922 3923 $post = get_post( $post ); 3924 if ( ! $post ) { 3925 return false; 3926 } 3927 3928 $pung = trim($post->pinged); 3922 3929 $pung = preg_split('/\s/', $pung); 3923 $pung[] = $uri; 3930 if ( is_array( $uri ) ) { 3931 $pung = array_merge( $pung, $uri ); 3932 } 3933 else { 3934 $pung[] = $uri; 3935 } 3924 3936 $new = implode("\n", $pung); 3925 3937 3926 3938 /** … … function add_ping( $post_id, $uri ) { 3932 3944 */ 3933 3945 $new = apply_filters( 'add_ping', $new ); 3934 3946 3935 // expected_slashed ($new).3936 $new = wp_unslash($new);3937 return $ wpdb->update( $wpdb->posts, array( 'pinged' => $new ), array( 'ID' => $post_id ) );3947 $return = $wpdb->update( $wpdb->posts, array( 'pinged' => $new ), array( 'ID' => $post->ID ) ); 3948 clean_post_cache( $post->ID ); 3949 return $return; 3938 3950 } 3939 3951 3940 3952 /** … … function get_enclosed( $post_id ) { 3976 3988 * 3977 3989 * @since 1.5.0 3978 3990 * 3979 * @ global wpdb $wpdb WordPress database abstraction object.3991 * @since 4.7.0 Accept Post Object 3980 3992 * 3981 * @param int $post_id Post ID.3993 * @param int|WP_Post $post Post ID or object. 3982 3994 * @return array 3983 3995 */ 3984 function get_pung( $post_id ) { 3985 global $wpdb; 3986 $pung = $wpdb->get_var( $wpdb->prepare( "SELECT pinged FROM $wpdb->posts WHERE ID = %d", $post_id )); 3987 $pung = trim($pung); 3988 $pung = preg_split('/\s/', $pung); 3996 function get_pung( $post ) { 3997 $post = get_post( $post ); 3998 if ( ! $post ) { 3999 return false; 4000 } 4001 $pung = trim( $post->pinged ); 4002 $pung = preg_split( '/\s/', $pung ); 3989 4003 3990 4004 /** 3991 4005 * Filters the list of already-pinged URLs for the given post. … … function get_pung( $post_id ) { 4002 4016 * 4003 4017 * @since 1.5.0 4004 4018 * 4005 * @ global wpdb $wpdb WordPress database abstraction object.4019 * @since 4.7.0 Support Post Object. 4006 4020 * 4007 * @param int $post_id PostID4021 * @param int|WP_Post $post Post Object or ID 4008 4022 * @return array 4009 4023 */ 4010 function get_to_ping( $post_id ) { 4011 global $wpdb; 4012 $to_ping = $wpdb->get_var( $wpdb->prepare( "SELECT to_ping FROM $wpdb->posts WHERE ID = %d", $post_id )); 4013 $to_ping = sanitize_trackback_urls( $to_ping ); 4024 function get_to_ping( $post ) { 4025 $post = get_post( $post ); 4026 if ( ! $post ) { 4027 return false; 4028 } 4029 4030 $to_ping = sanitize_trackback_urls( $post->to_ping ); 4014 4031 $to_ping = preg_split('/\s/', $to_ping, -1, PREG_SPLIT_NO_EMPTY); 4015 4032 4016 4033 /** -
tests/phpunit/tests/post/pings.php
diff --git a/tests/phpunit/tests/post/pings.php b/tests/phpunit/tests/post/pings.php index 3935d15..aa2bd2e 100644
a b 5 5 * @group pings 6 6 */ 7 7 class Tests_Ping_and_Trackback_Sending extends WP_UnitTestCase { 8 public function test_returns_pinged_sites() { 9 $post_id = self::factory()->post->create( array( 'pinged' => 'foo\nbar\nbaz' ) ); 8 public function test_returns_to_ping_sites_from_post_id() { 9 $post_id = self::factory()->post->create( array( 'to_ping' => 'http://www.example.com 10 http://www.otherexample.com' ) ); 11 $this->assertEqualSets( array( 'http://www.example.com', 'http://www.otherexample.com' ), get_to_ping( $post_id ) ); 12 } 13 public function test_returns_to_ping_sites_from_post_object() { 14 $post_id = self::factory()->post->create( array( 'to_ping' => 'http://www.example.com 15 http://www.otherexample.com' ) ); 16 $post = get_post( $post_id ); 17 $this->assertEqualSets( array( 'http://www.example.com', 'http://www.otherexample.com' ), get_to_ping( $post ) ); 18 } 19 20 public function test_returns_pinged_sites_from_post_id() { 21 $post_id = self::factory()->post->create( array( 'pinged' => 'foo bar baz' ) ); 22 $this->assertEqualSets( array( 'foo', 'bar', 'baz' ), get_pung( $post_id ) ); 23 } 24 public function test_returns_pinged_sites_from_post_object() { 25 $post_id = self::factory()->post->create( array( 'pinged' => 'foo bar baz' ) ); 26 $post = get_post( $post_id ); 27 $this->assertEqualSets( array( 'foo', 'bar', 'baz' ), get_pung( $post ) ); 28 } 29 public function test_add_ping_with_post_id() { 30 $post_id = self::factory()->post->create(); 31 add_ping( $post_id, 'foo' ); 32 add_ping( $post_id, 'bar' ); 33 add_ping( $post_id, 'baz' ); 34 $this->assertEqualSets( array( 'foo', 'bar', 'baz' ), get_pung( $post_id ) ); 35 } 36 37 public function test_add_ping_array_with_post_id() { 38 $post_id = self::factory()->post->create(); 39 add_ping( $post_id, array( 'foo', 'bar', 'baz' ) ); 10 40 $this->assertEqualSets( array( 'foo', 'bar', 'baz' ), get_pung( $post_id ) ); 11 41 } 42 43 public function test_add_ping_with_post_object() { 44 $post_id = self::factory()->post->create(); 45 $post = get_post( $post_id ); 46 add_ping( $post, 'foo' ); 47 $this->assertEqualSets( array( 'foo' ), get_pung( $post_id ) ); 48 } 49 50 51 12 52 } 13 53