WordPress.org

Making WordPress.org

Changeset 3375


Ignore:
Timestamp:
06/15/2016 05:37:03 AM (5 years ago)
Author:
dd32
Message:

Plugin Directory: Disable Canonical for 404's, this prevents plugin partial matches from redirecting, but also prevents direct url's redirecting to other plugins.

See #1719

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r3343 r3375  
    3131        add_filter( 'pre_update_option_jetpack_options', array( $this, 'filter_jetpack_options' ) );
    3232        add_action( 'template_redirect', array( $this, 'redirect_hidden_plugins' ) );
     33        add_action( 'template_redirect', array( $this, 'prevent_canonical_for_plugins' ), 9 );
    3334
    3435        // Shim in postmeta support for data which doesn't yet live in postmeta
    3536        add_filter( 'get_post_metadata', array( $this, 'filter_shim_postmeta' ), 10, 3 );
    36 
    3737
    3838        add_filter( 'map_meta_cap', array( __NAMESPACE__ . '\Capabilities', 'map_meta_cap' ), 10, 4 );
     
    541541        if ( $post instanceof \WP_Post && in_array( $post->post_status, array( 'disabled', 'closed' ), true ) && current_user_can( 'edit_post', $post ) ) {
    542542            wp_safe_redirect( add_query_arg( array( 'post' => $post->ID, 'action' => 'edit' ), admin_url( 'post.php' ) ) );
     543        }
     544    }
     545
     546    /**
     547     * Prevents Canonical redirecting to other plugins on 404's.
     548     */
     549    function prevent_canonical_for_plugins() {
     550        if ( is_404() ) {
     551            remove_action( 'template_redirect', 'redirect_canonical' );
    543552        }
    544553    }
Note: See TracChangeset for help on using the changeset viewer.