From f4c5d4332656c43f3a62317a978021a8d08fd68a Mon Sep 17 00:00:00 2001 From: nacin Date: Thu, 29 Sep 2011 05:29:20 +0000 Subject: [PATCH] Revert [18783], as it breaks term relationship counts for attachment taxonomies. see #17548. git-svn-id: http://svn.automattic.com/wordpress/trunk@18809 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/default-filters.php | 1 - wp-includes/post.php | 22 ++++++---------------- wp-includes/taxonomy.php | 8 +++++++- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 4ebe014e4..f82da2986 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -254,7 +254,6 @@ add_action( 'pre_post_update', 'wp_save_post_revision' add_action( 'publish_post', '_publish_post_hook', 5, 1 ); add_action( 'save_post', '_save_post_hook', 5, 2 ); add_action( 'transition_post_status', '_transition_post_status', 5, 3 ); -add_action( 'transition_post_status', '_update_term_count_on_transition_post_status', 10, 3 ); add_action( 'comment_form', 'wp_comment_form_unfiltered_html_nonce' ); add_action( 'wp_scheduled_delete', 'wp_scheduled_delete' ); add_action( 'admin_init', 'send_frame_options_header', 10, 0 ); diff --git a/wp-includes/post.php b/wp-includes/post.php index 9ebb2fbdc..091ebaccb 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -2727,6 +2727,12 @@ function wp_publish_post($post_id) { $post->post_status = 'publish'; wp_transition_post_status('publish', $old_status, $post); + // Update counts for the post's terms. + foreach ( (array) get_object_taxonomies('post') as $taxonomy ) { + $tt_ids = wp_get_object_terms($post_id, $taxonomy, array('fields' => 'tt_ids')); + wp_update_term_count($tt_ids, $taxonomy); + } + do_action('edit_post', $post_id, $post); do_action('save_post', $post_id, $post); do_action('wp_insert_post', $post_id, $post); @@ -5305,20 +5311,4 @@ function _post_format_wp_get_object_terms( $terms ) { } add_filter( 'wp_get_object_terms', '_post_format_wp_get_object_terms' ); -/** - * 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. - * - * @access private - * @param string $new_status - * @param string $old_status - * @param object $post - * @since 3.3.0 - */ -function _update_term_count_on_transition_post_status( $new_status, $old_status, $post ) { - // Update counts for the post's terms. - foreach ( (array) get_object_taxonomies( $post->post_type ) as $taxonomy ) { - $tt_ids = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'tt_ids' ) ); - wp_update_term_count( $tt_ids, $taxonomy ); - } -} ?> diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 7028ca6ff..e231a6cde 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -2445,7 +2445,13 @@ function wp_update_term_count_now( $terms, $taxonomy ) { call_user_func($taxonomy->update_count_callback, $terms, $taxonomy); } else { // Default count updater - _update_post_term_count( $terms, $taxonomy ); + foreach ( (array) $terms as $term) { + $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term) ); + do_action( 'edit_term_taxonomy', $term, $taxonomy ); + $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) ); + do_action( 'edited_term_taxonomy', $term, $taxonomy ); + } + } clean_term_cache($terms, '', false);