Skip to:
Content

BuddyPress.org

Ticket #6325: 6325.02.patch

File 6325.02.patch, 1.6 KB (added by r-a-y, 9 years ago)
  • src/bp-core/bp-core-catchuri.php

    diff --git src/bp-core/bp-core-catchuri.php src/bp-core/bp-core-catchuri.php
    index ada5bf9..49b2049 100644
    function bp_core_catch_profile_uri() { 
    517517}
    518518
    519519/**
     520 * Members user shortlink redirector.
     521 *
     522 * Redirects x.com/members/me/* to x.com/members/{LOGGED_IN_USER_SLUG}/*
     523 *
     524 * @since 2.6.0
     525 *
     526 * @param string $member_slug The current member slug.
     527 */
     528function bp_core_members_shortlink_redirector( $member_slug ) {
     529        /**
     530         * Shortlink slug to redirect to logged-in user.
     531         *
     532         * x.com/members/me/* will redirect to x.com/members/{LOGGED_IN_USER_SLUG}/*
     533         *
     534         * @since 2.6.0
     535         *
     536         * @var string $slug Defaults to 'me'.
     537         */
     538        $me_slug = apply_filters( 'bp_core_members_shortlink_slug', 'me' );
     539
     540        // Check if we're on our special shortlink slug. If not, bail.
     541        if ( $me_slug !== $member_slug ) {
     542                return $member_slug;
     543        }
     544
     545        // If logged out, redirect user to login.
     546        if ( false === is_user_logged_in() ) {
     547                // Create anonymous function to perform redirect on the 'bp_template_redirect' hook.
     548                $do_redirect = create_function( '', "
     549                        bp_core_no_access();
     550                        exit();
     551                " );
     552
     553                add_action( 'bp_template_redirect', $do_redirect, 0 );
     554                return $member_slug;
     555        }
     556
     557        $user = wp_get_current_user();
     558
     559        return bp_core_get_username( $user->ID, $user->user_nicename, $user->user_login );
     560}
     561add_filter( 'bp_core_set_uri_globals_member_slug', 'bp_core_members_shortlink_redirector' );
     562
     563/**
    520564 * Catch unauthorized access to certain BuddyPress pages and redirect accordingly.
    521565 *
    522566 * @since 1.5.0