Making WordPress.org


Ignore:
Timestamp:
04/04/2014 12:39:30 PM (12 years ago)
Author:
johnjamesjacoby
Message:

BuddyPress.org: Update bporg_redirect():

  • Only run on buddypress.org root site.
  • Update rules for removal of community page hierarchy.
  • Ensure single member pages redirect correctly.
  • Add braces and inline doc, for clarity of intent.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/buddypress.org/public_html/wp-content/plugins/buddypress-org/extensions.php

    r447 r499  
    7777/** Other Functions ***********************************************************/
    7878
     79/**
     80 * Function (hooked to 'init') to handle redirect logic from various rearranged
     81 * BuddyPress.org root site page locations.
     82 *
     83 * @author johnjamesjacoby
     84 * @return if not BuddyPress.org root site
     85 */
    7986function bporg_redirect() {
     87
     88        // Explode the request (could use parse_url() here too)
    8089        $uri_chunks = explode( '/', $_SERVER['REQUEST_URI'] );
    8190
    8291        // Redirect /forums/ to /support/
    83         if ( $uri_chunks[1] == 'forums' && empty( $uri_chunks[2] ) )
     92        if ( $uri_chunks[1] === 'forums' && empty( $uri_chunks[2] ) ) {
    8493                bp_core_redirect( 'http://buddypress.org/support/' );
     94        }
    8595
    8696        // Redirect members directory to root to block heavy paginated user queries
    87         if ( ( $uri_chunks[1] == 'members' ) || ( $uri_chunks[1] == 'community' && $uri_chunks[2] == 'members' && empty( $uri_chunks[3] ) ) )
     97        if ( ( $uri_chunks[1] === 'members' ) && empty( $uri_chunks[2] ) ) {
    8898                bp_core_redirect( 'http://buddypress.org' );
    89 
    90         // Redirect members directory to root to block heavy paginated user queries
    91         if ( $uri_chunks[1] == 'community' && $uri_chunks[2] == 'groups' ) {
    92 
    93                 if ( !empty( $uri_chunks[5] ) && ( $uri_chunks[5] == 'topic' ) ) {
     99        }
     100
     101        // Redirect old members profile pages to
     102        if ( ( $uri_chunks[1] === 'community' ) && ( $uri_chunks[2] === 'members' ) && ! empty( $uri_chunks[3] ) ) {
     103                bp_core_redirect( 'http://buddypress.org/members/' . $uri_chunks[3] . '/' );
     104        }
     105
     106        // Redirect old plugin groups to deprecated plugin forums
     107        if ( ( $uri_chunks[1] === 'community' ) && ( $uri_chunks[2] === 'groups' ) ) {
     108
     109                // Single group topic redirect
     110                if ( !empty( $uri_chunks[5] ) && ( $uri_chunks[5] === 'topic' ) ) {
    94111                        bp_core_redirect( 'http://buddypress.org/support/topic/' . $uri_chunks[6] . '/' );
    95112
    96                 } elseif ( empty( $uri_chunks[4] ) || ( $uri_chunks[4] == 'forum' ) ) {
     113                // Single group forum redirect
     114                } elseif ( empty( $uri_chunks[4] ) || ( $uri_chunks[4] === 'forum' ) ) {
    97115
    98116                        // Use legacy group slug
     
    103121                        } else {
    104122
    105                                 // New forums locations
     123                                // New BuddyPress project forums locations
    106124                                switch ( $uri_chunks[3] ) {
    107125                                        case 'gallery' :
     
    133151
    134152        // Redirect /support/topics/ to /support/
    135         if ( $uri_chunks[1] == 'support' && ( !empty( $uri_chunks[2] ) && ( 'topics' == $uri_chunks[2] ) ) )
     153        if ( $uri_chunks[1] === 'support' && ( !empty( $uri_chunks[2] ) && ( 'topics' === $uri_chunks[2] ) ) ) {
    136154                bp_core_redirect( 'http://buddypress.org/support/' );
    137 
    138         // Redirect /members/ to /community/members/
    139         if ( $uri_chunks[1] == 'members' && !empty( $uri_chunks[2] ) )
    140                 bp_core_redirect( 'http://buddypress.org/community/members/' . strtolower( $uri_chunks[2] ) . '/' );
    141 }
    142 add_action( 'init', 'bporg_redirect' );
     155        }
     156}
     157if ( 'buddypress.org' === $_SERVER['HTTP_HOST'] && ! is_admin() && defined( 'WP_USE_THEMES' ) && WP_USE_THEMES ) {
     158        add_action( 'init', 'bporg_redirect', 1 ); // before bp_init
     159}
    143160
    144161function wporg_profiles_redirect() {
    145162        $uri_chunks = explode( '/', trim( $_SERVER['REQUEST_URI'], '/' ) );
    146163        if ( 'users' == $uri_chunks[0] ) {
    147                 if ( ! empty( $uri_chunks[1] ) )
     164                if ( ! empty( $uri_chunks[1] ) ) {
    148165                        wp_redirect( 'http://profiles.wordpress.org/' . $uri_chunks[1] . '/', 301 );
    149                 else
     166                } else {
    150167                        wp_redirect( 'http://wordpress.org/' );
     168                }
    151169                exit;
    152170        }
    153171
    154         if ( get_user_by( 'slug', $uri_chunks[0] ) )
     172        if ( get_user_by( 'slug', $uri_chunks[0] ) ) {
    155173                return;
     174        }
     175
    156176        if ( $user = get_user_by( 'login', urldecode( $uri_chunks[0] ) ) ) {
    157177                wp_redirect( 'http://profiles.wordpress.org/' . $user->user_nicename . '/', 301 );
     
    167187
    168188function wporg_profiles_maybe_template_redirect() {
    169         if ( is_robots() || is_feed() || is_trackback() )
     189        if ( is_robots() || is_feed() || is_trackback() ) {
    170190                return;
     191        }
    171192
    172193        ob_start();
Note: See TracChangeset for help on using the changeset viewer.