bp_activity_user_can_delete

Determine if the current user can delete an activity item.

Description

bp_activity_user_can_delete( (bool) $activity = false ); 

Parameters (1)

0. $activity — Optional. (bool) => false
Falls back on the current item in the loop.

Usage

  1. if ( !function_exists( 'bp_activity_user_can_delete' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-template.php'; 
  3.  
  4. // Optional. Falls back on the current item in the loop. 
  5. $activity = false; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_activity_user_can_delete($activity); 
  9.  

Defined (1)

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

/bp-activity/bp-activity-template.php  
  1. function bp_activity_user_can_delete( $activity = false ) { 
  2. global $activities_template; 
  3.  
  4. // Try to use current activity if none was passed. 
  5. if ( empty( $activity ) && ! empty( $activities_template->activity ) ) { 
  6. $activity = $activities_template->activity; 
  7.  
  8. // If current_comment is set, we'll use that in place of the main activity. 
  9. if ( isset( $activity->current_comment ) ) { 
  10. $activity = $activity->current_comment; 
  11.  
  12. // Assume the user cannot delete the activity item. 
  13. $can_delete = false; 
  14.  
  15. // Only logged in users can delete activity. 
  16. if ( is_user_logged_in() ) { 
  17.  
  18. // Community moderators can always delete activity (at least for now). 
  19. if ( bp_current_user_can( 'bp_moderate' ) ) { 
  20. $can_delete = true; 
  21.  
  22. // Users are allowed to delete their own activity. This is actually 
  23. // quite powerful, because doing so also deletes all comments to that 
  24. // activity item. We should revisit this eventually. 
  25. if ( isset( $activity->user_id ) && ( $activity->user_id === bp_loggedin_user_id() ) ) { 
  26. $can_delete = true; 
  27.  
  28. // Viewing a single item, and this user is an admin of that item. 
  29. $can_delete = true; 
  30.  
  31. /** 
  32. * Filters whether the current user can delete an activity item. 
  33. * @since 1.5.0 
  34. * @param bool $can_delete Whether the user can delete the item. 
  35. * @param object $activity Current activity item object. 
  36. */ 
  37. return (bool) apply_filters( 'bp_activity_user_can_delete', $can_delete, $activity );