diff --git src/wp-includes/default-filters.php src/wp-includes/default-filters.php
index c50a9d9..6897c2e 100644
|
|
add_action( 'begin_fetch_post_thumbnail_html', '_wp_post_thumbnail_class_filter_ |
294 | 294 | add_action( 'end_fetch_post_thumbnail_html', '_wp_post_thumbnail_class_filter_remove' ); |
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 |
301 | 302 | add_action( 'init', '_show_post_preview' ); |
diff --git src/wp-includes/post-functions.php src/wp-includes/post-functions.php
index 47db1df..0d0a99c 100644
|
|
function _post_type_meta_capabilities( $capabilities = null ) { |
1330 | 1330 | * @since 4.3.0 Added the `featured_image`, `set_featured_image`, `remove_featured_image`, |
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 | * |
1336 | 1336 | * @param object $post_type_object Post type object. |
… |
… |
function wp_insert_post( $postarr, $wp_error = false ) { |
3280 | 3280 | * @param int $post_ID Attachment ID. |
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 | |
3285 | 3297 | /** |
… |
… |
function wp_mime_type_icon( $mime = 0 ) { |
5134 | 5146 | */ |
5135 | 5147 | function wp_check_for_changed_slugs( $post_id, $post, $post_before ) { |
5136 | 5148 | // Don't bother if it hasnt changed. |
5137 | | if ( $post->post_name == $post_before->post_name ) |
| 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 ( ! in_array($post->post_status, array( 'publish', 'inherit' ) ) || is_post_type_hierarchical( $post->post_type ) ) { |
5142 | 5155 | return; |
| 5156 | } |
5143 | 5157 | |
5144 | 5158 | $old_slugs = (array) get_post_meta($post_id, '_wp_old_slug'); |
5145 | 5159 | |
diff --git src/wp-includes/query.php src/wp-includes/query.php
index 28cf56f..cc48edd 100644
|
|
function wp_old_slug_redirect() { |
4736 | 4736 | global $wpdb; |
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 | | else |
| 4745 | } else { |
4744 | 4746 | $post_type = 'post'; |
| 4747 | } |
4745 | 4748 | |
4746 | 4749 | if ( is_array( $post_type ) ) { |
4747 | 4750 | if ( count( $post_type ) > 1 ) |
diff --git tests/phpunit/tests/rewrite/oldSlugRedirect.php tests/phpunit/tests/rewrite/oldSlugRedirect.php
index a166d43..5e8cdda 100644
|
|
class Tests_Rewrite_OldSlugRedirect extends WP_UnitTestCase { |
121 | 121 | wp_old_slug_redirect(); |
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 | |
126 | 139 | public function test_old_slug_redirect_paged() { |