Set broadcast info custom fields

This snippet for Broadcast sets custom fields on the parent and child posts that contain broadcasted from / to information.

The custom fields can then be filtered using a WP_Query.

/**
	@brief		This will delete the broadcasted_to custom field so that it is not propagated to the children.
	@since		2021-08-13 22:05:09
**/
add_action( 'threewp_broadcast_broadcasting_started', function( $action )
{
    $bcd = $action->broadcasting_data;
    $key = 'broadcasted_to';
    ThreeWP_Broadcast()->debug( 'Deleting custom field %s', $key );
    $bcd->custom_fields()->forget( $key );
    delete_post_meta( $bcd->post->ID, $key );
} );

/**
	@brief		This sets the broadcasted_from_blog_id and broadcasted_from_post_id custom fields on each child.
	@since		2021-08-13 22:13:32
**/
add_action( 'threewp_broadcast_broadcasting_before_restore_current_blog', function( $action )
{
	$bcd = $action->broadcasting_data;
	$new_post_id = $bcd->new_post( 'ID' );
	$bcd->custom_fields()
		->child_fields()
		->update_meta( 'broadcasted_from_blog_id', $bcd->broadcast_data->blog_id )
		->update_meta( 'broadcasted_from_post_id', $bcd->broadcast_data->post_id );
} );

/**
	@brief		This sets the broadcasted_to custom field on the parent.
	@since		2021-08-13 22:05:26
**/
add_action( 'threewp_broadcast_broadcasting_finished', function( $action )
{
    $bcd = $action->broadcasting_data;
    $key = 'broadcasted_to';
    $bcd->custom_fields()->forget( $key );

    // Add a custom field to this parent.
    $broadcasted_to = $bcd->broadcast_data->get_linked_children();
    ThreeWP_Broadcast()->debug( 'Setting %s custom field to %s', $key, $broadcasted_to );
    delete_post_meta( $bcd->post->ID, $key );
    update_post_meta( $bcd->post->ID, $key, $broadcasted_to );
} );