Make WordPress Core


Ignore:
Timestamp:
11/21/2014 03:16:08 AM (9 years ago)
Author:
boonebgorges
Message:

Improve cleanup of cached term_ids after shared terms are split.

  • If the split term ID is stored as 'default_category', 'default_link_category', or 'default_email_category', update it to the new ID.
  • If the split term ID is associated with a nav menu item, update that piece of postmeta to the new ID.

Props mboynes.
See #30335.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r30493 r30494  
    41374137
    41384138/**
     4139 * Check default categories when a term gets split to see if any of them need
     4140 * to be updated.
     4141 *
     4142 * @since 4.1.0
     4143 * @access private
     4144 *
     4145 * @param int    $term_id          ID of the formerly shared term.
     4146 * @param int    $new_term_id      ID of the new term created for the $term_taxonomy_id.
     4147 * @param int    $term_taxonomy_id ID for the term_taxonomy row affected by the split.
     4148 * @param string $taxonomy         Taxonomy for the split term.
     4149 */
     4150function _wp_check_split_default_terms( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) {
     4151    if ( 'category' == $taxonomy ) {
     4152        foreach ( array( 'default_category', 'default_link_category', 'default_email_category' ) as $option ) {
     4153            if ( $term_id == get_option( $option, -1 ) ) {
     4154                update_option( $option, $new_term_id );
     4155            }
     4156        }
     4157    }
     4158}
     4159
     4160/**
     4161 * Check menu items when a term gets split to see if any of them need to be
     4162 * updated.
     4163 *
     4164 * @since 4.1.0
     4165 * @access private
     4166 *
     4167 * @param int    $term_id          ID of the formerly shared term.
     4168 * @param int    $new_term_id      ID of the new term created for the $term_taxonomy_id.
     4169 * @param int    $term_taxonomy_id ID for the term_taxonomy row affected by the split.
     4170 * @param string $taxonomy         Taxonomy for the split term.
     4171 */
     4172function _wp_check_split_terms_in_menus( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) {
     4173    global $wpdb;
     4174    $post_ids = $wpdb->get_col( $wpdb->prepare(
     4175        "SELECT m1.post_id
     4176        FROM {$wpdb->postmeta} AS m1
     4177            INNER JOIN {$wpdb->postmeta} AS m2 ON m2.post_id=m1.post_id
     4178            INNER JOIN {$wpdb->postmeta} AS m3 ON m3.post_id=m1.post_id
     4179        WHERE ( m1.meta_key = '_menu_item_type' AND m1.meta_value = 'taxonomy' )
     4180            AND ( m2.meta_key = '_menu_item_object' AND m2.meta_value = '%s' )
     4181            AND ( m3.meta_key = '_menu_item_object_id' AND m3.meta_value = %d )",
     4182        $taxonomy,
     4183        $term_id
     4184    ) );
     4185
     4186    if ( $post_ids ) {
     4187        foreach ( $post_ids as $post_id ) {
     4188            update_post_meta( $post_id, '_menu_item_object_id', $new_term_id, $term_id );
     4189        }
     4190    }
     4191}
     4192
     4193/**
    41394194 * Generate a permalink for a taxonomy term archive.
    41404195 *
Note: See TracChangeset for help on using the changeset viewer.