| 871 | | $allowedtypes = array( |
| 872 | | 'comment' => '', |
| 873 | | 'pingback' => 'pingback', |
| 874 | | 'trackback' => 'trackback', |
| 875 | | ); |
| | 871 | switch ( $args['type'] ) { |
| | 872 | case 'comment': |
| | 873 | $comment_type = 'comment'; |
| | 874 | $comment_type_where = " AND comment_type = ''"; |
| | 875 | break; |
| | 876 | case 'pingback': |
| | 877 | $comment_type = 'pingback'; |
| | 878 | $comment_type_where = " AND comment_type = 'pingback'"; |
| | 879 | break; |
| | 880 | case 'trackback': |
| | 881 | $comment_type = 'trackback'; |
| | 882 | $comment_type_where = " AND comment_type = 'trackback'"; |
| | 883 | break; |
| | 884 | case 'pings': |
| | 885 | $comment_type = 'pings'; |
| | 886 | $comment_type_where = " AND ( comment_type = 'pingback' OR comment_type = 'trackback' )"; |
| | 887 | break; |
| | 888 | default: |
| | 889 | $comment_type = 'all'; |
| | 890 | $comment_type_where = ''; |
| | 891 | } |
| 877 | | $comtypewhere = ( 'all' != $args['type'] && isset($allowedtypes[$args['type']]) ) ? " AND comment_type = '" . $allowedtypes[$args['type']] . "'" : ''; |
| | 893 | $cache_key = 'post-' . $comment->comment_post_ID; |
| | 894 | // Check the cache and set it up if it's not set (so we can use replace later on) |
| | 895 | if ( false === $older_comments_cache = wp_cache_get( $cache_key, 'comment_pages' ) ) { |
| | 896 | $older_comments_cache = array(); |
| | 897 | wp_cache_add( $cache_key, $older_comments_cache, 'comment_pages' ); |
| | 898 | } |
| | 899 | $older_comments_cache = (array) $older_comments_cache; |
| 879 | | // Count comments older than this one |
| 880 | | $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 ) ); |
| | 901 | // Get comments older than this comment |
| | 902 | $older_comments = ( isset( $older_comments_cache[ $comment_type ] ) && isset( $older_comments_cache[ $comment_type ][ $comment->comment_ID ] ) ) ? $older_comments_cache[ $comment_type ][ $comment->comment_ID ] : false; |
| | 903 | if ( false === $older_comments ) { |
| | 904 | $older_comments = $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'" . $comment_type_where, $comment->comment_post_ID, $comment->comment_date_gmt ) ); |
| | 919 | * Clears the cache used by get_page_of_comment(). Is designed to be attached to the |
| | 920 | * 'clear_page_of_comment_cache' action inside of wp_transition_comment_status(); |
| | 921 | * |
| | 922 | * @since 3.7.0 |
| | 923 | * @uses wp_cache_delete() Does the cache deleting. |
| | 924 | * |
| | 925 | * @param string $new_status Unused |
| | 926 | * @param string $old_status Unused |
| | 927 | * @param object $comment Comment object that had it's status changed |
| | 928 | * @return bool True on successful removal, false on failure |
| | 929 | */ |
| | 930 | function clear_page_of_comment_cache( $new_status, $old_status, $comment ) { |
| | 931 | return wp_cache_delete( 'post-' . $comment->comment_post_ID, 'comment_pages' ); |
| | 932 | } |
| | 933 | |
| | 934 | /** |