Ticket #17548: 17548.7.2.diff

File 17548.7.2.diff, 4.5 KB (added by joehoyle, 20 months ago)
  • wp-includes/default-filters.php

     
    254254add_action( 'publish_post',               '_publish_post_hook',                       5, 1 ); 
    255255add_action( 'save_post',                  '_save_post_hook',                          5, 2 ); 
    256256add_action( 'transition_post_status',     '_transition_post_status',                  5, 3 ); 
     257add_action( 'transition_post_status',     '_update_term_count_on_transition_post_status', 10, 3 ); 
    257258add_action( 'comment_form',               'wp_comment_form_unfiltered_html_nonce'          ); 
    258259add_action( 'wp_scheduled_delete',        'wp_scheduled_delete'                            ); 
    259260add_action( 'admin_init',                 'send_frame_options_header',               10, 0 ); 
  • wp-includes/taxonomy.php

     
    24472447                call_user_func($taxonomy->update_count_callback, $terms, $taxonomy); 
    24482448        } else { 
    24492449                // Default count updater 
    2450                 foreach ( (array) $terms as $term) { 
    2451                         $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term) ); 
    2452                         do_action( 'edit_term_taxonomy', $term, $taxonomy ); 
    2453                         $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) ); 
    2454                         do_action( 'edited_term_taxonomy', $term, $taxonomy ); 
    2455                 } 
    2456  
     2450                _update_post_term_count( $terms, $taxonomy ); 
    24572451        } 
    24582452 
    24592453        clean_term_cache($terms, '', false); 
     
    28492843        $object_types = esc_sql($object_types); 
    28502844 
    28512845        foreach ( (array) $terms as $term ) { 
    2852                 $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type IN ('" . implode("', '", $object_types) . "') AND term_taxonomy_id = %d", $term ) ); 
     2846                 
     2847                // Attachments can be 'inherit' status, we need to base count off the parent's staus if so 
     2848                if ( in_array( 'attachment', $object_types ) ) 
     2849                        $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts p1 WHERE p1.ID = $wpdb->term_relationships.object_id AND ( post_status = 'publish' OR ( post_status = 'inherit' AND post_parent > 0 AND ( SELECT post_status FROM $wpdb->posts WHERE ID = p1.post_parent ) = 'publish' ) ) AND post_type IN ('" . implode("', '", $object_types) . "') AND term_taxonomy_id = %d", $term ) ); 
     2850                else 
     2851                        $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type IN ('" . implode("', '", $object_types) . "') AND term_taxonomy_id = %d", $term ) ); 
     2852 
    28532853                do_action( 'edit_term_taxonomy', $term, $taxonomy ); 
    28542854                $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) ); 
    28552855                do_action( 'edited_term_taxonomy', $term, $taxonomy ); 
  • wp-includes/post.php

     
    27312731        $post->post_status = 'publish'; 
    27322732        wp_transition_post_status('publish', $old_status, $post); 
    27332733 
    2734         // Update counts for the post's terms. 
    2735         foreach ( (array) get_object_taxonomies('post') as $taxonomy ) { 
    2736                 $tt_ids = wp_get_object_terms($post_id, $taxonomy, array('fields' => 'tt_ids')); 
    2737                 wp_update_term_count($tt_ids, $taxonomy); 
    2738         } 
    2739  
    27402734        do_action('edit_post', $post_id, $post); 
    27412735        do_action('save_post', $post_id, $post); 
    27422736        do_action('wp_insert_post', $post_id, $post); 
     
    53125306} 
    53135307add_filter( 'wp_get_object_terms', '_post_format_wp_get_object_terms' ); 
    53145308 
     5309/** 
     5310 * Update the custom taxonomies' term counts when a post's status is changed. For example, default posts term counts (for custom taxonomies) don't include private / draft posts. 
     5311 *  
     5312 * @access private 
     5313 * @param string $new_status 
     5314 * @param string $old_status 
     5315 * @param object $post 
     5316 * @since 3.3.0 
     5317 */ 
     5318function _update_term_count_on_transition_post_status( $new_status, $old_status, $post ) { 
     5319        // Update counts for the post's terms. 
     5320        foreach ( (array) get_object_taxonomies( $post->post_type ) as $taxonomy ) { 
     5321                $tt_ids = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'tt_ids' ) ); 
     5322                wp_update_term_count( $tt_ids, $taxonomy ); 
     5323        } 
     5324} 
    53155325?>