BP_Groups_Component::setup_canonical_stack()

Set up canonical stack for this component.

Description

Source

File: bp-groups/classes/class-bp-groups-component.php

464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
public function setup_canonical_stack() {
    if ( ! bp_is_groups_component() ) {
        return;
    }
 
    if ( empty( $this->current_group ) ) {
        return;
    }
 
    $customizer_option = 'group_default_tab';
    $default_tab       = '';
 
    if ( function_exists( 'bp_nouveau_get_temporary_setting' ) && function_exists( 'bp_nouveau_get_appearance_settings' ) ) {
        $default_tab = bp_nouveau_get_temporary_setting( $customizer_option,bp_nouveau_get_appearance_settings( $customizer_option ) );
    }
    $default_tab = bp_is_active( $default_tab ) ? $default_tab : 'members';
 
    /**
     * Filters the default groups extension.
     *
     * @since BuddyPress 1.6.0
     *
     * @param string $value BP_GROUPS_DEFAULT_EXTENSION constant if defined,
     *                      else 'members'.
     */
    $this->default_extension = apply_filters( 'bp_groups_default_extension', defined( 'BP_GROUPS_DEFAULT_EXTENSION' ) ? BP_GROUPS_DEFAULT_EXTENSION : ( '' === $default_tab ) ? 'members' : $default_tab );
 
    $bp = buddypress();
 
    $user_has_access = $this->current_group->user_has_access;
    $is_visible      = $this->current_group->is_visible;
 
    if ( ! $user_has_access && $is_visible ) {
        $bp->current_action = 'request-membership';
    }
 
    // members are displayed in the front nav.
    if ( bp_is_current_action( 'home' ) || ! bp_current_action() ) {
        $bp->current_action = $this->default_extension;
    }
 
    // Prepare for a redirect to the canonical URL.
    $bp->canonical_stack['base_url'] = bp_get_group_permalink( $this->current_group );
 
    if ( bp_current_action() ) {
        $bp->canonical_stack['action'] = bp_current_action();
    }
 
    if ( ! empty( $bp->action_variables ) ) {
        $bp->canonical_stack['action_variables'] = bp_action_variables();
    }
 
    // When viewing the default extension, the canonical URL should not have
    // that extension's slug, unless more has been tacked onto the URL via
    // action variables.
    if ( bp_is_current_action( $this->default_extension ) && empty( $bp->action_variables ) )  {
        unset( $bp->canonical_stack['action'] );
    }
}

Changelog

Changelog
Version Description
BuddyPress 2.1.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.