Make WordPress Core

Ticket #11334: 11334.patch

File 11334.patch, 4.2 KB (added by Viper007Bond, 15 years ago)
  • wp-includes/comment.php

     
    674674        if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent )
    675675                return get_page_of_comment( $comment->comment_parent, $args );
    676676
    677         $allowedtypes = array(
    678                 'comment' => '',
    679                 'pingback' => 'pingback',
    680                 'trackback' => 'trackback',
    681         );
     677        switch ( $args['type'] ) {
     678                case 'comment':
     679                        $comtype = 'comment';
     680                        $comtypewhere = " AND comment_type = ''";
     681                        break;
     682                case 'pingback':
     683                        $comtype = 'pingback';
     684                        $comtypewhere = " AND comment_type = 'pingback'";
     685                        break;
     686                case 'trackback':
     687                        $comtype = 'trackback';
     688                        $comtypewhere = " AND comment_type = 'trackback'";
     689                        break;
     690                case 'pings':
     691                        $comtype = 'pings';
     692                        $comtypewhere = " AND ( comment_type = 'pingback' OR comment_type = 'trackback' )";
     693                        break;
     694                default;
     695                        $comtype = 'all';
     696                        $comtypewhere = '';
     697        }
    682698
    683         $comtypewhere = ( 'all' != $args['type'] && isset($allowedtypes[$args['type']]) ) ? " AND comment_type = '" . $allowedtypes[$args['type']] . "'" : '';
     699        $cachekey = 'post-' . $comment->comment_post_ID;
    684700
    685         // Count comments older than this one
    686         $oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = 0 AND comment_approved = '1' AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt ) );
     701        // Check the cache and set it up if it's not set (so we can use replace later on)
     702        if ( false === $oldercoms_cache = wp_cache_get( $cachekey, 'comment_pages' ) ) {
     703                $oldercoms_cache = array();
     704                wp_cache_add( $cachekey, $oldercoms_cache, 'comment_pages' );
     705        }
     706        $oldercoms_cache = (array) $oldercoms_cache;
    687707
     708        // Get comments older than this comment
     709        $oldercoms = ( isset( $oldercoms_cache[$comtype] ) && isset( $oldercoms_cache[$comtype][$comment->comment_ID] ) ) ? $oldercoms_cache[$comtype][$comment->comment_ID] : false;
     710        if ( false === $oldercoms ) {
     711                $oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = 0 AND comment_approved = '1' AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt ) );
     712                $oldercoms_cache[$comtype][$comment->comment_ID] = $oldercoms;
     713                wp_cache_replace( $cachekey, $oldercoms_cache, 'comment_pages' );
     714        }
     715
    688716        // No older comments? Then it's page #1.
    689717        if ( 0 == $oldercoms )
    690718                return 1;
     
    694722}
    695723
    696724/**
     725 * Clears the cache used by get_page_of_comment(). Is designed to be attached to the
     726 * 'clear_page_of_comment_cache' action inside of wp_transition_comment_status();
     727 *
     728 * @since 2.9.0
     729 * @uses wp_cache_delete() Does the cache deleting.
     730 *
     731 * @param string $new_status Unused
     732 * @param string $old_status Unused
     733 * @param object $comment Comment object that had it's status changed
     734 * @return bool True on successful removal, false on failure
     735 */
     736function clear_page_of_comment_cache( $new_status, $old_status, $comment ) {
     737        return wp_cache_delete( 'post-' . $comment->comment_post_ID, 'comment_pages' );
     738}
     739
     740/**
    697741 * Does comment contain blacklisted characters or words.
    698742 *
    699743 * @since 1.5.0
  • wp-includes/default-filters.php

     
    210210add_action( 'future_page',                '_future_post_hook',        5, 2 );
    211211add_action( 'save_post',                  '_save_post_hook',          5, 2 );
    212212add_action( 'transition_post_status',     '_transition_post_status',  5, 3 );
    213 add_action( 'comment_form', 'wp_comment_form_unfiltered_html_nonce'        );
    214 add_action( 'wp_scheduled_delete',        'wp_scheduled_delete' );
     213add_action( 'comment_form',        'wp_comment_form_unfiltered_html_nonce' );
     214add_action( 'wp_scheduled_delete',        'wp_scheduled_delete'            );
     215add_action( 'transition_comment_status',  'clear_page_of_comment_cache'    );
    215216
    216217// Post Image CSS class filtering
    217218add_action( 'begin_fetch_post_image_html', '_wp_post_image_class_filter_add'    );