WordPress.org

Make WordPress Core

Ticket #38202: 38202.diff

File 38202.diff, 7.0 KB (added by dshanske, 4 years ago)

Add Post Object support to Ping Functions

  • 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() { 
    23082308 * Perform trackbacks.
    23092309 *
    23102310 * @since 1.5.0
     2311 * @since 4.7.0
    23112312 *
    23122313 * @global wpdb $wpdb WordPress database abstraction object.
    23132314 *
    2314  * @param int $post_id Post ID to do trackbacks on.
     2315 * @param int|WP_Post $post Post Object or ID to do trackbacks on.
    23152316 */
    2316 function do_trackbacks($post_id) {
     2317function do_trackbacks( $post ) {
    23172318        global $wpdb;
     2319        $post = get_post( $post );
     2320        if ( ! $post ) {
     2321                return false;
     2322        }
    23182323
    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 );
    23222326        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) );
    23242328                return;
    23252329        }
    23262330
    function do_trackbacks($post_id) { 
    23432347                foreach ( (array) $to_ping as $tb_ping ) {
    23442348                        $tb_ping = trim($tb_ping);
    23452349                        if ( !in_array($tb_ping, $pinged) ) {
    2346                                 trackback($tb_ping, $post_title, $excerpt, $post_id);
     2350                                trackback($tb_ping, $post_title, $excerpt, $post->ID);
    23472351                                $pinged[] = $tb_ping;
    23482352                        } 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) );
    23502355                        }
    23512356                }
    23522357        }
    function generic_ping( $post_id = 0 ) { 
    23782383 *
    23792384 * @since 0.71
    23802385 *
    2381  * @param string $content Post content to check for links.
    2382  * @param int $post_ID Post ID.
     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.
    23832388 */
    2384 function pingback($content, $post_ID) {
     2389function pingback($content, $post) {
    23852390        include_once( ABSPATH . WPINC . '/class-IXR.php' );
    23862391        include_once( ABSPATH . WPINC . '/class-wp-http-ixr-client.php' );
    23872392
    23882393        // original code by Mort (http://mort.mine.nu:8080)
    23892394        $post_links = array();
    23902395
    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        }
    23922406
    23932407        // Step 1
    23942408        // Parsing the post, external links (if any) are stored in the $post_links array
    function pingback($content, $post_ID) { 
    24042418        // We don't wanna ping first and second types, even if they have a valid <link/>
    24052419
    24062420        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 itself
     2421                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
    24082422                                && !is_local_attachment($link_test) ) : // Also, let's never ping local attachments.
    24092423                        if ( $test = @parse_url($link_test) ) {
    24102424                                if ( isset($test['query']) )
    function pingback($content, $post_ID) { 
    24252439         * @param array &$pung       Whether a link has already been pinged, passed by reference.
    24262440         * @param int   $post_ID     The post ID.
    24272441         */
    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 ) );
    24292443
    24302444        foreach ( (array) $post_links as $pagelinkedto ) {
    24312445                $pingback_server_url = discover_pingback_server_uri( $pagelinkedto );
    function pingback($content, $post_ID) { 
    24332447                if ( $pingback_server_url ) {
    24342448                        @ set_time_limit( 60 );
    24352449                        // Now, the RPC call
    2436                         $pagelinkedfrom = get_permalink($post_ID);
     2450                        $pagelinkedfrom = get_permalink( $post );
    24372451
    24382452                        // using a timeout of 3 seconds should be enough to cover slow servers
    24392453                        $client = new WP_HTTP_IXR_Client($pingback_server_url);
    function pingback($content, $post_ID) { 
    24552469                        $client->debug = false;
    24562470
    24572471                        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 );
    24592473                }
    24602474        }
    24612475}
  • src/wp-includes/post.php

    diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
    index c02108e..c7edd3e 100644
    a b function wp_transition_post_status( $new_status, $old_status, $post ) { 
    39093909 *
    39103910 * @since 1.5.0
    39113911 *
     3912 * @since 4.7.0 Support Post Object.
     3913 *
    39123914 * @global wpdb $wpdb WordPress database abstraction object.
    39133915 *
    3914  * @param int    $post_id Post ID.
     3916 * @param int|WP_Post    $post Post Object or ID.
    39153917 * @param string $uri     Ping URI.
    39163918 * @return int|false How many rows were updated.
    39173919 */
    3918 function add_ping( $post_id, $uri ) {
     3920function add_ping( $post, $uri ) {
    39193921        global $wpdb;
    3920         $pung = $wpdb->get_var( $wpdb->prepare( "SELECT pinged FROM $wpdb->posts WHERE ID = %d", $post_id ));
     3922       
     3923        $post = get_post( $post );
     3924        if ( ! $post ) {
     3925                return false;
     3926        }
     3927
     3928        $pung = $post-pinged;
    39213929        $pung = trim($pung);
    39223930        $pung = preg_split('/\s/', $pung);
    39233931        $pung[] = $uri;
    function add_ping( $post_id, $uri ) { 
    39343942
    39353943        // expected_slashed ($new).
    39363944        $new = wp_unslash($new);
    3937         return $wpdb->update( $wpdb->posts, array( 'pinged' => $new ), array( 'ID' => $post_id ) );
     3945        return $wpdb->update( $wpdb->posts, array( 'pinged' => $new ), array( 'ID' => $post->ID ) );
    39383946}
    39393947
    39403948/**
    function get_enclosed( $post_id ) { 
    39763984 *
    39773985 * @since 1.5.0
    39783986 *
    3979  * @global wpdb $wpdb WordPress database abstraction object.
     3987 * @since 4.7.0 Accept Post Object
    39803988 *
    3981  * @param int $post_id Post ID.
     3989 * @param int|WP_Post $post Post ID or object.
    39823990 * @return array
    39833991 */
    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);
     3992function get_pung( $post ) {
     3993        $post = get_post( $post );
     3994        if ( ! $post ) {
     3995                return false;
     3996        }
     3997        $pung = trim( $post->pinged );
     3998        $pung = preg_split( '/\s/', $pung );
    39893999
    39904000        /**
    39914001         * Filters the list of already-pinged URLs for the given post.
    function get_pung( $post_id ) { 
    40024012 *
    40034013 * @since 1.5.0
    40044014 *
    4005  * @global wpdb $wpdb WordPress database abstraction object.
     4015 * @since 4.7.0 Support Post Object.
    40064016 *
    4007  * @param int $post_id Post ID
     4017 * @param int|WP_Post $post Post Object or ID
    40084018 * @return array
    40094019 */
    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 );
     4020function get_to_ping( $post ) {
     4021        $post = get_post( $post );
     4022        if ( ! $post ) {
     4023                return false;
     4024        }
     4025
     4026        $to_ping = sanitize_trackback_urls( $post->to_ping );
    40144027        $to_ping = preg_split('/\s/', $to_ping, -1, PREG_SPLIT_NO_EMPTY);
    40154028
    40164029        /**