bp_attachments_current_user_can

Check the current user's capability to edit an avatar for a given object.

Description

bp_attachments_current_user_can( (string) $capability, (array) $args = array() ); 

Parameters (2)

0. $capability (string)
The capability to check.
1. $args — Optional. (array) => array()
An array containing the item_id and the object to check.

Usage

  1. if ( !function_exists( 'bp_attachments_current_user_can' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-attachments.php'; 
  3.  
  4. // The capability to check. 
  5. $capability = ''; 
  6.  
  7. // An array containing the item_id and the object to check. 
  8. $args = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_attachments_current_user_can($capability, $args); 
  12.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-attachments.php  
  1. function bp_attachments_current_user_can( $capability, $args = array() ) { 
  2. $can = false; 
  3.  
  4. if ( 'edit_avatar' === $capability || 'edit_cover_image' === $capability ) { 
  5. /** 
  6. * Needed avatar arguments are set. 
  7. */ 
  8. if ( isset( $args['item_id'] ) && isset( $args['object'] ) ) { 
  9. // Group profile photo. 
  10. if ( bp_is_active( 'groups' ) && 'group' === $args['object'] ) { 
  11. if ( bp_is_group_create() ) { 
  12. $can = (bool) groups_is_user_creator( bp_loggedin_user_id(), $args['item_id'] ) || bp_current_user_can( 'bp_moderate' ); 
  13. } else { 
  14. $can = (bool) groups_is_user_admin( bp_loggedin_user_id(), $args['item_id'] ) || bp_current_user_can( 'bp_moderate' ); 
  15. // User profile photo. 
  16. } elseif ( bp_is_active( 'xprofile' ) && 'user' === $args['object'] ) { 
  17. $can = bp_loggedin_user_id() === (int) $args['item_id'] || bp_current_user_can( 'bp_moderate' ); 
  18. /** 
  19. * No avatar arguments, fallback to bp_user_can_create_groups() 
  20. */ 
  21. } else { 
  22. if ( bp_is_group_create() ) { 
  23. } else { 
  24. $can = bp_is_item_admin(); 
  25.  
  26. return apply_filters( 'bp_attachments_current_user_can', $can, $capability, $args );