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-blogs/classes/class-bp-blogs-component.php

    r13432 r13436  
    8282            'has_directory'         => is_multisite(), // Non-multisite installs don't need a top-level Sites directory, since there's only one site.
    8383            'rewrite_ids'           => array(
    84                 'directory'                    => 'blogs',
    85                 'single_item_action'           => 'blogs_action',
    86                 'single_item_action_variables' => 'blogs_action_variables',
     84                'directory'          => 'blogs',
     85                'create_single_item' => 'blog_create',
    8786            ),
    8887            'directory_title'       => isset( $bp->pages->blogs->title ) ? $bp->pages->blogs->title : $default_directory_title,
     
    312311            // Create a Site.
    313312            if ( bp_blog_signup_enabled() ) {
     313                $url = bp_get_blogs_directory_url(
     314                    array(
     315                        'create_single_item' => 1,
     316                    )
     317                );
     318
    314319                $wp_admin_nav[] = array(
    315320                    'parent'   => 'my-account-' . $this->id,
    316321                    'id'       => 'my-account-' . $this->id . '-create',
    317322                    'title'    => __( 'Create a Site', 'buddypress' ),
    318                     'href'     => trailingslashit( bp_get_blogs_directory_permalink() . 'create' ),
     323                    'href'     => $url,
    319324                    'position' => 99
    320325                );
     
    371376
    372377        parent::setup_cache_groups();
     378    }
     379
     380    /**
     381     * Add the Blog Create rewrite tags.
     382     *
     383     * @since 12.0.0
     384     *
     385     * @param array $rewrite_tags Optional. See BP_Component::add_rewrite_tags() for
     386     *                            description.
     387     */
     388    public function add_rewrite_tags( $rewrite_tags = array() ) {
     389        $rewrite_tags = array(
     390            'create_single_item' => '([1]{1,})',
     391        );
     392
     393        parent::add_rewrite_tags( $rewrite_tags );
     394    }
     395
     396    /**
     397     * Add the Registration and Activation rewrite rules.
     398     *
     399     * @since 12.0.0
     400     *
     401     * @param array $rewrite_rules Optional. See BP_Component::add_rewrite_rules() for
     402     *                             description.
     403     */
     404    public function add_rewrite_rules( $rewrite_rules = array() ) {
     405        $create_slug = bp_rewrites_get_slug( 'blogs', 'blog_create', 'create' );
     406
     407        $rewrite_rules = array(
     408            'create_single_item' => array(
     409                'regex' => $this->root_slug . '/' . $create_slug . '/?$',
     410                'order' => 50,
     411                'query' => 'index.php?' . $this->rewrite_ids['directory'] . '=1&' . $this->rewrite_ids['create_single_item'] . '=1',
     412            ),
     413        );
     414
     415        parent::add_rewrite_rules( $rewrite_rules );
    373416    }
    374417
Note: See TracChangeset for help on using the changeset viewer.