Make WordPress Core

Ticket #36824: 36824.7.diff

File 36824.7.diff, 5.4 KB (added by dshanske, 7 years ago)
  • src/wp-includes/comment.php

     
    25792579function do_all_pings() {
    25802580        global $wpdb;
    25812581
     2582        // Determine which classes support trackbacks and pingbacks
     2583        $ping_types = get_post_types_by_support( 'trackbacks' );
     2584
    25822585        // Do pingbacks
    2583         while ( $ping = $wpdb->get_row( "SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1" ) ) {
    2584                 delete_metadata_by_mid( 'post', $ping->meta_id );
    2585                 pingback( $ping->post_content, $ping->ID );
     2586
     2587        $pings = get_posts(
     2588                array(
     2589                        'post_type' => $ping_types,
     2590                        'suppress_filters' => false,
     2591                        'nopaging' => true,
     2592                        'meta_value' => '_pingme',
     2593                        'fields' => 'ids'
     2594                )
     2595        );
     2596        foreach ( $pings as $ping ) {
     2597                delete_post_meta( $ping, '_pingme' );
     2598                pingback( null, $ping );
    25862599        }
    25872600
    25882601        // Do Enclosures
    2589         while ( $enclosure = $wpdb->get_row( "SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1" ) ) {
    2590                 delete_metadata_by_mid( 'post', $enclosure->meta_id );
    2591                 do_enclose( $enclosure->post_content, $enclosure->ID );
     2602        $enclosures = get_posts(
     2603                array(
     2604                        'post_type' => get_post_types( array( 'publicly_queryable' => true ) ),
     2605                        'suppress_filters' => false,
     2606                        'nopaging' => true,
     2607                        'meta_value' => '_encloseme',
     2608                        'fields' => 'ids'
     2609                )
     2610        );
     2611        foreach ( $enclosures as $enclosure ) {
     2612                delete_post_meta( $enclosure, '_encloseme' );
     2613                do_enclose( null, $enclosure );
    25922614        }
    25932615
    25942616        // Do Trackbacks
    2595         $trackbacks = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE to_ping <> '' AND post_status = 'publish'" );
    2596         if ( is_array( $trackbacks ) ) {
    2597                 foreach ( $trackbacks as $trackback ) {
    2598                         do_trackbacks( $trackback );
    2599                 }
     2617        $trackbacks = get_posts(
     2618                array(
     2619                        'post_type' => $ping_types,
     2620                        'suppress_filters' => false,
     2621                        'nopaging' => true,
     2622                        'to_ping' => true,
     2623                        'fields' => 'ids'
     2624                )
     2625        );
     2626        foreach ( $trackbacks as $trackback ) {
     2627                do_trackbacks( $trackback );
    26002628        }
    26012629
    26022630        //Do Update Services/Generic Pings
  • src/wp-includes/functions.php

     
    562562 * pingbacks and trackbacks.
    563563 *
    564564 * @since 1.5.0
     565 * @since 4.9.7 $post_id can be a WP_Post Object
    565566 *
    566567 * @global wpdb $wpdb WordPress database abstraction object.
    567568 *
    568  * @param string $content Post Content.
    569  * @param int    $post_ID Post ID.
     569 * @param string $content Post Content. If empty will retrieve from post.
     570 * @param int|WP_Post    $post_id Post object or ID.
    570571 */
    571 function do_enclose( $content, $post_ID ) {
     572function do_enclose( $content, $post_id ) {
    572573        global $wpdb;
     574        $post = get_post( $post_id );
     575        if ( ! $post ) {
     576                return false;
     577        }
     578        if ( ! $content ) {
     579                $content = $post->post_content;
     580        }
    573581
    574582        //TODO: Tidy this ghetto code up and make the debug code optional
    575583        include_once( ABSPATH . WPINC . '/class-IXR.php' );
    576584
    577585        $post_links = array();
    578586
    579         $pung = get_enclosed( $post_ID );
     587        $pung = get_enclosed( $post->ID );
    580588
    581589        $post_links_temp = wp_extract_urls( $content );
    582590
    583591        foreach ( $pung as $link_test ) {
    584592                if ( ! in_array( $link_test, $post_links_temp ) ) { // link no longer in post
    585                         $mids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE %s", $post_ID, $wpdb->esc_like( $link_test ) . '%' ) );
     593                        $mids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE %s", $post->ID, $wpdb->esc_like( $link_test ) . '%' ) );
    586594                        foreach ( $mids as $mid ) {
    587595                                delete_metadata_by_mid( 'post', $mid );
    588596                        }
     
    591599
    592600        foreach ( (array) $post_links_temp as $link_test ) {
    593601                if ( ! in_array( $link_test, $pung ) ) { // If we haven't pung it already
    594                         $test = @parse_url( $link_test );
     602                        $test = @wp_parse_url( $link_test );
    595603                        if ( false === $test ) {
    596604                                continue;
    597605                        }
     
    612620         * @since 4.4.0
    613621         *
    614622         * @param array $post_links An array of enclosure links.
    615          * @param int   $post_ID    Post ID.
     623         * @param int   $post_id    Post ID.
    616624         */
    617         $post_links = apply_filters( 'enclosure_links', $post_links, $post_ID );
     625        $post_links = apply_filters( 'enclosure_links', $post_links, $post->ID );
    618626
    619627        foreach ( (array) $post_links as $url ) {
    620                 if ( $url != '' && ! $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE %s", $post_ID, $wpdb->esc_like( $url ) . '%' ) ) ) {
     628                if ( $url != '' && ! $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE %s", $post->ID, $wpdb->esc_like( $url ) . '%' ) ) ) {
    621629
    622630                        if ( $headers = wp_get_http_headers( $url ) ) {
    623631                                $len           = isset( $headers['content-length'] ) ? (int) $headers['content-length'] : 0;
     
    640648                                }
    641649
    642650                                if ( in_array( substr( $type, 0, strpos( $type, '/' ) ), $allowed_types ) ) {
    643                                         add_post_meta( $post_ID, 'enclosure', "$url\n$len\n$mime\n" );
     651                                        add_post_meta( $post->ID, 'enclosure', "$url\n$len\n$mime\n" );
    644652                                }
    645653                        }
    646654                }