Skip to:
Content

BuddyPress.org

Changeset 13505


Ignore:
Timestamp:
06/22/2023 04:08:38 AM (3 years ago)
Author:
imath
Message:

Blogs: implement Action, Action variables & Create rewrite rules

These rules were missed in #4954

Fixes #8925
Closes https://github.com/buddypress/buddypress/pull/119

File:
1 edited

Legend:

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

    r13503 r13505  
    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                 'create_single_item' => 'blog_create',
     84                'directory'                  => 'blogs',
     85                'create_single_item'         => 'blog_create',
     86                'directory_action'           => 'blogs_action',
     87                'directory_action_variables' => 'blogs_action_variables'
    8688            ),
    8789            'directory_title'       => isset( $bp->pages->blogs->title ) ? $bp->pages->blogs->title : $default_directory_title,
     
    398400    public function add_rewrite_tags( $rewrite_tags = array() ) {
    399401        $rewrite_tags = array(
    400             'create_single_item' => '([1]{1,})',
     402            'create_single_item'         => '([1]{1,})',
     403            'directory_action'           => '([^/]+)',
     404            'directory_action_variables' => '(.+?)',
    401405        );
    402406
     
    416420
    417421        $rewrite_rules = array(
     422            'directory_action_variables' => array(
     423                'regex' => $this->root_slug . '/([^/]+)/(.+?)/?$',
     424                'order' => 70,
     425                'query' => 'index.php?' . $this->rewrite_ids['directory'] . '=1&' . $this->rewrite_ids['directory_action'] . '=$matches[1]&' . $this->rewrite_ids['directory_action_variables'] . '=$matches[2]',
     426            ),
     427            'directory_action'           => array(
     428                'regex' => $this->root_slug . '/([^/]+)/?$',
     429                'order' => 60,
     430                'query' => 'index.php?' . $this->rewrite_ids['directory'] . '=1&' . $this->rewrite_ids['directory_action'] . '=$matches[1]',
     431            ),
    418432            'create_single_item' => array(
    419433                'regex' => $this->root_slug . '/' . $create_slug . '/?$',
     
    453467        if ( 1 === (int) $query->get( $this->rewrite_ids['directory'] ) ) {
    454468            $bp->current_component = 'blogs';
    455 
    456             $current_action = $query->get( $this->rewrite_ids['single_item_action'] );
    457             if ( $current_action ) {
    458                 $bp->current_action = $current_action;
    459             }
    460 
    461             $action_variables = $query->get( $this->rewrite_ids['single_item_action_variables'] );
    462             if ( $action_variables ) {
    463                 if ( ! is_array( $action_variables ) ) {
    464                     $bp->action_variables = explode( '/', ltrim( $action_variables, '/' ) );
    465                 } else {
    466                     $bp->action_variables = $action_variables;
     469            $is_blog_create        = 1 === (int) $query->get( $this->rewrite_ids['create_single_item'] );
     470
     471            if ( $is_blog_create ) {
     472                $bp->current_action = 'create';
     473            } else {
     474                $current_action = $query->get( $this->rewrite_ids['directory_action'] );
     475                if ( $current_action ) {
     476                    $bp->current_action = $current_action;
    467477                }
     478
     479                $action_variables = $query->get( $this->rewrite_ids['directory_action_variables'] );
     480                if ( $action_variables ) {
     481                    if ( ! is_array( $action_variables ) ) {
     482                        $bp->action_variables = explode( '/', ltrim( $action_variables, '/' ) );
     483                    } else {
     484                        $bp->action_variables = $action_variables;
     485                    }
     486                }
    468487            }
    469488
    470489            // Set the BuddyPress queried object.
    471             if ( isset( $bp->pages->blogs->id ) ) {
     490            if ( isset( $bp->pages->blogs->id ) && ( ! bp_current_action() || bp_is_current_action( 'create' ) ) ) {
    472491                $query->queried_object    = get_post( $bp->pages->blogs->id );
    473492                $query->queried_object_id = $query->queried_object->ID;
Note: See TracChangeset for help on using the changeset viewer.