WordPress.org

Make WordPress Core

Ticket #23074: combined.2.patch

File combined.2.patch, 2.2 KB (added by kitchin, 7 years ago)

maintains data correctly

  • wp-includes/post.php

     
    45204520 * @return int Same as $post_id
    45214521 */
    45224522function wp_check_for_changed_slugs($post_id, $post, $post_before) {
    4523         // dont bother if it hasnt changed
     4523        if ( empty( $post_before->post_name ) )
     4524                return;
     4525
     4526        $old_slugs = (array) get_post_meta($post_id, '_wp_old_slug');
     4527
     4528        // if the new slug was used previously, delete it from the list
     4529        if ( in_array($post->post_name, $old_slugs) )
     4530                delete_post_meta($post_id, '_wp_old_slug', $post->post_name);
     4531
     4532        // don't bother if it hasn't changed
    45244533        if ( $post->post_name == $post_before->post_name )
    45254534                return;
    45264535
     
    45284537        if ( $post->post_status != 'publish' || is_post_type_hierarchical( $post->post_type ) )
    45294538                return;
    45304539
    4531         $old_slugs = (array) get_post_meta($post_id, '_wp_old_slug');
    4532 
    45334540        // if we haven't added this old slug before, add it now
    4534         if ( !empty( $post_before->post_name ) && !in_array($post_before->post_name, $old_slugs) )
     4541        if ( !in_array($post_before->post_name, $old_slugs) )
    45354542                add_post_meta($post_id, '_wp_old_slug', $post_before->post_name);
    4536 
    4537         // if the new slug was used previously, delete it from the list
    4538         if ( in_array($post->post_name, $old_slugs) )
    4539                 delete_post_meta($post_id, '_wp_old_slug', $post->post_name);
    45404543}
    45414544
    45424545/**
  • wp-includes/query.php

     
    39233923
    39243924                $query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_slug' AND meta_value = %s", $post_type, $wp_query->query_vars['name']);
    39253925
     3926                // Prevent a simple redirect loop due to values in '_wp_old_slug' not deleted
     3927                // when in an unpublished status (only in legacy data).
     3928                $query .= $wpdb->prepare(" AND post_name != %s", $wp_query->query_vars['name']);
     3929
    39263930                // if year, monthnum, or day have been specified, make our query more precise
    39273931                // just in case there are multiple identical _wp_old_slug values
    39283932                if ( '' != $wp_query->query_vars['year'] )