Changeset 8605 for trunk/src/bp-groups/bp-groups-actions.php
- Timestamp:
- 07/12/2014 01:26:36 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/bp-groups-actions.php
r8125 r8605 14 14 // Exit if accessed directly 15 15 if ( !defined( 'ABSPATH' ) ) exit; 16 17 /** 18 * Protect access to single groups. 19 * 20 * @since BuddyPress (2.1.0) 21 */ 22 function bp_groups_group_access_protection() { 23 if ( ! bp_is_group() ) { 24 return; 25 } 26 27 $current_group = groups_get_current_group(); 28 $user_has_access = $current_group->user_has_access; 29 $no_access_args = array(); 30 31 if ( ! $user_has_access && 'hidden' !== $current_group->status ) { 32 // Always allow access to home and request-membership 33 if ( bp_is_current_action( 'home' ) || bp_is_current_action( 'request-membership' ) ) { 34 $user_has_access = true; 35 36 // User doesn't have access, so set up redirect args 37 } else if ( is_user_logged_in() ) { 38 $no_access_args = array( 39 'message' => __( 'You do not have access to this group.', 'buddypress' ), 40 'root' => bp_get_group_permalink( $current_group ) . 'home/', 41 'redirect' => false 42 ); 43 } 44 } 45 46 // Protect the admin tab from non-admins 47 if ( bp_is_current_action( 'admin' ) && ! bp_is_item_admin() ) { 48 $user_has_access = false; 49 $no_access_args = array( 50 'message' => __( 'You are not an admin of this group.', 'buddypress' ), 51 'root' => bp_get_group_permalink( $current_group ), 52 'redirect' => false 53 ); 54 } 55 56 /** 57 * Allow plugins to filter whether the current user has access to this group content. 58 * 59 * Note that if a plugin sets $user_has_access to false, it may also 60 * want to change the $no_access_args, to avoid problems such as 61 * logged-in users being redirected to wp-login.php. 62 * 63 * @since BuddyPress (2.1.0) 64 * 65 * @param bool $user_has_access True if the user has access to the 66 * content, otherwise false. 67 * @param array $no_access_args Arguments to be passed to 68 * bp_core_no_access() in case of no access. Note that this 69 * value is passed by reference, so it can be modified by the 70 * filter callback. 71 */ 72 $user_has_access = apply_filters_ref_array( 'bp_group_user_has_access', array( $user_has_access, &$no_access_args ) ); 73 74 // If user has access, we return rather than redirect 75 if ( $user_has_access ) { 76 return; 77 } 78 79 // Hidden groups should return a 404 for non-members. 80 // Unset the current group so that you're not redirected 81 // to the default group tab 82 if ( 'hidden' == $current_group->status ) { 83 buddypress()->groups->current_group = 0; 84 buddypress()->is_single_item = false; 85 bp_do_404(); 86 return; 87 } else { 88 bp_core_no_access( $no_access_args ); 89 } 90 91 } 92 add_action( 'bp_actions', 'bp_groups_group_access_protection' ); 16 93 17 94 /**
Note: See TracChangeset
for help on using the changeset viewer.