bp_activity_catch_transition_post_type_status

Detect a change in post type status, and initiate an activity update if necessary.

Description

bp_activity_catch_transition_post_type_status( (string) $new_status, (string) $old_status, (object) $post ); 

Parameters (3)

0. $new_status (string)
New status for the post.
1. $old_status (string)
Old status for the post.
2. $post (object)
Post data.

Usage

  1. if ( !function_exists( 'bp_activity_catch_transition_post_type_status' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-actions.php'; 
  3.  
  4. // New status for the post. 
  5. $new_status = ''; 
  6.  
  7. // Old status for the post. 
  8. $old_status = ''; 
  9.  
  10. // Post data. 
  11. $post = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bp_activity_catch_transition_post_type_status($new_status, $old_status, $post); 
  15.  

Defined (1)

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

/bp-activity/bp-activity-actions.php  
  1. function bp_activity_catch_transition_post_type_status( $new_status, $old_status, $post ) { 
  2. if ( ! post_type_supports( $post->post_type, 'buddypress-activity' ) ) { 
  3. return; 
  4.  
  5. // This is an edit. 
  6. if ( $new_status === $old_status ) { 
  7. // An edit of an existing post should update the existing activity item. 
  8. if ( $new_status == 'publish' ) { 
  9. $edit = bp_activity_post_type_update( $post ); 
  10.  
  11. // Post was never recorded into activity stream, so record it now! 
  12. if ( null === $edit ) { 
  13. bp_activity_post_type_publish( $post->ID, $post ); 
  14.  
  15. // Allow plugins to eventually deal with other post statuses. 
  16. } else { 
  17. /** 
  18. * Fires when editing the post and the new status is not 'publish'. 
  19. * This is a variable filter that is dependent on the post type 
  20. * being untrashed. 
  21. * @since 2.5.0 
  22. * @param WP_Post $post Post data. 
  23. * @param string $new_status New status for the post. 
  24. * @param string $old_status Old status for the post. 
  25. */ 
  26. do_action( 'bp_activity_post_type_edit_' . $post->post_type, $post, $new_status, $old_status ); 
  27.  
  28. return; 
  29.  
  30. // Publishing a previously unpublished post. 
  31. if ( 'publish' === $new_status ) { 
  32. // Untrashing the post type - nothing here yet. 
  33. if ( 'trash' == $old_status ) { 
  34.  
  35. /** 
  36. * Fires if untrashing post in a post type. 
  37. * This is a variable filter that is dependent on the post type 
  38. * being untrashed. 
  39. * @since 2.2.0 
  40. * @param WP_Post $post Post data. 
  41. */ 
  42. do_action( 'bp_activity_post_type_untrash_' . $post->post_type, $post ); 
  43. } else { 
  44. // Record the post. 
  45. bp_activity_post_type_publish( $post->ID, $post ); 
  46.  
  47. // Unpublishing a previously published post. 
  48. } elseif ( 'publish' === $old_status ) { 
  49. // Some form of pending status - only remove the activity entry. 
  50. bp_activity_post_type_unpublish( $post->ID, $post ); 
  51.  
  52. // For any other cases, allow plugins to eventually deal with it. 
  53. } else { 
  54. /** 
  55. * Fires when the old and the new post status are not 'publish'. 
  56. * This is a variable filter that is dependent on the post type 
  57. * being untrashed. 
  58. * @since 2.5.0 
  59. * @param WP_Post $post Post data. 
  60. * @param string $new_status New status for the post. 
  61. * @param string $old_status Old status for the post. 
  62. */ 
  63. do_action( 'bp_activity_post_type_transition_status_' . $post->post_type, $post, $new_status, $old_status );