Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/29/2024 12:29:00 AM (2 years 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.