Changeset 49451 for trunk/src/wp-includes/post.php
- Timestamp:
- 10/30/2020 04:57:16 AM (6 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/post.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r49328 r49451 4075 4075 } 4076 4076 4077 // Allow term counts to be handled by transitioning post type.4078 _wp_prevent_term_counting( true );4079 4077 if ( is_object_in_taxonomy( $post_type, 'category' ) ) { 4080 4078 wp_set_post_categories( $post_ID, $post_category ); … … 4133 4131 } 4134 4132 } 4135 // Restore term counting.4136 _wp_prevent_term_counting( false );4137 4133 4138 4134 if ( ! empty( $postarr['meta_input'] ) ) { … … 4451 4447 continue; 4452 4448 } 4453 _wp_prevent_term_counting( true );4454 4449 wp_set_post_terms( $post->ID, array( $default_term_id ), $taxonomy ); 4455 _wp_prevent_term_counting( false );4456 4450 } 4457 4451 … … 7361 7355 */ 7362 7356 function _update_term_count_on_transition_post_status( $new_status, $old_status, $post ) { 7363 if ( 'inherit' === $new_status ) { 7364 $new_status = get_post_status( $post->post_parent ); 7365 } 7366 7367 if ( 'inherit' === $old_status ) { 7368 $old_status = get_post_status( $post->post_parent ); 7369 } 7370 7371 $count_new = 'publish' === $new_status; 7372 $count_old = 'publish' === $old_status; 7373 7374 if ( $count_new === $count_old ) { 7375 // Nothing to do. 7376 return; 7377 } 7378 7379 /* 7380 * Update counts for the post's terms. 7381 * 7382 * Term counting is deferred while incrementing/decrementing the counts to 7383 * reduce the number of database queries required. Once the counts are 7384 * complete the updates are performed if term counting wasn't previously 7385 * deferred. 7386 */ 7387 $previous_deferred_setting = wp_defer_term_counting(); 7388 wp_defer_term_counting( true ); 7357 // Update counts for the post's terms. 7389 7358 foreach ( (array) get_object_taxonomies( $post->post_type ) as $taxonomy ) { 7390 7359 $tt_ids = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'tt_ids' ) ); 7391 7392 if ( empty( $tt_ids ) ) { 7393 // No terms for this taxonomy on object. 7394 continue; 7395 } 7396 7397 $object_types = (array) get_taxonomy( $taxonomy )->object_type; 7398 7399 foreach ( $object_types as &$object_type ) { 7400 list( $object_type ) = explode( ':', $object_type ); 7401 } 7402 7403 $object_types = array_unique( $object_types ); 7404 7405 if ( ! in_array( $post->post_type, $object_types, true ) ) { 7406 $modify_by = 0; 7407 } elseif ( $count_new && ! $count_old ) { 7408 $modify_by = 1; 7409 } elseif ( $count_old && ! $count_new ) { 7410 $modify_by = -1; 7411 } 7412 7413 if ( 'attachment' === $post->post_type ) { 7414 wp_modify_term_count_by( $tt_ids, $taxonomy, $modify_by ); 7415 continue; 7416 } 7417 7418 $check_attachments = array_search( 'attachment', $object_types, true ); 7419 if ( false !== $check_attachments ) { 7420 unset( $object_types[ $check_attachments ] ); 7421 $check_attachments = true; 7422 } 7423 7424 wp_modify_term_count_by( $tt_ids, $taxonomy, $modify_by ); 7425 if ( ! $check_attachments ) { 7426 continue; 7427 } 7428 7429 /* 7430 * For non-attachments, check if there are any attachment children 7431 * with 'inherited' post status -- if so those will need to be counted. 7432 */ 7433 $attachments = get_children( 7434 array( 7435 'post_parent' => $post->ID, 7436 'post_status' => 'inherit', 7437 'post_type' => 'attachment', 7438 'update_post_meta_cache' => false, 7439 'update_post_term_cache' => true, 7440 ) 7441 ); 7442 7443 foreach ( $attachments as $attachment ) { 7444 _update_term_count_on_transition_post_status( $new_status, $old_status, $attachment ); 7445 } 7446 } 7447 wp_defer_term_counting( $previous_deferred_setting ); 7360 wp_update_term_count( $tt_ids, $taxonomy ); 7361 } 7448 7362 } 7449 7363
Note: See TracChangeset
for help on using the changeset viewer.