Making WordPress.org

Changeset 3377


Ignore:
Timestamp:
06/15/2016 06:54:47 AM (6 years ago)
Author:
dd32
Message:

Plugin Directory: Add redirect handling for /%plugin%/random_data()/ as well as /%plugin%/%tabname%/

See r3376 #1584 #1719

File:
1 edited

Legend:

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

    r3376 r3377  
    3232        add_action( 'template_redirect', array( $this, 'redirect_hidden_plugins' ) );
    3333        add_action( 'template_redirect', array( $this, 'prevent_canonical_for_plugins' ), 9 );
    34         add_action( 'template_redirect', array( $this, 'redirect_old_plugin_tabs' ) );
     34        add_action( 'template_redirect', array( $this, 'redirect_old_plugin_urls' ) );
    3535        add_filter( 'query_vars', array( $this, 'filter_query_vars' ) );
    3636
     
    573573
    574574    /**
    575      * Handles a redirect for the old /$plugin/$tab_name/ URLs
    576      */
    577     function redirect_old_plugin_tabs() {
     575     * Handles a redirect for the old /$plugin/$tab_name/ URLs and search.php
     576     */
     577    function redirect_old_plugin_urls() {
     578        // Handle a redirect for /$plugin/$tab_name/ to /$plugin/#$tab_name
    578579        if ( get_query_var( 'redirect_plugin_tab' ) ) {
    579580            wp_safe_redirect( site_url( get_query_var( 'redirect_plugin_tab' ) ) );
     581            die();
     582        }
     583
     584        // We don't have attachments, but /$plugin/random() will hit this check.
     585        if ( is_404() ) {
     586            // [1] => plugins [2] => example-plugin-name [2..] => random()
     587            $plugin_slug = explode( '/', $_SERVER['REQUEST_URI'] )[2];
     588            if ( $plugin = self::get_plugin_post( $plugin_slug ) ) {
     589                wp_safe_redirect( get_permalink( $plugin->ID ) );
     590                die();
     591            }
     592        }
     593
     594        // If it's an old search query, handle that too.
     595        if ( 'search.php' == get_query_var( 'name' ) && isset( $_GET['q'] ) ) {
     596            wp_safe_redirect( site_url( '/search/' . urlencode( wp_unslash( $_GET['q'] ) ) . '/' ) );
    580597            die();
    581598        }
Note: See TracChangeset for help on using the changeset viewer.