Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/07/2023 04:28:08 AM (22 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/members/template.php

    r12791 r13433  
    44 */
    55class BP_Tests_Members_Template extends BP_UnitTestCase {
     6    protected $permalink_structure = '';
     7
     8    public function set_up() {
     9        parent::set_up();
     10        $this->permalink_structure = get_option( 'permalink_structure', '' );
     11    }
     12
     13    public function tear_down() {
     14        $this->set_permalink_structure( $this->permalink_structure );
     15
     16        parent::tear_down();
     17    }
     18
    619    public function test_bp_has_members_include_on_user_page() {
    720        $u1 = self::factory()->user->create();
    821        $u2 = self::factory()->user->create();
    9 
    10         $this->go_to( bp_core_get_user_domain( $u1 ) );
     22        $this->set_permalink_structure( '/%postname%/' );
     23
     24        $this->go_to( bp_members_get_user_url( $u1 ) );
    1125
    1226        global $members_template;
     
    5973        $old_user = get_current_user_id();
    6074        $this->set_current_user( $u2 );
    61 
    62         $this->go_to( bp_core_get_user_domain( $u2 ) . bp_get_friends_slug() . '/requests/' );
     75        $this->set_permalink_structure( '/%postname%/' );
     76
     77        $this->go_to(
     78            bp_members_get_user_url(
     79                $u2,
     80                array(
     81                    'single_item_component' => bp_rewrites_get_slug( 'members', 'member_friends', bp_get_friends_slug() ),
     82                    'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_friends_requests', 'requests' ),
     83                )
     84            )
     85        );
    6386        $this->restore_admins();
    6487
     
    86109        $old_user = get_current_user_id();
    87110        $this->set_current_user( $u2 );
     111        $this->set_permalink_structure( '/%postname%/' );
    88112
    89113        // For some reason, in all the user switching, the cache gets
     
    93117        wp_cache_delete( 'bp_user_domain_' . $u2, 'bp' );
    94118
    95         $this->go_to( bp_core_get_user_domain( $u2 ) . bp_get_friends_slug() . '/requests/' );
     119        $this->go_to(
     120            bp_members_get_user_url(
     121                $u2,
     122                array(
     123                    'single_item_component' => bp_rewrites_get_slug( 'members', 'member_friends', bp_get_friends_slug() ),
     124                    'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_friends_requests', 'requests' ),
     125                )
     126            )
     127        );
    96128        $this->restore_admins();
    97129
Note: See TracChangeset for help on using the changeset viewer.