bp_activity_catch_transition_post_type_status( string $new_status, string $old_status, object $post )
Detect a change in post type status, and initiate an activity update if necessary.
Description
Parameters
- $new_status
-
(Required) New status for the post.
- $old_status
-
(Required) Old status for the post.
- $post
-
(Required) Post data.
Source
File: bp-activity/bp-activity-functions.php
function bp_activity_catch_transition_post_type_status( $new_status, $old_status, $post ) { if ( ! post_type_supports( $post->post_type, 'buddypress-activity' ) ) { return; } // This is an edit. if ( $new_status === $old_status ) { // An edit of an existing post should update the existing activity item. if ( $new_status == 'publish' ) { $edit = bp_activity_post_type_update( $post ); // Post was never recorded into activity feed, so record it now! if ( null === $edit ) { bp_activity_post_type_publish( $post->ID, $post ); } // Allow plugins to eventually deal with other post statuses. } else { /** * Fires when editing the post and the new status is not 'publish'. * * This is a variable filter that is dependent on the post type * being untrashed. * * @since BuddyPress 2.5.0 * * @param WP_Post $post Post data. * @param string $new_status New status for the post. * @param string $old_status Old status for the post. */ do_action( 'bp_activity_post_type_edit_' . $post->post_type, $post, $new_status, $old_status ); } return; } // Publishing a previously unpublished post. if ( 'publish' === $new_status ) { // Untrashing the post type - nothing here yet. if ( 'trash' == $old_status ) { /** * Fires if untrashing post in a post type. * * This is a variable filter that is dependent on the post type * being untrashed. * * @since BuddyPress 2.2.0 * * @param WP_Post $post Post data. */ do_action( 'bp_activity_post_type_untrash_' . $post->post_type, $post ); } else { // Record the post. bp_activity_post_type_publish( $post->ID, $post ); } // Unpublishing a previously published post. } elseif ( 'publish' === $old_status ) { // Some form of pending status - only remove the activity entry. bp_activity_post_type_unpublish( $post->ID, $post ); // For any other cases, allow plugins to eventually deal with it. } else { /** * Fires when the old and the new post status are not 'publish'. * * This is a variable filter that is dependent on the post type * being untrashed. * * @since BuddyPress 2.5.0 * * @param WP_Post $post Post data. * @param string $new_status New status for the post. * @param string $old_status Old status for the post. */ do_action( 'bp_activity_post_type_transition_status_' . $post->post_type, $post, $new_status, $old_status ); } }
Changelog
Version | Description |
---|---|
BuddyPress 2.2.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.