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/members/functions.php

    r13431 r13433  
    55#[AllowDynamicProperties]
    66class BP_Tests_Members_Functions 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    /**
     
    114126     * @group bp_core_get_directory_pages
    115127     */
    116     public function test_bp_core_get_user_domain_after_directory_page_update() {
     128    public function test_bp_members_get_user_url_after_directory_page_update() {
    117129        // Generate user
    118130        $user_id = self::factory()->user->create( array( 'role' => 'subscriber' ) );
     131        $this->set_permalink_structure( '/%postname%/' );
    119132
    120133        // Set object cache first for user domain
    121         $user_domain = bp_core_get_user_domain( $user_id );
     134        $user_domain = bp_members_get_user_url( $user_id );
    122135
    123136        // Now change the members directory slug
     
    137150        $user = new WP_User( $user_id );
    138151
    139         $this->assertSame( home_url( $new_members_slug ) . '/' . $user->user_nicename . '/', bp_core_get_user_domain( $user_id ) );
     152        $this->assertSame( home_url( $new_members_slug ) . '/' . $user->user_nicename . '/', bp_members_get_user_url( $user_id ) );
    140153    }
    141154
Note: See TracChangeset for help on using the changeset viewer.