WordPress.org

Make WordPress Core

Ticket #34043: 34043.diff

File 34043.diff, 4.4 KB (added by swissspidy, 4 years ago)
  • src/wp-includes/default-filters.php

    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_ 
    294294add_action( 'end_fetch_post_thumbnail_html',   '_wp_post_thumbnail_class_filter_remove' );
    295295
    296296// Redirect Old Slugs
    297 add_action( 'template_redirect', 'wp_old_slug_redirect'              );
    298 add_action( 'post_updated',      'wp_check_for_changed_slugs', 12, 3 );
     297add_action( 'template_redirect',  'wp_old_slug_redirect'              );
     298add_action( 'post_updated',       'wp_check_for_changed_slugs', 12, 3 );
     299add_action( 'attachment_updated', 'wp_check_for_changed_slugs', 12, 3 );
    299300
    300301// Nonce check for Post Previews
    301302add_action( 'init', '_show_post_preview' );
  • src/wp-includes/post-functions.php

    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 ) { 
    13301330 * @since 4.3.0 Added the `featured_image`, `set_featured_image`, `remove_featured_image`,
    13311331 *              and `use_featured_image` labels.
    13321332 * @since 4.4.0 Added the `insert_into_item` and `uploaded_to_this_item` labels.
    1333  * 
     1333 *
    13341334 * @access private
    13351335 *
    13361336 * @param object $post_type_object Post type object.
    function wp_insert_post( $postarr, $wp_error = false ) { 
    32803280                         * @param int $post_ID Attachment ID.
    32813281                         */
    32823282                        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);
    32833295                } else {
    32843296
    32853297                        /**
    function wp_mime_type_icon( $mime = 0 ) { 
    51345146 */
    51355147function wp_check_for_changed_slugs( $post_id, $post, $post_before ) {
    51365148        // 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 ) {
    51385150                return;
     5151        }
    51395152
    51405153        // 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 ) ) {
    51425155                return;
     5156        }
    51435157
    51445158        $old_slugs = (array) get_post_meta($post_id, '_wp_old_slug');
    51455159
  • src/wp-includes/query.php

    diff --git src/wp-includes/query.php src/wp-includes/query.php
    index 28cf56f..cc48edd 100644
    function wp_old_slug_redirect() { 
    47364736                global $wpdb;
    47374737
    47384738                // 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'] ) ) {
    47424744                        $post_type = 'page';
    4743                 else
     4745                } else {
    47444746                        $post_type = 'post';
     4747                }
    47454748
    47464749                if ( is_array( $post_type ) ) {
    47474750                        if ( count( $post_type ) > 1 )
  • tests/phpunit/tests/rewrite/oldSlugRedirect.php

    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 { 
    121121                wp_old_slug_redirect();
    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
    126139        public function test_old_slug_redirect_paged() {