Ticket #4785: 4785.02.patch
File 4785.02.patch, 6.6 KB (added by , 10 years ago) |
---|
-
bp-groups/bp-groups-actions.php
diff --git bp-groups/bp-groups-actions.php bp-groups/bp-groups-actions.php index b81d244..1e54d80 100644
15 15 if ( !defined( 'ABSPATH' ) ) exit; 16 16 17 17 /** 18 * Protect access to single groups. 19 * 20 * @since BuddyPress (2.0.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 { 38 if ( is_user_logged_in() ) { 39 $no_access_args = array( 40 'message' => __( 'You do not have access to this group.', 'buddypress' ), 41 'root' => bp_get_group_permalink( $current_group ) . 'home/', 42 'redirect' => false 43 ); 44 } 45 } 46 } 47 48 // Protect the admin tab from non-admins 49 if ( bp_is_current_action( 'admin' ) && ! bp_is_item_admin() ) { 50 $user_has_access = false; 51 $no_access_args = array( 52 'message' => __( 'You are not an admin of this group.', 'buddypress' ), 53 'root' => bp_get_group_permalink( $current_group ), 54 'redirect' => false 55 ); 56 } 57 58 $user_has_access = apply_filters( 'bp_group_user_has_access', $user_has_access ); 59 60 if ( $user_has_access ) { 61 return; 62 } 63 64 // Hidden groups should return a 404 for non-members. 65 // Unset the current group so that you're not redirected 66 // to the default group tab 67 if ( 'hidden' == $current_group->status ) { 68 buddypress()->groups->current_group = 0; 69 buddypress()->is_single_item = false; 70 bp_do_404(); 71 return; 72 } else { 73 bp_core_no_access( $no_access_args ); 74 } 75 } 76 add_action( 'bp_actions', 'bp_groups_group_access_protection' ); 77 78 /** 18 79 * Catch and process group creation form submissions. 19 80 */ 20 81 function groups_action_create_group() { … … function groups_action_leave_group() { 281 342 } else { 282 343 bp_core_add_message( __( 'You successfully left the group.', 'buddypress' ) ); 283 344 } 284 345 285 346 $redirect = bp_get_group_permalink( groups_get_current_group() ); 286 347 287 348 if( 'hidden' == $bp->groups->current_group->status ) { 288 349 $redirect = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ); 289 350 } -
bp-groups/bp-groups-classes.php
diff --git bp-groups/bp-groups-classes.php bp-groups/bp-groups-classes.php index 95e102e..560815f 100644
class BP_Group_Extension { 2983 2983 'display_hook' => $this->display_hook, 2984 2984 'template_file' => $this->template_file, 2985 2985 'screens' => $this->get_default_screens(), 2986 'access' => array( 2987 'public' => 'anyone', 2988 'private' => 'members', 2989 'hidden' => 'members', 2990 ), 2986 2991 ) ); 2987 2992 2988 2993 $this->initialized = true; … … class BP_Group_Extension { 3177 3182 3178 3183 // When we are viewing the extension display page, set the title and options title 3179 3184 if ( bp_is_current_action( $this->slug ) ) { 3185 add_filter( 'bp_group_user_has_access', array( $this, 'user_has_access' ) ); 3180 3186 add_action( 'bp_template_content_header', create_function( '', 'echo "' . esc_attr( $this->name ) . '";' ) ); 3181 3187 add_action( 'bp_template_title', create_function( '', 'echo "' . esc_attr( $this->name ) . '";' ) ); 3182 3188 } … … class BP_Group_Extension { 3196 3202 bp_core_load_template( apply_filters( 'bp_core_template_plugin', $this->template_file ) ); 3197 3203 } 3198 3204 3205 /** 3206 * Determine whether the current user has access to this tab. 3207 * 3208 * @since BuddyPress (2.0.0) 3209 * 3210 * @return bool 3211 */ 3212 protected function user_has_access( $user_has_access ) { 3213 if ( current_user_can( 'bp_moderate' ) ) { 3214 return true; 3215 } 3216 3217 $group = groups_get_group( array( 3218 'group_id' => $this->group_id, 3219 ) ); 3220 3221 $access_setting = ''; 3222 if ( isset( $this->params['access'][ $group->status ] ) ) { 3223 $access_setting = $this->params['access'][ $group->status ]; 3224 } 3225 3226 switch ( $access_setting ) { 3227 case 'admins' : 3228 $user_has_access = groups_is_user_admin( bp_loggedin_user_id(), $this->group_id ); 3229 break; 3230 3231 case 'mods' : 3232 $user_has_access = groups_is_user_mod( bp_loggedin_user_id(), $this->group_id ); 3233 break; 3234 3235 case 'members' : 3236 $user_has_access = groups_is_user_member( bp_loggedin_user_id(), $this->group_id ); 3237 break; 3238 3239 case 'loggedin' : 3240 $user_has_access = is_user_logged_in(); 3241 break; 3242 } 3243 3244 return $user_has_access; 3245 } 3246 3199 3247 /** Create ************************************************************/ 3200 3248 3201 3249 /** -
bp-groups/bp-groups-loader.php
diff --git bp-groups/bp-groups-loader.php bp-groups/bp-groups-loader.php index b40bf45..b19d196 100644
class BP_Groups_Component extends BP_Component { 268 268 269 269 } 270 270 271 // Group access control272 if ( bp_is_groups_component() && !empty( $this->current_group ) ) {273 if ( !$this->current_group->user_has_access ) {274 275 // Hidden groups should return a 404 for non-members.276 // Unset the current group so that you're not redirected277 // to the default group tab278 if ( 'hidden' == $this->current_group->status ) {279 $this->current_group = 0;280 $bp->is_single_item = false;281 bp_do_404();282 return;283 284 // Skip the no_access check on home and membership request pages285 } elseif ( !bp_is_current_action( 'home' ) && !bp_is_current_action( 'request-membership' ) ) {286 287 // Off-limits to this user. Throw an error and redirect to the group's home page288 if ( is_user_logged_in() ) {289 bp_core_no_access( array(290 'message' => __( 'You do not have access to this group.', 'buddypress' ),291 'root' => bp_get_group_permalink( $bp->groups->current_group ) . 'home/',292 'redirect' => false293 ) );294 295 // User does not have access, and does not get a message296 } else {297 bp_core_no_access();298 }299 }300 }301 302 // Protect the admin tab from non-admins303 if ( bp_is_current_action( 'admin' ) && !bp_is_item_admin() ) {304 bp_core_no_access( array(305 'message' => __( 'You are not an admin of this group.', 'buddypress' ),306 'root' => bp_get_group_permalink( $bp->groups->current_group ),307 'redirect' => false308 ) );309 }310 }311 312 271 // Preconfigured group creation steps 313 272 $this->group_creation_steps = apply_filters( 'groups_create_group_steps', array( 314 273 'group-details' => array(