Changeset 11776
- Timestamp:
- 12/14/2017 01:24:01 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/bp-groups-actions.php
r11763 r11776 421 421 422 422 // User wants to join a group that is not public. 423 if ( $bp->groups->current_group->status != 'public') {423 if ( bp_current_user_can( 'groups_join_group', array( 'group_id' => $bp->groups->current_group->id ) ) ) { 424 424 if ( !groups_check_user_has_invite( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) { 425 425 bp_core_add_message( __( 'There was an error joining the group.', 'buddypress' ), 'error' ); -
trunk/src/bp-groups/bp-groups-filters.php
r11764 r11776 159 159 } 160 160 161 if ( 'groups' === $activity->component ) { 162 $group = groups_get_group( $activity->item_id ); 163 if ( 'public' !== $group->status && ! groups_is_user_member( $user_id, $group->id ) ) { 164 $send = false; 165 } 161 if ( 'groups' === $activity->component && ! bp_user_can( $user_id, 'groups_access_group', array( 'group_id' => $activity->item_id ) ) ) { 162 $send = false; 166 163 } 167 164 … … 191 188 return $avatar; 192 189 } 190 191 /** 192 * Filter the bp_user_can value to determine what the user can do 193 * with regards to a specific group. 194 * 195 * @since 3.0.0 196 * 197 * @param bool $retval Whether or not the current user has the capability. 198 * @param int $user_id 199 * @param string $capability The capability being checked for. 200 * @param int $site_id Site ID. Defaults to the BP root blog. 201 * @param array $args Array of extra arguments passed. 202 * 203 * @return bool 204 */ 205 function bp_groups_user_can_filter( $retval, $user_id, $capability, $site_id, $args ) { 206 if ( empty( $args['group_id'] ) ) { 207 $group_id = bp_get_current_group_id(); 208 } else { 209 $group_id = (int) $args['group_id']; 210 } 211 212 switch ( $capability ) { 213 case 'groups_join_group': 214 // Return early if the user isn't logged in or the group ID is unknown. 215 if ( ! $user_id || ! $group_id ) { 216 break; 217 } 218 219 // The group must allow joining, and the user should not currently be a member. 220 $group = groups_get_group( $group_id ); 221 if ( 'public' === bp_get_group_status( $group ) 222 && ! groups_is_user_member( $user_id, $group->id ) 223 && ! groups_is_user_banned( $user_id, $group->id ) 224 ) { 225 $retval = true; 226 } 227 break; 228 229 case 'groups_request_membership': 230 // Return early if the user isn't logged in or the group ID is unknown. 231 if ( ! $user_id || ! $group_id ) { 232 break; 233 } 234 235 /* 236 * The group must accept membership requests, and the user should not 237 * currently be a member, have an active request, or be banned. 238 */ 239 $group = groups_get_group( $group_id ); 240 if ( 'private' === bp_get_group_status( $group ) 241 && ! groups_is_user_member( $user_id, $group->id ) 242 && ! groups_check_for_membership_request( $user_id, $group->id ) 243 && ! groups_is_user_banned( $user_id, $group->id ) 244 ) { 245 $retval = true; 246 } 247 break; 248 249 case 'groups_send_invitation': 250 // Return early if the user isn't logged in or the group ID is unknown. 251 if ( ! $user_id || ! $group_id ) { 252 break; 253 } 254 255 /* 256 * The group must allow invitations, and the user should not 257 * currently be a member or be banned from the group. 258 */ 259 $group = groups_get_group( $group_id ); 260 // Users with the 'bp_moderate' cap can always send invitations. 261 if ( bp_user_can( $user_id, 'bp_moderate' ) ) { 262 $retval = true; 263 } else { 264 $invite_status = bp_group_get_invite_status( $group_id ); 265 266 switch ( $invite_status ) { 267 case 'admins' : 268 if ( groups_is_user_admin( $user_id, $group_id ) ) { 269 $retval = true; 270 } 271 break; 272 273 case 'mods' : 274 if ( groups_is_user_mod( $user_id, $group_id ) || groups_is_user_admin( $user_id, $group_id ) ) { 275 $retval = true; 276 } 277 break; 278 279 case 'members' : 280 if ( groups_is_user_member( $user_id, $group_id ) ) { 281 $retval = true; 282 } 283 break; 284 } 285 } 286 break; 287 288 case 'groups_receive_invitation': 289 // Return early if the user isn't logged in or the group ID is unknown. 290 if ( ! $user_id || ! $group_id ) { 291 break; 292 } 293 294 /* 295 * The group must allow invitations, and the user should not 296 * currently be a member or be banned from the group. 297 */ 298 $group = groups_get_group( $group_id ); 299 if ( in_array( bp_get_group_status( $group ), array( 'private', 'hidden' ), true ) 300 && ! groups_is_user_member( $user_id, $group->id ) 301 && ! groups_is_user_banned( $user_id, $group->id ) 302 ) { 303 $retval = true; 304 } 305 break; 306 307 case 'groups_access_group': 308 // Return early if the group ID is unknown. 309 if ( ! $group_id ) { 310 break; 311 } 312 313 $group = groups_get_group( $group_id ); 314 315 // If the check is for the logged-in user, use the BP_Groups_Group property. 316 if ( $user_id === bp_loggedin_user_id() ) { 317 $retval = $group->user_has_access; 318 319 /* 320 * If the check is for a specified user who is not the logged-in user 321 * run the check manually. 322 */ 323 } elseif ( 'public' === bp_get_group_status( $group ) || groups_is_user_member( $user_id, $group->id ) ) { 324 $retval = true; 325 } 326 break; 327 328 case 'groups_see_group': 329 // Return early if the group ID is unknown. 330 if ( ! $group_id ) { 331 break; 332 } 333 334 $group = groups_get_group( $group_id ); 335 336 // If the check is for the logged-in user, use the BP_Groups_Group property. 337 if ( $user_id === bp_loggedin_user_id() ) { 338 $retval = $group->is_visible; 339 340 /* 341 * If the check is for a specified user who is not the logged-in user 342 * run the check manually. 343 */ 344 } elseif ( 'hidden' !== bp_get_group_status( $group ) || groups_is_user_member( $user_id, $group->id ) ) { 345 $retval = true; 346 } 347 break; 348 } 349 350 return $retval; 351 352 } 353 add_filter( 'bp_user_can', 'bp_groups_user_can_filter', 10, 5 ); -
trunk/src/bp-groups/bp-groups-template.php
r11763 r11776 2186 2186 2187 2187 if ( $user_id ) { 2188 // Users with the 'bp_moderate' cap can always send invitations. 2189 if ( bp_user_can( $user_id, 'bp_moderate' ) ) { 2190 $can_send_invites = true; 2191 } else { 2192 $invite_status = bp_group_get_invite_status( $group_id ); 2193 2194 switch ( $invite_status ) { 2195 case 'admins' : 2196 if ( groups_is_user_admin( $user_id, $group_id ) ) { 2197 $can_send_invites = true; 2198 } 2199 break; 2200 2201 case 'mods' : 2202 if ( groups_is_user_mod( $user_id, $group_id ) || groups_is_user_admin( $user_id, $group_id ) ) { 2203 $can_send_invites = true; 2204 } 2205 break; 2206 2207 case 'members' : 2208 if ( groups_is_user_member( $user_id, $group_id ) ) { 2209 $can_send_invites = true; 2210 } 2211 break; 2212 } 2213 } 2188 $can_send_invites = bp_user_can( $user_id, 'groups_send_invitation', array( 'group_id' => $group_id ) ); 2214 2189 } 2215 2190 -
trunk/src/bp-groups/classes/class-bp-groups-component.php
r11763 r11776 544 544 // member and does not have an outstanding invitation, 545 545 // show a "Request Membership" nav item. 546 if ( is_user_logged_in() && 547 ! $this->current_group->is_member && 548 ! groups_check_for_membership_request( bp_loggedin_user_id(), $this->current_group->id ) && 549 $this->current_group->status == 'private' && 550 ! groups_check_user_has_invite( bp_loggedin_user_id(), $this->current_group->id ) 551 ) { 546 if ( bp_current_user_can( 'groups_request_membership', array( 'group_id' => $this->current_group->id ) ) ) { 552 547 553 548 $sub_nav[] = array( -
trunk/src/bp-templates/bp-legacy/buddypress-functions.php
r11773 r11776 1493 1493 1494 1494 if ( ! groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) { 1495 if ( 'public' == $group->status) {1495 if ( bp_current_user_can( 'groups_join_group', array( 'group_id' => $group->id ) ) ) { 1496 1496 check_ajax_referer( 'groups_join_group' ); 1497 1497 … … 1502 1502 } 1503 1503 1504 } elseif ( 'private' == $group->status) {1504 } elseif ( bp_current_user_can( 'groups_request_membership', array( 'group_id' => $group->id ) ) ) { 1505 1505 1506 1506 // If the user has already been invited, then this is … … 1532 1532 if ( ! groups_leave_group( $group->id ) ) { 1533 1533 _e( 'Error leaving group', 'buddypress' ); 1534 } elseif ( 'public' == $group->status) {1534 } elseif ( bp_current_user_can( 'groups_join_group', array( 'group_id' => $group->id ) ) ) { 1535 1535 echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button join-group" rel="join" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'join', 'groups_join_group' ) . '">' . __( 'Join Group', 'buddypress' ) . '</a>'; 1536 } elseif ( 'private' == $group->status) {1536 } elseif ( bp_current_user_can( 'groups_request_membership', array( 'group_id' => $group->id ) ) ) { 1537 1537 echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button request-membership" rel="join" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'request-membership', 'groups_request_membership' ) . '">' . __( 'Request Membership', 'buddypress' ) . '</a>'; 1538 1538 }
Note: See TracChangeset
for help on using the changeset viewer.