Changeset 34685
- Timestamp:
- 09/29/2015 04:57:02 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/default-filters.php
r34561 r34685 295 295 296 296 // Redirect Old Slugs 297 add_action( 'template_redirect', 'wp_old_slug_redirect' ); 298 add_action( 'post_updated', 'wp_check_for_changed_slugs', 12, 3 ); 297 add_action( 'template_redirect', 'wp_old_slug_redirect' ); 298 add_action( 'post_updated', 'wp_check_for_changed_slugs', 12, 3 ); 299 add_action( 'attachment_updated', 'wp_check_for_changed_slugs', 12, 3 ); 299 300 300 301 // Nonce check for Post Previews -
trunk/src/wp-includes/post-functions.php
r34668 r34685 1331 1331 * and `use_featured_image` labels. 1332 1332 * @since 4.4.0 Added the `insert_into_item` and `uploaded_to_this_item` labels. 1333 * 1333 * 1334 1334 * @access private 1335 1335 * … … 3281 3281 */ 3282 3282 do_action( 'edit_attachment', $post_ID ); 3283 $post_after = get_post( $post_ID ); 3284 3285 /** 3286 * Fires once an existing attachment has been updated. 3287 * 3288 * @since 4.4.0 3289 * 3290 * @param int $post_ID Post ID. 3291 * @param WP_Post $post_after Post object following the update. 3292 * @param WP_Post $post_before Post object before the update. 3293 */ 3294 do_action( 'attachment_updated', $post_ID, $post_after, $post_before ); 3283 3295 } else { 3284 3296 … … 5134 5146 */ 5135 5147 function wp_check_for_changed_slugs( $post_id, $post, $post_before ) { 5136 // Don't bother if it hasn t changed.5137 if ( $post->post_name == $post_before->post_name ) 5148 // Don't bother if it hasn't changed. 5149 if ( $post->post_name == $post_before->post_name ) { 5138 5150 return; 5151 } 5139 5152 5140 5153 // We're only concerned with published, non-hierarchical objects. 5141 if ( $post->post_status != 'publish' || is_post_type_hierarchical( $post->post_type ) )5154 if ( ! ( 'publish' === $post->post_status || ( 'attachment' === get_post_type( $post ) && 'inherit' === $post->post_status ) ) || is_post_type_hierarchical( $post->post_type ) ) { 5142 5155 return; 5143 5144 $old_slugs = (array) get_post_meta($post_id, '_wp_old_slug'); 5156 } 5157 5158 $old_slugs = (array) get_post_meta( $post_id, '_wp_old_slug' ); 5145 5159 5146 5160 // If we haven't added this old slug before, add it now. 5147 if ( !empty( $post_before->post_name ) && !in_array($post_before->post_name, $old_slugs) ) 5148 add_post_meta($post_id, '_wp_old_slug', $post_before->post_name); 5161 if ( ! empty( $post_before->post_name ) && ! in_array( $post_before->post_name, $old_slugs ) ) { 5162 add_post_meta( $post_id, '_wp_old_slug', $post_before->post_name ); 5163 } 5149 5164 5150 5165 // If the new slug was used previously, delete it from the list. 5151 if ( in_array($post->post_name, $old_slugs) ) 5152 delete_post_meta($post_id, '_wp_old_slug', $post->post_name); 5166 if ( in_array( $post->post_name, $old_slugs ) ) { 5167 delete_post_meta( $post_id, '_wp_old_slug', $post->post_name ); 5168 } 5153 5169 } 5154 5170 -
trunk/src/wp-includes/query.php
r34659 r34685 4737 4737 4738 4738 // Guess the current post_type based on the query vars. 4739 if ( get_query_var('post_type') ) 4740 $post_type = get_query_var('post_type'); 4741 elseif ( !empty($wp_query->query_vars['pagename']) ) 4739 if ( get_query_var( 'post_type' ) ) { 4740 $post_type = get_query_var( 'post_type' ); 4741 } elseif ( get_query_var( 'attachment' ) ) { 4742 $post_type = 'attachment'; 4743 } elseif ( ! empty( $wp_query->query_vars['pagename'] ) ) { 4742 4744 $post_type = 'page'; 4743 else4745 } else { 4744 4746 $post_type = 'post'; 4747 } 4745 4748 4746 4749 if ( is_array( $post_type ) ) { -
trunk/tests/phpunit/tests/rewrite/oldSlugRedirect.php
r34659 r34685 122 122 $this->assertNull( $this->old_slug_redirect_url ); 123 123 $this->assertQueryTrue( 'is_attachment', 'is_singular', 'is_single' ); 124 125 $old_permalink = get_attachment_link( $attachment_id ); 126 127 wp_update_post( array( 128 'ID' => $attachment_id, 129 'post_name' => 'the-attachment', 130 ) ); 131 132 $permalink = user_trailingslashit( trailingslashit( get_permalink( $this->post_id ) ) . 'the-attachment' ); 133 134 $this->go_to( $old_permalink ); 135 wp_old_slug_redirect(); 136 $this->assertEquals( $permalink, $this->old_slug_redirect_url ); 124 137 } 125 138
Note: See TracChangeset
for help on using the changeset viewer.