WordPress.org

Make WordPress Core

Ticket #11334: 11334-3.6.patch

File 11334-3.6.patch, 4.0 KB (added by wmertens, 8 months ago)

Applies to 3.6

  • wp-includes/comment.php

    diff --git a/wp-includes/comment.php b/wp-includes/comment.php
    index 4d4c9bc..5cb54e9 100644
    a b function get_page_of_comment( $comment_ID, $args = array() ) { 
    853853        if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent ) 
    854854                return get_page_of_comment( $comment->comment_parent, $args ); 
    855855 
    856         $allowedtypes = array( 
    857                 'comment' => '', 
    858                 'pingback' => 'pingback', 
    859                 'trackback' => 'trackback', 
    860         ); 
    861  
    862         $comtypewhere = ( 'all' != $args['type'] && isset($allowedtypes[$args['type']]) ) ? " AND comment_type = '" . $allowedtypes[$args['type']] . "'" : ''; 
    863  
    864         // Count comments older than this one 
     856        switch ( $args['type'] ) { 
     857                case 'comment': 
     858                        $comtype = 'comment'; 
     859                        $comtypewhere = " AND comment_type = ''"; 
     860                        break; 
     861                case 'pingback': 
     862                        $comtype = 'pingback'; 
     863                        $comtypewhere = " AND comment_type = 'pingback'"; 
     864                        break; 
     865                case 'trackback': 
     866                        $comtype = 'trackback'; 
     867                        $comtypewhere = " AND comment_type = 'trackback'"; 
     868                        break; 
     869                case 'pings': 
     870                        $comtype = 'pings'; 
     871                        $comtypewhere = " AND ( comment_type = 'pingback' OR comment_type = 'trackback' )"; 
     872                        break; 
     873                default; 
     874                        $comtype = 'all'; 
     875                        $comtypewhere = ''; 
     876        } 
     877  
     878        $cachekey = 'post-' . $comment->comment_post_ID; 
     879        // Check the cache and set it up if it's not set (so we can use replace later on) 
     880        if ( false === $oldercoms_cache = wp_cache_get( $cachekey, 'comment_pages' ) ) { 
     881                $oldercoms_cache = array(); 
     882                wp_cache_add( $cachekey, $oldercoms_cache, 'comment_pages' ); 
     883        } 
     884        $oldercoms_cache = (array) $oldercoms_cache; 
     885  
     886        // Get comments older than this comment 
     887        $oldercoms = ( isset( $oldercoms_cache[$comtype] ) && isset( $oldercoms_cache[$comtype][$comment->comment_ID] ) ) ? $oldercoms_cache[$comtype][$comment->comment_ID] : false; 
     888        if ( false === $oldercoms ) { 
    865889        $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 ) ); 
    866  
     890                $oldercoms_cache[$comtype][$comment->comment_ID] = $oldercoms; 
     891                wp_cache_replace( $cachekey, $oldercoms_cache, 'comment_pages' ); 
     892        } 
     893  
    867894        // No older comments? Then it's page #1. 
    868895        if ( 0 == $oldercoms ) 
    869896                return 1; 
    function get_page_of_comment( $comment_ID, $args = array() ) { 
    873900} 
    874901 
    875902/** 
     903 * Clears the cache used by get_page_of_comment(). Is designed to be attached to the 
     904 * 'clear_page_of_comment_cache' action inside of wp_transition_comment_status(); 
     905 * 
     906 * @since 2.9.0 
     907 * @uses wp_cache_delete() Does the cache deleting. 
     908 * 
     909 * @param string $new_status Unused 
     910 * @param string $old_status Unused 
     911 * @param object $comment Comment object that had it's status changed 
     912 * @return bool True on successful removal, false on failure 
     913 */ 
     914function clear_page_of_comment_cache( $new_status, $old_status, $comment ) { 
     915        return wp_cache_delete( 'post-' . $comment->comment_post_ID, 'comment_pages' ); 
     916} 
     917 
     918/** 
    876919 * Does comment contain blacklisted characters or words. 
    877920 * 
    878921 * @since 1.5.0 
  • wp-includes/default-filters.php

    diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php
    index 89b3976..60f4dbf 100644
    a b add_action( 'transition_post_status', '_update_term_count_on_transition_post 
    259259add_action( 'comment_form',               'wp_comment_form_unfiltered_html_nonce'          ); 
    260260add_action( 'wp_scheduled_delete',        'wp_scheduled_delete'                            ); 
    261261add_action( 'wp_scheduled_auto_draft_delete', 'wp_delete_auto_drafts'                      ); 
     262add_action( 'transition_comment_status',  'clear_page_of_comment_cache',             10, 3 ); 
    262263add_action( 'admin_init',                 'send_frame_options_header',               10, 0 ); 
    263264add_action( 'importer_scheduled_cleanup', 'wp_delete_attachment'                           ); 
    264265add_action( 'upgrader_scheduled_cleanup', 'wp_delete_attachment'                           );