Make WordPress Core


Ignore:
Timestamp:
09/29/2015 04:57:02 AM (11 years ago)
Author:
pento
Message:

Rewrite: Redirect attachment URLs when their slug changes.

Using the same logic that we use to redirect posts when their slug changes, we can provide the same functionality for attachments. Attachment pages are posts, too.

Props swissspdy.

Fixes #34043.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rewrite/oldSlugRedirect.php

    r34659 r34685  
    122122                $this->assertNull( $this->old_slug_redirect_url );
    123123                $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 );
    124137        }
    125138
Note: See TracChangeset for help on using the changeset viewer.