Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/14/2023 04:11:52 AM (2 years ago)
Author:
imath
Message:

Administration: add Group slugs management into the URLs settings tab

  • Add a new $built_in argument to bp_get_group_screens() to only get BP built in single Groups item screens.
  • Edit the BP_Groups_Component::setup_nav() method so that it uses bp_get_group_screens() to generate the single group's navigation items.
  • bp_get_group_screens() is making it easier to manage all single group's nav item slugs from the BP Urls settings tab.

Props r-a-y, johnjamesjacoby, boonebgorges

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-functions.php

    r13449 r13451  
    12761276     */
    12771277    return apply_filters( 'groups_get_current_group', $current_group );
     1278}
     1279
     1280/**
     1281 * Can the current user access to the current group?
     1282 *
     1283 * @since 12.0.0
     1284 *
     1285 * @return boolean True if the current user can access to the current group.
     1286 *                 False otherwise.
     1287 */
     1288function bp_groups_user_can_access_current_group() {
     1289    $can_access = false;
     1290
     1291    $current_group = groups_get_current_group();
     1292    if ( isset( $current_group->user_has_access ) ) {
     1293        $can_access = $current_group->user_has_access;
     1294    }
     1295
     1296    return $can_access;
    12781297}
    12791298
     
    37913810 * @since 12.0.0
    37923811 *
    3793  * @param string $context The display context. Required. Defaults to `read`.
    3794  * @return array          The list of potential Group screens.
    3795  */
    3796 function bp_get_group_screens( $context = 'read' ) {
     3812 * @param string  $context  The display context. Required. Defaults to `read`.
     3813 * @param boolean $built_in True to only get builtin screens. False otherwise.
     3814 * @return array            The list of potential Group screens.
     3815 */
     3816function bp_get_group_screens( $context = 'read', $built_in = false ) {
    37973817    $screens = array(
    37983818        'create' => array(
     
    38373857                'item_css_id'     => 'home',
    38383858            ),
    3839             'activity'            => array(
    3840                 'rewrite_id'      => 'bp_group_read_activity',
    3841                 'slug'            => 'activity',
    3842                 'name'            => _x( 'Activity', 'Group read screen', 'buddypress' ),
    3843                 'screen_function' => 'groups_screen_group_activity',
    3844                 'position'        => 11,
    3845                 'user_has_access' => false,
    3846                 'no_access_url'   => '',
    3847                 'item_css_id'     => 'activity',
    3848             ),
    38493859            'request-membership' => array(
    38503860                'rewrite_id'      => 'bp_group_read_request_membership',
     
    38543864                'position'        => 30,
    38553865            ),
     3866            'activity'           => array(
     3867                'rewrite_id'               => 'bp_group_read_activity',
     3868                'slug'                     => 'activity',
     3869                'name'                     => _x( 'Activity', 'Group read screen', 'buddypress' ),
     3870                'screen_function'          => 'groups_screen_group_activity',
     3871                'position'                 => 11,
     3872                'user_has_access'          => false,
     3873                'user_has_access_callback' => 'bp_groups_user_can_access_current_group',
     3874                'no_access_url'            => '',
     3875                'item_css_id'              => 'activity',
     3876            ),
    38563877            'members'            => array(
    3857                 'rewrite_id'      => 'bp_group_read_members',
    3858                 'slug'            => 'members',
     3878                'rewrite_id'               => 'bp_group_read_members',
     3879                'slug'                     => 'members',
    38593880                /* translators: %s: total member count */
    3860                 'name'            => _x( 'Members %s', 'Group read screen', 'buddypress' ),
    3861                 'screen_function' => 'groups_screen_group_members',
    3862                 'position'        => 60,
    3863                 'user_has_access' => false,
    3864                 'no_access_url'   => '',
    3865                 'item_css_id'     => 'members',
     3881                'name'                     => _x( 'Members %s', 'Group read screen', 'buddypress' ),
     3882                'screen_function'          => 'groups_screen_group_members',
     3883                'position'                 => 60,
     3884                'user_has_access'          => false,
     3885                'user_has_access_callback' => 'bp_groups_user_can_access_current_group',
     3886                'no_access_url'            => '',
     3887                'item_css_id'              => 'members',
    38663888            ),
    38673889            'send-invites'       => array(
    3868                 'rewrite_id'      => 'bp_group_read_send_invites',
    3869                 'slug'            => 'send-invites',
    3870                 'name'            => _x( 'Send Invites', 'Group read screen', 'buddypress' ),
    3871                 'screen_function' => 'groups_screen_group_invite',
    3872                 'position'        => 70,
    3873                 'user_has_access' => false,
    3874                 'no_access_url'   => '',
    3875                 'item_css_id'     => 'invite',
     3890                'rewrite_id'               => 'bp_group_read_send_invites',
     3891                'slug'                     => 'send-invites',
     3892                'name'                     => _x( 'Send Invites', 'Group read screen', 'buddypress' ),
     3893                'screen_function'          => 'groups_screen_group_invite',
     3894                'position'                 => 70,
     3895                'user_has_access'          => false,
     3896                'user_has_access_callback' => 'bp_groups_user_can_send_invites',
     3897                'no_access_url'            => '',
     3898                'item_css_id'              => 'invite',
    38763899            ),
    38773900            'admin'              => array(
    3878                 'rewrite_id'      => 'bp_group_read_admin',
    3879                 'slug'            => 'admin',
    3880                 'name'            => _x( 'Manage', 'Group read screen', 'buddypress' ),
    3881                 'screen_function' => 'groups_screen_group_admin',
    3882                 'position'        => 1000,
    3883                 'user_has_access' => false,
    3884                 'no_access_url'   => '',
    3885                 'item_css_id'     => 'admin',
     3901                'rewrite_id'               => 'bp_group_read_admin',
     3902                'slug'                     => 'admin',
     3903                'name'                     => _x( 'Manage', 'Group read screen', 'buddypress' ),
     3904                'screen_function'          => 'groups_screen_group_admin',
     3905                'position'                 => 1000,
     3906                'user_has_access'          => false,
     3907                'user_has_access_callback' => 'bp_is_item_admin',
     3908                'no_access_url'            => '',
     3909                'item_css_id'              => 'admin',
    38863910            ),
    38873911        ),
     
    39573981    }
    39583982
     3983    // We only need built-in screens, do not get custom ones.
     3984    if ( $built_in ) {
     3985        return $screens[ $context ];
     3986    }
     3987
    39593988    $context_screens         = array();
    39603989    $custom_screens          = apply_filters( 'bp_get_group_custom_' . $context . '_screens', $context_screens );
     
    39673996    if ( $custom_screens && ! wp_is_numeric_array( $custom_screens ) ) {
    39683997        // The screen key (used as default slug) and `rewrite_id` prop need to be unique.
    3969         $valid_custom_screens   = array_diff_key( $custom_screens, $screens[ $context ] );
     3998        $valid_custom_screens = array_diff_key( $custom_screens, $screens[ $context ] );
    39703999        $existing_rewrite_ids = array_column( $screens[ $context ], 'rewrite_id' );
    39714000        $existing_rewrite_ids = array_merge(
Note: See TracChangeset for help on using the changeset viewer.