Making WordPress.org

Changeset 3376


Ignore:
Timestamp:
06/15/2016 06:07:50 AM (8 years ago)
Author:
dd32
Message:

Plugin Directory: Handle various redirects we need

  • /$plugin/faq (the old plugin tabs) should redirect to /$plugin/#faq
  • /browse/ should have something on it, we're going with the popular view by default.
  • /browse/favorites/$user should list that users favourites.

See #1584 #1719

File:
1 edited

Legend:

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

    r3375 r3376  
    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' ) );
     35        add_filter( 'query_vars', array( $this, 'filter_query_vars' ) );
    3436
    3537        // Shim in postmeta support for data which doesn't yet live in postmeta
     
    204206
    205207        // Add the browse/* views.
    206         // TODO: browse/favorites/$user
    207208        add_rewrite_tag( '%browse%', '(featured|popular|beta|new|favorites)' );
    208209        add_permastruct( 'browse', 'browse/%browse%' );
     210
     211        // /browse/ should be the popular archive view.
     212        add_rewrite_rule( '^browse$', 'index.php?browse=popular', 'top' );
     213        // Create an archive for a users favorites too.
     214        add_rewrite_rule( '^browse/favorites/([^/]+)$', 'index.php?browse=favorites&favorites_user=$matches[1]', 'top' );
     215
     216        // Handle the old plugin tabs URLs
     217        add_rewrite_rule( '^([^/]+)/(installation|faq|screenshots|changelog|stats|developers|other_notes)$', 'index.php?redirect_plugin_tab=$matches[1]/#$matches[2]', 'top' );
    209218
    210219        // If changing capabilities around, uncomment this.
     
    517526
    518527    /**
     528     * Filters the available public query vars to add our custom parameters.
     529     */
     530    public function filter_query_vars( $vars ) {
     531        $vars[] = 'favorites_user';
     532        $vars[] = 'redirect_plugin_tab';
     533        return $vars;
     534    }
     535
     536    /**
    519537     * Filter for pre_update_option_jetpack_options to ensure CPT posts are seen as public and searchable by TP
    520538     *
     
    541559        if ( $post instanceof \WP_Post && in_array( $post->post_status, array( 'disabled', 'closed' ), true ) && current_user_can( 'edit_post', $post ) ) {
    542560            wp_safe_redirect( add_query_arg( array( 'post' => $post->ID, 'action' => 'edit' ), admin_url( 'post.php' ) ) );
     561            die();
    543562        }
    544563    }
     
    550569        if ( is_404() ) {
    551570            remove_action( 'template_redirect', 'redirect_canonical' );
     571        }
     572    }
     573
     574    /**
     575     * Handles a redirect for the old /$plugin/$tab_name/ URLs
     576     */
     577    function redirect_old_plugin_tabs() {
     578        if ( get_query_var( 'redirect_plugin_tab' ) ) {
     579            wp_safe_redirect( site_url( get_query_var( 'redirect_plugin_tab' ) ) );
     580            die();
    552581        }
    553582    }
Note: See TracChangeset for help on using the changeset viewer.