bp_activity_post_type_unpublish

Unpublish an activity for the custom post type.

Description

bp_activity_post_type_unpublish( (int) $post_id = 0, (null) $post = null ); 

Parameters (2)

0. $post_id — Optional. (int)
ID of the post being unpublished.
1. $post — Optional. (null) => null
Post object.

Usage

  1. if ( !function_exists( 'bp_activity_post_type_unpublish' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-functions.php'; 
  3.  
  4. // ID of the post being unpublished. 
  5. $post_id = -1; 
  6.  
  7. // Post object. 
  8. $post = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_activity_post_type_unpublish($post_id, $post); 
  12.  

Defined (1)

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

/bp-activity/bp-activity-functions.php  
  1. function bp_activity_post_type_unpublish( $post_id = 0, $post = null ) { 
  2.  
  3. if ( ! is_a( $post, 'WP_Post' ) ) { 
  4. return; 
  5.  
  6. // Get the post type tracking args. 
  7. $activity_post_object = bp_activity_get_post_type_tracking_args( $post->post_type ); 
  8.  
  9. if ( empty( $activity_post_object->action_id ) ) { 
  10. return; 
  11.  
  12. if ( empty( $post_id ) ) { 
  13. $post_id = $post->ID; 
  14.  
  15. $delete_activity_args = array( 
  16. 'item_id' => get_current_blog_id(),  
  17. 'secondary_item_id' => $post_id,  
  18. 'component' => $activity_post_object->component_id,  
  19. 'type' => $activity_post_object->action_id,  
  20. 'user_id' => false,  
  21. ); 
  22.  
  23. $deleted = bp_activity_delete_by_item_id( $delete_activity_args ); 
  24.  
  25. /** 
  26. * Fires after the unpublishing for the custom post type. 
  27. * @since 2.2.0 
  28. * @param array $delete_activity_args Array of arguments for activity deletion. 
  29. * @param WP_Post $post Post object. 
  30. * @param bool $activity Whether or not the activity was successfully deleted. 
  31. */ 
  32. do_action( 'bp_activity_post_type_unpublished', $delete_activity_args, $post, $deleted ); 
  33.  
  34. return $deleted;