Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/07/2023 04:28:08 AM (2 years 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/routing/groups.php

    r13314 r13433  
    66class BP_Tests_Routing_Groups extends BP_UnitTestCase {
    77    protected $old_current_user = 0;
     8    protected $permalink_structure = '';
    89
    910    public function set_up() {
     
    1213        buddypress()->members->types = array();
    1314        $this->old_current_user = get_current_user_id();
     15        $this->permalink_structure = get_option( 'permalink_structure', '' );
    1416        $this->set_current_user( self::factory()->user->create( array( 'role' => 'subscriber' ) ) );
    1517    }
     
    1820        parent::tear_down();
    1921        $this->set_current_user( $this->old_current_user );
     22        $this->set_permalink_structure( $this->permalink_structure );
    2023    }
    2124
    2225    function test_member_groups() {
    23         $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_groups_slug() );
     26        $this->set_permalink_structure( '/%postname%/' );
     27        $this->go_to(
     28            bp_members_get_user_url(
     29                bp_loggedin_user_id(),
     30                array(
     31                    'single_item_component' => bp_rewrites_get_slug( 'members', 'member_groups', bp_get_groups_slug() ),
     32                )
     33            )
     34        );
    2435        $this->assertTrue( bp_is_user_groups() );
    2536    }
    2637
    2738    function test_member_groups_invitations() {
    28         $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_groups_slug() . '/invites' );
     39        $this->set_permalink_structure( '/%postname%/' );
     40        $this->go_to(
     41            bp_members_get_user_url(
     42                bp_loggedin_user_id(),
     43                array(
     44                    'single_item_component' => bp_rewrites_get_slug( 'members', 'member_groups', bp_get_groups_slug() ),
     45                    'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_friends_invites', 'invites' ),
     46                )
     47            )
     48        );
    2949        $this->assertTrue( bp_is_user_groups() && bp_is_current_action( 'invites' ) );
    3050    }
     
    3454     */
    3555    public function test_group_directory_with_type() {
     56        $this->set_permalink_structure( '/%postname%/' );
    3657        bp_groups_register_group_type( 'foo' );
    3758        $this->go_to( bp_get_groups_directory_permalink() . 'type/foo/' );
     
    4364     */
    4465    public function test_group_directory_with_type_that_has_custom_directory_slug() {
     66        $this->set_permalink_structure( '/%postname%/' );
    4567        bp_groups_register_group_type( 'foo', array( 'has_directory' => 'foos' ) );
    4668        $this->go_to( bp_get_groups_directory_permalink() . 'type/foos/' );
     
    5274     */
    5375    public function test_group_directory_should_404_for_group_types_that_have_no_directory() {
     76        $this->set_permalink_structure( '/%postname%/' );
    5477        bp_register_member_type( 'foo', array( 'has_directory' => false ) );
    5578        $this->go_to( bp_get_members_directory_permalink() . 'type/foo/' );
     
    6184     */
    6285    public function test_group_directory_should_404_for_invalid_group_types() {
     86        $this->set_permalink_structure( '/%postname%/' );
    6387        $this->go_to( bp_get_members_directory_permalink() . 'type/foo/' );
    6488        $this->assertTrue( is_404() );
     
    6993     */
    7094    public function test_group_previous_slug_current_slug_should_resolve() {
     95        $this->set_permalink_structure( '/%postname%/' );
    7196        $g1 = self::factory()->group->create( array(
    7297            'slug' => 'george',
     
    86111     */
    87112    public function test_group_previous_slug_should_resolve() {
     113        $this->set_permalink_structure( '/%postname%/' );
    88114        $g1 = self::factory()->group->create( array(
    89115            'slug' => 'george',
     
    104130     */
    105131    public function test_group_previous_slug_most_recent_takes_precedence() {
     132        $this->set_permalink_structure( '/%postname%/' );
    106133        $g1 = self::factory()->group->create( array(
    107134            'slug' => 'george',
Note: See TracChangeset for help on using the changeset viewer.