bp_activity_action_delete_activity

Delete specific activity item and redirect to previous page.

Description

bp_activity_action_delete_activity( (int) $activity_id = 0 ); 

Parameters (1)

0. $activity_id — Optional. (int)
Activity id to be deleted. Defaults to 0.

Usage

  1. if ( !function_exists( 'bp_activity_action_delete_activity' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-actions.php'; 
  3.  
  4. // Activity id to be deleted. Defaults to 0. 
  5. $activity_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_activity_action_delete_activity($activity_id); 
  9.  

Defined (1)

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

/bp-activity/bp-activity-actions.php  
  1. function bp_activity_action_delete_activity( $activity_id = 0 ) { 
  2.  
  3. // Not viewing activity or action is not delete. 
  4. if ( !bp_is_activity_component() || !bp_is_current_action( 'delete' ) ) 
  5. return false; 
  6.  
  7. if ( empty( $activity_id ) && bp_action_variable( 0 ) ) 
  8. $activity_id = (int) bp_action_variable( 0 ); 
  9.  
  10. // Not viewing a specific activity item. 
  11. if ( empty( $activity_id ) ) 
  12. return false; 
  13.  
  14. // Check the nonce. 
  15. check_admin_referer( 'bp_activity_delete_link' ); 
  16.  
  17. // Load up the activity item. 
  18. $activity = new BP_Activity_Activity( $activity_id ); 
  19.  
  20. // Check access. 
  21. if ( ! bp_activity_user_can_delete( $activity ) ) 
  22. return false; 
  23.  
  24. /** 
  25. * Fires before the deletion so plugins can still fetch information about it. 
  26. * @since 1.5.0 
  27. * @param int $activity_id The activity ID. 
  28. * @param int $user_id The user associated with the activity. 
  29. */ 
  30. do_action( 'bp_activity_before_action_delete_activity', $activity_id, $activity->user_id ); 
  31.  
  32. // Delete the activity item and provide user feedback. 
  33. if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) ) 
  34. bp_core_add_message( __( 'Activity deleted successfully', buddypress ) ); 
  35. else 
  36. bp_core_add_message( __( 'There was anerrorwhen deleting that activity', buddypress ), error ); 
  37.  
  38. /** 
  39. * Fires after the deletion so plugins can act afterwards based on the activity. 
  40. * @since 1.1.0 
  41. * @param int $activity_id The activity ID. 
  42. * @param int $user_id The user associated with the activity. 
  43. */ 
  44. do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id ); 
  45.  
  46. // Check for the redirect query arg, otherwise let WP handle things. 
  47. if ( !empty( $_GET['redirect_to'] ) ) 
  48. bp_core_redirect( esc_url( $_GET['redirect_to'] ) ); 
  49. else