Changeset 10791
- Timestamp:
- 05/19/2016 06:04:47 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-catchuri.php
r10714 r10791 534 534 } 535 535 } 536 537 /** 538 * Members user shortlink redirector. 539 * 540 * Redirects x.com/members/me/* to x.com/members/{LOGGED_IN_USER_SLUG}/* 541 * 542 * @since 2.6.0 543 * 544 * @param string $member_slug The current member slug. 545 */ 546 function bp_core_members_shortlink_redirector( $member_slug ) { 547 /** 548 * Shortlink slug to redirect to logged-in user. 549 * 550 * x.com/members/me/* will redirect to x.com/members/{LOGGED_IN_USER_SLUG}/* 551 * 552 * @since 2.6.0 553 * 554 * @var string $slug Defaults to 'me'. 555 */ 556 $me_slug = apply_filters( 'bp_core_members_shortlink_slug', 'me' ); 557 558 // Check if we're on our special shortlink slug. If not, bail. 559 if ( $me_slug !== $member_slug ) { 560 return $member_slug; 561 } 562 563 // If logged out, redirect user to login. 564 if ( false === is_user_logged_in() ) { 565 // Add our login redirector hook. 566 add_action( 'template_redirect', 'bp_core_no_access', 0 ); 567 568 return $member_slug; 569 } 570 571 $user = wp_get_current_user(); 572 573 return bp_core_get_username( $user->ID, $user->user_nicename, $user->user_login ); 574 } 575 add_filter( 'bp_core_set_uri_globals_member_slug', 'bp_core_members_shortlink_redirector' ); 536 576 537 577 /** -
trunk/tests/phpunit/testcases/routing/members.php
r9914 r10791 109 109 $this->assertTrue( is_404() ); 110 110 } 111 112 /** 113 * @ticket BP6325 114 */ 115 function test_members_shortlink_redirector() { 116 $shortlink_member_slug = 'me'; 117 118 $this->go_to( bp_get_members_directory_permalink() . $shortlink_member_slug ); 119 120 $this->assertSame( get_current_user_id(), bp_displayed_user_id() ); 121 } 111 122 }
Note: See TracChangeset
for help on using the changeset viewer.