WordPress.org

Make WordPress Core

Ticket #23074: combined.patch

File combined.patch, 2.6 KB (added by kitchin, 8 years ago)

Combine the minimal patch with the post patch and update the comment (to "legacy data")

  • 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
    4524         if ( $post->post_name == $post_before->post_name )
    4525                 return;
     4523        $old_slugs = (array) get_post_meta($post_id, '_wp_old_slug');
    45264524
    45274525        // we're only concerned with published, non-hierarchical objects
    4528         if ( $post->post_status != 'publish' || is_post_type_hierarchical( $post->post_type ) )
     4526        if ( $post->post_status != 'publish' || is_post_type_hierarchical( $post->post_type ) ) {
     4527                // Delete any values in '_wp_old_slug' added when it was published and non-hierarchical.
     4528                // Note this means cycling a post from Published to Private to Published will delete old slugs.
     4529                if ($old_slugs)
     4530                        delete_post_meta($post_id, '_wp_old_slug');
    45294531                return;
     4532        }
    45304533
    4531         $old_slugs = (array) get_post_meta($post_id, '_wp_old_slug');
     4534        // don't bother if it hasn't changed
     4535        if ( $post->post_name != $post_before->post_name )
     4536                // if we haven't added this old slug before, add it now
     4537                if ( !empty( $post_before->post_name ) && !in_array($post_before->post_name, $old_slugs) )
     4538                        add_post_meta($post_id, '_wp_old_slug', $post_before->post_name);
    45324539
    4533         // 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) )
    4535                 add_post_meta($post_id, '_wp_old_slug', $post_before->post_name);
    4536 
    45374540        // if the new slug was used previously, delete it from the list
    45384541        if ( in_array($post->post_name, $old_slugs) )
    45394542                delete_post_meta($post_id, '_wp_old_slug', $post->post_name);
  • 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 (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'] )