Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/22/2021 04:47:17 PM (4 years ago)
Author:
imath
Message:

Add a new method to the Members & Groups components main class

BP_Members_Component::setup_additional_globals() & BP_Groups_Component::setup_additional_globals() are used to set specific components globals that are not passed to BP_Component::setup_globals(). This commit also makes sure the BP Nouveau template pack uses a consistent object ID for its directory navigation.

Fixes #8555

File:
1 edited

Legend:

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

    r13004 r13087  
    216216
    217217    /**
    218      * Set up component global data.
    219      *
    220      * The BP_GROUPS_SLUG constant is deprecated, and only used here for
    221      * backwards compatibility.
    222      *
    223      * @since 1.5.0
    224      *
    225      * @see BP_Component::setup_globals() for a description of arguments.
    226      *
    227      * @param array $args See BP_Component::setup_globals() for a description.
    228      */
    229     public function setup_globals( $args = array() ) {
     218     * Set up additional globals for the component.
     219     *
     220     * @since 10.0.0
     221     */
     222    public function setup_additional_globals() {
    230223        $bp = buddypress();
    231 
    232         // Define a slug, if necessary.
    233         if ( ! defined( 'BP_GROUPS_SLUG' ) ) {
    234             define( 'BP_GROUPS_SLUG', $this->id );
    235         }
    236 
    237         // Global tables for groups component.
    238         $global_tables = array(
    239             'table_name'           => $bp->table_prefix . 'bp_groups',
    240             'table_name_members'   => $bp->table_prefix . 'bp_groups_members',
    241             'table_name_groupmeta' => $bp->table_prefix . 'bp_groups_groupmeta'
    242         );
    243 
    244         // Metadata tables for groups component.
    245         $meta_tables = array(
    246             'group' => $bp->table_prefix . 'bp_groups_groupmeta',
    247         );
    248 
    249         // Fetch the default directory title.
    250         $default_directory_titles = bp_core_get_directory_page_default_titles();
    251         $default_directory_title  = $default_directory_titles[$this->id];
    252 
    253         // All globals for groups component.
    254         // Note that global_tables is included in this array.
    255         $args = array(
    256             'slug'                  => BP_GROUPS_SLUG,
    257             'root_slug'             => isset( $bp->pages->groups->slug ) ? $bp->pages->groups->slug : BP_GROUPS_SLUG,
    258             'has_directory'         => true,
    259             'directory_title'       => isset( $bp->pages->groups->title ) ? $bp->pages->groups->title : $default_directory_title,
    260             'notification_callback' => 'groups_format_notifications',
    261             'search_string'         => _x( 'Search Groups...', 'Component directory search', 'buddypress' ),
    262             'global_tables'         => $global_tables,
    263             'meta_tables'           => $meta_tables,
    264             'block_globals'         => array(
    265                 'bp/dynamic-groups' => array(
    266                     'widget_classnames' => array( 'widget_bp_groups_widget', 'buddypress' ),
    267                 ),
    268             ),
    269         );
    270 
    271         parent::setup_globals( $args );
    272224
    273225        /* Single Group Globals **********************************************/
     
    442394        // Auto join group when non group member performs group activity.
    443395        $this->auto_join = defined( 'BP_DISABLE_AUTO_GROUP_JOIN' ) && BP_DISABLE_AUTO_GROUP_JOIN ? false : true;
     396    }
     397
     398    /**
     399     * Set up component global data.
     400     *
     401     * The BP_GROUPS_SLUG constant is deprecated, and only used here for
     402     * backwards compatibility.
     403     *
     404     * @since 1.5.0
     405     *
     406     * @see BP_Component::setup_globals() for a description of arguments.
     407     *
     408     * @param array $args See BP_Component::setup_globals() for a description.
     409     */
     410    public function setup_globals( $args = array() ) {
     411        $bp = buddypress();
     412
     413        // Define a slug, if necessary.
     414        if ( ! defined( 'BP_GROUPS_SLUG' ) ) {
     415            define( 'BP_GROUPS_SLUG', $this->id );
     416        }
     417
     418        // Global tables for groups component.
     419        $global_tables = array(
     420            'table_name'           => $bp->table_prefix . 'bp_groups',
     421            'table_name_members'   => $bp->table_prefix . 'bp_groups_members',
     422            'table_name_groupmeta' => $bp->table_prefix . 'bp_groups_groupmeta'
     423        );
     424
     425        // Metadata tables for groups component.
     426        $meta_tables = array(
     427            'group' => $bp->table_prefix . 'bp_groups_groupmeta',
     428        );
     429
     430        // Fetch the default directory title.
     431        $default_directory_titles = bp_core_get_directory_page_default_titles();
     432        $default_directory_title  = $default_directory_titles[$this->id];
     433
     434        // All globals for groups component.
     435        // Note that global_tables is included in this array.
     436        $args = array(
     437            'slug'                  => BP_GROUPS_SLUG,
     438            'root_slug'             => isset( $bp->pages->groups->slug ) ? $bp->pages->groups->slug : BP_GROUPS_SLUG,
     439            'has_directory'         => true,
     440            'directory_title'       => isset( $bp->pages->groups->title ) ? $bp->pages->groups->title : $default_directory_title,
     441            'notification_callback' => 'groups_format_notifications',
     442            'search_string'         => _x( 'Search Groups...', 'Component directory search', 'buddypress' ),
     443            'global_tables'         => $global_tables,
     444            'meta_tables'           => $meta_tables,
     445            'block_globals'         => array(
     446                'bp/dynamic-groups' => array(
     447                    'widget_classnames' => array( 'widget_bp_groups_widget', 'buddypress' ),
     448                ),
     449            ),
     450        );
     451
     452        parent::setup_globals( $args );
     453
     454        // Additional globals.
     455        $this->setup_additional_globals();
    444456    }
    445457
Note: See TracChangeset for help on using the changeset viewer.