Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/15/2023 08:16:46 AM (22 months ago)
Author:
imath
Message:

Make more BuddyPress generated links ready for BP Rewrites

  • Improve the Members component adding permastructs and custom rewrite

rules for registration and activation pages.

  • Improve the Blogs component adding custom rewrite rule to handle the

Blogs create page.

  • Make a huge progress about replacing all occurrences of

bp_get_root_domain() (45 replacements were performed).

  • Deprecate bp_groups_directory_permalink(),

bp_get_groups_directory_permalink(), bp_blogs_directory_permalink() &
bp_get_blogs_directory_permalink() and replace them with these new
functions: bp_groups_directory_url(), bp_get_groups_directory_url(),
bp_blogs_directory_url() & bp_get_blogs_directory_url().

  • Although bp_loggedin_user_domain() & bp_displayed_user_domain()

should also be deprecated, we're leaving them as aliases of the right
functions to use. Plugin authors shouldn't use them to build other links
than member's profile home url.

NB: these deprecations are required because these functions were used
to build BuddyPress URLs concatenating URL chunks. Once the BP Classic
plugin will be built we will adapt the code to remove these deprecation
notices.

Props r-a-y, johnjamesjacoby, boonebgorges

Closes https://github.com/buddypress/buddypress/pull/73
See #4954

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/classes/class-bp-members-component.php

    r13433 r13436  
    215215    public function setup_additional_globals() {
    216216        $bp = buddypress();
     217
     218        // Set-up Extra permastructs for the register and activate pages.
     219        $this->register_permastruct = bp_get_signup_slug() . '/%' . $this->rewrite_ids['member_register'] . '%';
     220        $this->activate_permastruct = bp_get_activate_slug() . '/%' . $this->rewrite_ids['member_activate'] . '%';
    217221
    218222        /** Logged in user ***************************************************
     
    784788
    785789    /**
     790     * Add the Registration and Activation rewrite tags.
     791     *
     792     * @since 12.0.0
     793     *
     794     * @param array $rewrite_tags Optional. See BP_Component::add_rewrite_tags() for
     795     *                            description.
     796     */
     797    public function add_rewrite_tags( $rewrite_tags = array() ) {
     798        $rewrite_tags = array(
     799            'member_register'     => '([1]{1,})',
     800            'member_activate'     => '([1]{1,})',
     801            'member_activate_key' => '([^/]+)',
     802        );
     803
     804        parent::add_rewrite_tags( $rewrite_tags );
     805    }
     806
     807    /**
     808     * Add the Registration and Activation rewrite rules.
     809     *
     810     * @since 12.0.0
     811     *
     812     * @param array $rewrite_rules Optional. See BP_Component::add_rewrite_rules() for
     813     *                             description.
     814     */
     815    public function add_rewrite_rules( $rewrite_rules = array() ) {
     816        $rewrite_rules = array(
     817            'directory_type'      => array(
     818                'regex' => $this->root_slug . '/' . bp_get_members_member_type_base() . '/([^/]+)/?$',
     819                'order' => 50,
     820                'query' => 'index.php?' . $this->rewrite_ids['directory'] . '=1&' . $this->rewrite_ids['directory_type'] . '=$matches[1]',
     821            ),
     822            'member_activate'     => array(
     823                'regex' => bp_get_activate_slug(),
     824                'order' => 40,
     825                'query' => 'index.php?' . $this->rewrite_ids['member_activate'] . '=1',
     826            ),
     827            'member_activate_key' => array(
     828                'regex' => bp_get_activate_slug() . '/([^/]+)/?$',
     829                'order' => 30,
     830                'query' => 'index.php?' . $this->rewrite_ids['member_activate'] . '=1&' . $this->rewrite_ids['member_activate_key'] . '=$matches[1]',
     831            ),
     832            'member_register'     => array(
     833                'regex' => bp_get_signup_slug(),
     834                'order' => 20,
     835                'query' => 'index.php?' . $this->rewrite_ids['member_register'] . '=1',
     836            ),
     837        );
     838
     839        parent::add_rewrite_rules( $rewrite_rules );
     840    }
     841
     842    /**
     843     * Add the Registration and Activation permastructs.
     844     *
     845     * @since 12.0.0
     846     *
     847     * @param array $permastructs Optional. See BP_Component::add_permastructs() for
     848     *                            description.
     849     */
     850    public function add_permastructs( $permastructs = array() ) {
     851        $permastructs = array(
     852            // Register permastruct.
     853            $this->rewrite_ids['member_register'] => array(
     854                'permastruct' => $this->register_permastruct,
     855                'args'        => array(),
     856            ),
     857            // Activate permastruct.
     858            $this->rewrite_ids['member_activate'] => array(
     859                'permastruct' => $this->activate_permastruct,
     860                'args'        => array(),
     861            ),
     862        );
     863
     864        parent::add_permastructs( $permastructs );
     865    }
     866
     867    /**
    786868     * Init the BP REST API.
    787869     *
Note: See TracChangeset for help on using the changeset viewer.