Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/12/2014 01:26:36 AM (12 years ago)
Author:
boonebgorges
Message:

Overhaul access and visibility control for group tabs

Previously, access control to group tabs was handled in two ways:

  • for BP_Group_Extension tabs, the 'enable_nav_item' and 'visibility' provided some control over access to plugin developers, though it was inconsistent, buggy, and difficult to implement properly
  • for tabs provided by bp-groups, access to the tabs of non-public groups was controlled directly in the BP_Groups_Component::setup_globals() method

Aside from being unclear for developers, this technique for controlling access
was also inflexible. For non-public groups, tab access was hardcoded and
handled before BP_Group_Extension plugins even had a chance to load. As a
result, it was essentially impossible to add public tabs to non-public groups
(among other non-standard customizations).

The current changeset comprises a number of changes that make tab access more
consistent and flexible:

  • Access control is moved to the new bp_groups_group_access_protection() function. This function has the necessary filters to customize access protection in arbitrary ways. And because it loads at 'bp_actions' - just before the page begins to render - all extensions have had a chance to load and register themselves with the desired access settings.
  • The 'visibility' and 'enable_nav_item' properties of BP_Group_Extension are phased out in favor of 'access' and 'show_tab' params. 'access' controls who can visit the tab, while 'show_tab' controls who can see the item in the navigation. These new properties have intelligent defaults (based on the privacy level of the group), but can be overridden with a number of custom settings: 'admin', 'mod', 'member', 'loggedin', 'anyone', or 'noone'. Backward compatibility is maintained, so that existing BP_Group_Extension plugins that use enable_nav_item or visibility will continue to work as before.

Fixes #4785

Props boonebgorges, dcavins, imath

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-legacy/buddypress/groups/single/home.php

    r8159 r8605  
    3434                 */
    3535
    36                 // Group is visible
    37                 if ( bp_group_is_visible() ) :
    38 
    3936                        // Looking at home location
    4037                        if ( bp_is_group_home() ) :
    4138
    42                                 // Use custom front if one exists
    43                                 $custom_front = bp_locate_template( array( 'groups/single/front.php' ), false, true );
    44                                 if     ( ! empty( $custom_front   ) ) : load_template( $custom_front, true );
     39                                if ( bp_group_is_visible() ) {
    4540
    46                                 // Default to activity
    47                                 elseif ( bp_is_active( 'activity' ) ) : bp_get_template_part( 'groups/single/activity' );
     41                                        // Use custom front if one exists
     42                                        $custom_front = bp_locate_template( array( 'groups/single/front.php' ), false, true );
     43                                        if     ( ! empty( $custom_front   ) ) : load_template( $custom_front, true );
    4844
    49                                 // Otherwise show members
    50                                 elseif ( bp_is_active( 'members'  ) ) : bp_groups_members_template_part();
     45                                        // Default to activity
     46                                        elseif ( bp_is_active( 'activity' ) ) : bp_get_template_part( 'groups/single/activity' );
    5147
    52                                 endif;
    53                                
     48                                        // Otherwise show members
     49                                        elseif ( bp_is_active( 'members'  ) ) : bp_groups_members_template_part();
     50
     51                                        endif;
     52
     53                                } else {
     54
     55                                        do_action( 'bp_before_group_status_message' ); ?>
     56
     57                                        <div id="message" class="info">
     58                                                <p><?php bp_group_status_message(); ?></p>
     59                                        </div>
     60
     61                                        <?php do_action( 'bp_after_group_status_message' );
     62
     63                                }
     64
    5465                        // Not looking at home
    5566                        else :
     
    7788
    7889                                endif;
    79                         endif;
    80 
    81                 // Group is not visible
    82                 elseif ( ! bp_group_is_visible() ) :
    83 
    84                         // Membership request
    85                         if ( bp_is_group_membership_request() ) :
    86                                 bp_get_template_part( 'groups/single/request-membership' );
    87 
    88                         // The group is not visible, show the status message
    89                         else :
    90 
    91                                 do_action( 'bp_before_group_status_message' ); ?>
    92 
    93                                 <div id="message" class="info">
    94                                         <p><?php bp_group_status_message(); ?></p>
    95                                 </div>
    96 
    97                                 <?php do_action( 'bp_after_group_status_message' );
    9890
    9991                        endif;
    100                 endif;
    10192
    10293                do_action( 'bp_after_group_body' ); ?>
Note: See TracChangeset for help on using the changeset viewer.