Skip to:
Content

BuddyPress.org

Changeset 14011


Ignore:
Timestamp:
08/29/2024 12:29:00 AM (6 weeks ago)
Author:
imath
Message:

Add 2 new filterable functions to get register/activate root slugs

These 2 functions are used to set rewrite rules and permastructs for registration and activation pages.

Using the provided filters it is now possible to prepend a custom-slug/ to these generated rewrite rules and permastructs. This was the only missing thing to be able to prepend a custom-slug/ to all BP directory/specific page root slugs.

Props espellcaste, slaFFik, dcavins.

See #9063
Closes https://github.com/buddypress/buddypress/pull/364

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-template.php

    r13897 r14011  
    244244
    245245/**
     246 * Returns the registration page root slug.
     247 *
     248 * This function is used to set the BP Signup rewrite rule and permastruct.
     249 *
     250 * @since 15.0.0
     251 *
     252 * @return string The registration page root slug.
     253 */
     254function bp_get_signup_root_slug() {
     255    /**
     256     * Filter here to edit the registration page root slug.
     257     *
     258     * @since 15.0.0
     259     *
     260     * @param string $register_root_slug The registration page root slug.
     261     */
     262    return apply_filters( 'bp_members_register_root_slug', bp_get_signup_slug() );
     263}
     264
     265/**
    246266 * Output the activation slug.
    247267 *
     
    275295        return apply_filters( 'bp_get_activate_slug', $slug );
    276296    }
     297
     298/**
     299 * Returns the registration page root slug.
     300 *
     301 * This function is used to set the BP Signup rewrite rule and permastruct.
     302 *
     303 * @since 15.0.0
     304 *
     305 * @return string The registration page root slug.
     306 */
     307function bp_get_activate_root_slug() {
     308    /**
     309     * Filter here to edit the activation page root slug.
     310     *
     311     * @since 15.0.0
     312     *
     313     * @param string $activate_root_slug The activation page root slug.
     314     */
     315    return apply_filters( 'bp_members_activate_root_slug', bp_get_activate_slug() );
     316}
    277317
    278318/**
  • trunk/src/bp-members/classes/class-bp-members-component.php

    r13979 r14011  
    228228
    229229        // Set-up Extra permastructs for the register and activate pages.
    230         $this->register_permastruct = bp_get_signup_slug() . '/%' . $this->rewrite_ids['member_register'] . '%';
    231         $this->activate_permastruct = bp_get_activate_slug() . '/%' . $this->rewrite_ids['member_activate'] . '%';
     230        $this->register_permastruct = bp_get_signup_root_slug() . '/%' . $this->rewrite_ids['member_register'] . '%';
     231        $this->activate_permastruct = bp_get_activate_root_slug() . '/%' . $this->rewrite_ids['member_activate'] . '%';
    232232
    233233        // Init the User's ID to use to build the Nav for.
     
    726726            ),
    727727            'member_activate'     => array(
    728                 'regex' => bp_get_activate_slug() . '/?$',
     728                'regex' => bp_get_activate_root_slug() . '/?$',
    729729                'order' => 40,
    730730                'query' => 'index.php?' . $this->rewrite_ids['member_activate'] . '=1',
    731731            ),
    732732            'member_activate_key' => array(
    733                 'regex' => bp_get_activate_slug() . '/([^/]+)/?$',
     733                'regex' => bp_get_activate_root_slug() . '/([^/]+)/?$',
    734734                'order' => 30,
    735735                'query' => 'index.php?' . $this->rewrite_ids['member_activate'] . '=1&' . $this->rewrite_ids['member_activate_key'] . '=$matches[1]',
    736736            ),
    737737            'member_register'     => array(
    738                 'regex' => bp_get_signup_slug() . '/?$',
     738                'regex' => bp_get_signup_root_slug() . '/?$',
    739739                'order' => 20,
    740740                'query' => 'index.php?' . $this->rewrite_ids['member_register'] . '=1',
  • trunk/tests/phpunit/testcases/routing/members.php

    r13980 r14011  
    122122        $this->assertSame( get_current_user_id(), bp_displayed_user_id() );
    123123    }
     124
     125    public function filter_root_slug( $root_slug ) {
     126        return 'community/' . $root_slug;
     127    }
     128
     129    /**
     130     * @ticket BP9063
     131     */
     132    public function test_members_registration_page_filtered() {
     133        $this->set_permalink_structure( '/%postname%/' );
     134
     135        add_filter( 'bp_members_register_root_slug', array( $this, 'filter_root_slug' ) );
     136        bp_delete_rewrite_rules();
     137
     138        // Regenerate rewrite rules.
     139        $this->go_to( home_url() );
     140        $bp_registration_url = bp_get_signup_page();
     141
     142        remove_filter( 'bp_members_register_root_slug', array( $this, 'filter_root_slug' ) );
     143
     144        $this->go_to( $bp_registration_url );
     145
     146        $this->assertTrue( false !== strpos( $bp_registration_url, 'community' ) );
     147        $this->assertTrue( bp_is_register_page() );
     148    }
     149
     150    /**
     151     * @ticket BP9063
     152     */
     153    public function test_members_registration_page() {
     154        $this->set_permalink_structure( '/%postname%/' );
     155        $bp_registration_url = bp_get_signup_page();
     156
     157        $this->go_to( $bp_registration_url );
     158
     159        $this->assertTrue( false === strpos( $bp_registration_url, 'community' ) );
     160        $this->assertTrue( bp_is_register_page() );
     161    }
     162
     163    /**
     164     * @ticket BP9063
     165     */
     166    public function test_members_activation_page_filtered() {
     167        $this->set_permalink_structure( '/%postname%/' );
     168
     169        add_filter( 'bp_members_activate_root_slug', array( $this, 'filter_root_slug' ) );
     170        bp_delete_rewrite_rules();
     171
     172        // Regenerate rewrite rules.
     173        $this->go_to( home_url() );
     174        $bp_activation_url = bp_get_activation_page();
     175
     176        remove_filter( 'bp_members_activate_root_slug', array( $this, 'filter_root_slug' ) );
     177
     178        $this->go_to( $bp_activation_url );
     179
     180        $this->assertTrue( false !== strpos( $bp_activation_url, 'community' ) );
     181        $this->assertTrue( bp_is_activation_page() );
     182    }
     183
     184    /**
     185     * @ticket BP9063
     186     */
     187    public function test_members_activation_page() {
     188        $this->set_permalink_structure( '/%postname%/' );
     189        $bp_activation_url = bp_get_activation_page();
     190
     191        $this->go_to( $bp_activation_url );
     192
     193        $this->assertTrue( false === strpos( $bp_activation_url, 'community' ) );
     194        $this->assertTrue( bp_is_activation_page() );
     195    }
    124196}
Note: See TracChangeset for help on using the changeset viewer.