This snippet for Broadcast will broadcast an imported post if instructed to do so using a specific custom field.
In the import file, add a column called “broadcast_to”. In that column you can specify blog IDs to which the post should be broadcasted during import.
/**
@brief Broadcast an imported post to the blogs specified in the broadcast_to custom field.
@details The blogs can be separated by commas or spaces.
@since 2019-08-09 12:14:15
**/
function bc_pmxi_saved_post( $post_id )
{
// Retrieve the broadcast_to meta.
$broadcast_to = get_post_meta( $post_id, 'broadcast_to', true );
if ( ! $broadcast_to )
return;
// Convert all commas to spaces
$broadcast_to = str_replace( ',', ' ', $broadcast_to );
// And break out the numbers.
$blogs = explode( ' ', $broadcast_to );
// Clean up the array.
$blogs = array_filter( $blogs );
// And broadcast!
ThreeWP_Broadcast()->api()
->low_priority()
->broadcast_children( $post_id, $blogs );
}
add_action( 'pmxi_saved_post', 'bc_pmxi_saved_post' );