Broadcast offers several actions which can be hooked into. All actions are based off of the Plainview SDK’s WordPress Action class, which means that the parameter is an object that is passed around.
All of the actions can be found in the src/actions directory. The name of the actions are prefixed with threewp_broadcast_. For example, the file src/actions/broadcasting_started.php provides the threewp_broadcast_broadcasting_started action.
The source code of the actions themselves should be documented enough to be self-explanatory.
Finish
The Action class offers two methods that could / should be used to signal to hooks that the action has been fully applied / completed / finished.
$action->finish();
and
$action->is_finished();
Generally, if an executed action modifies something, after which no other hook should do anything, call the finish() method. Logically, when receiving the action yourself, check is_finished().
Question: how would you recommend modifying the post status of broadcast posts only during their initial broadcasting? Our goal is to make all child posts ‘pending’ when they’re broadcast so that child site admins can choose which posts they want to appear on their site. They would then need to be able to publish posts or leave as pending without impacting the parent posts.
We’re currently playing around with the ‘threewp_broadcast_broadcasting_after_update_post’ hook, but having issues determining when a post is being broadcast for the first time or if it’s an update.
I’d have a look at the broadcasting_after_switch_to_blog action, together with the $bcd->new_post_created attribute. :)
See broadcast / src / traits / broadcasting, at about line 322.
If a new post was created, modify the $bcd->new_post->post_status.
The thing is, we can’t seem to get ‘new_child_created’ to ever be true. Any thoughts on what’s up? Here’s the code we’re using. $bcd->new_post_created always seems to be false, no matter how we create/broadcast our posts in the admin.
function broadcast_change_status( $action ) {
$bcd = $action->broadcasting_data;
if( $bcd->new_post_created ):
$bcd->new_post->post_status = ‘pending’;
$action->set_post_status( $bcd->new_post( ‘ID’ ), $bcd->new_post->post_status );
endif;
}
add_action( ‘threewp_broadcast_broadcasting_after_update_post’, ‘broadcast_change_status’ );
function broadcast_change_status( $action ) {
$bcd = $action->broadcasting_data;
if( $bcd->new_child_created ):
$bcd->new_post->post_status = ‘pending’;
wp_update_post($bcd->new_post);
endif;
}
add_action( ‘threewp_broadcast_broadcasting_after_update_post’, ‘broadcast_change_status’ );
I am unsure which action is better to use each_linked_post or trash_untrash_delete_post? and more importantly how to even use these methods.
Try this simpler code on the parent post:
$api = ThreeWP_Broadcast()->api();
$api->delete_children( $post_id );