/** * @group bp_activity_catch_transition_post_type_status * @group activity_tracking */ public function test_bp_activity_catch_transition_post_type_status_publish_to_publish() { $bp = buddypress(); register_post_type('foo', array('label' => 'foo', 'public' => true, 'supports' => array('buddypress-activity'))); $post_id = $this->factory->post->create(array('post_status' => 'publish', 'post_type' => 'foo')); $post = get_post($post_id); // 'new' => 'publish' $this->assertTrue($this->activity_exists_for_post($post_id, 'new_foo'), 'Published post type should have activity'); // Delete the activity bp_activity_post_type_unpublish($post_id, $post); $post->post_status = 'publish'; $post->post_content .= ' foo'; wp_update_post($post); $this->assertFalse($this->activity_exists_for_post($post_id, 'new_foo'), 'Updating a post type should not create a new activity'); _unregister_post_type('foo'); // Reset globals unset($bp->activity->actions->activity->new_foo); $bp->activity->track = array(); }
/** * Detect a change in post type status, and initiate an activity update if necessary. * * @since 2.2.0 * * @todo Support untrashing better. * * @param string $new_status New status for the post. * @param string $old_status Old status for the post. * @param object $post Post data. */ 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') { bp_activity_post_type_update($post); } 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 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); } }
/** * Detect a change in post type status, and initiate an activity update if necessary. * * @since 2.2.0 * * @todo Support untrashing better. * * @param string $new_status New status for the post. * @param string $old_status Old status for the post. * @param object $post Post data. */ 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 stream, 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 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 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 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); } }