Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/07/2023 04:28:08 AM (14 months ago)
Author:
imath
Message:

BP Rewrites: Introduce the bp_members_get_user_url() function

As many member URLs are built concatenating bp_core_get_user_domain()
with URL chunks, the safer way to make sure developers update the way they
build their member URLs in favor of using BP Rewrites is:

  1. to deprecate this function
  2. create a new function bp_members_get_user_url() which is a wrapper of

bp_rewrites_get_url()

  1. replace all bp_core_get_user_domain() occurrences by

bp_members_get_user_url()

This commit also deprecates bp_core_get_username() in favor of the new
bp_members_get_user_slug() function and updates PHPUnit tests.

Props r-a-y, johnjamesjacoby, boonebgorges

Closes https://github.com/buddypress/buddypress/pull/70
See #4954

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/core/nav/bpCoreMaybeHookNewSubnavScreenFunction.php

    r11737 r13433  
    55 */
    66class BP_Tests_Core_Nav_BpCoreMaybeHookNewSubnavScreenFunction extends BP_UnitTestCase {
     7    protected $permalink_structure = '';
     8
     9    public function set_up() {
     10        parent::set_up();
     11        $this->permalink_structure = get_option( 'permalink_structure', '' );
     12    }
     13
     14    public function tear_down() {
     15        $this->set_permalink_structure( $this->permalink_structure );
     16
     17        parent::tear_down();
     18    }
    719
    820    public function test_user_has_access_true_no_callable_function() {
     
    5769        $old_current_user = get_current_user_id();
    5870        $this->set_current_user( $u );
    59 
    60         $this->go_to( bp_core_get_user_domain( $u ) );
    61 
    62         $subnav_item = array(
    63             'user_has_access' => false,
    64         );
    65 
    66         // Just test relevant info
    67         $found = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item );
    68         $this->assertSame( 'failure', $found['status'] );
    69         $this->assertSame( bp_core_get_user_domain( $u ), $found['redirect_args']['root'] );
     71        $this->set_permalink_structure( '/%postname%/' );
     72
     73        $this->go_to( bp_members_get_user_url( $u ) );
     74
     75        $subnav_item = array(
     76            'user_has_access' => false,
     77        );
     78
     79        // Just test relevant info
     80        $found = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item );
     81        $this->assertSame( 'failure', $found['status'] );
     82        $this->assertSame( bp_members_get_user_url( $u ), $found['redirect_args']['root'] );
    7083
    7184        $this->set_current_user( $old_current_user );
     
    7790        $old_current_user = get_current_user_id();
    7891        $this->set_current_user( $u1 );
    79 
    80         $this->go_to( bp_core_get_user_domain( $u2 ) );
     92        $this->set_permalink_structure( '/%postname%/' );
     93
     94        $this->go_to( bp_members_get_user_url( $u2 ) );
    8195
    8296        $old_bp_nav = buddypress()->bp_nav;
     
    104118
    105119        $this->assertSame( 'failure', $found['status'] );
    106         $this->assertSame( bp_core_get_user_domain( $u2 ), $found['redirect_args']['root'] );
     120        $this->assertSame( bp_members_get_user_url( $u2 ), $found['redirect_args']['root'] );
    107121    }
    108122
     
    112126        $old_current_user = get_current_user_id();
    113127        $this->set_current_user( $u1 );
    114 
    115         $this->go_to( bp_core_get_user_domain( $u2 ) );
     128        $this->set_permalink_structure( '/%postname%/' );
     129
     130        $this->go_to( bp_members_get_user_url( $u2 ) );
    116131
    117132        $old_bp_nav = buddypress()->bp_nav;
     
    140155
    141156        $this->assertSame( 'failure', $found['status'] );
    142         $this->assertSame( bp_core_get_user_domain( $u2 ) . bp_get_activity_slug() . '/', $found['redirect_args']['root'] );
     157        $this->assertSame(
     158            bp_members_get_user_url(
     159                $u2,
     160                array(
     161                    'single_item_component' => bp_rewrites_get_slug( 'members', 'member_activity', bp_get_activity_slug() ),
     162                )
     163            ),
     164            $found['redirect_args']['root']
     165        );
    143166    }
    144167
Note: See TracChangeset for help on using the changeset viewer.