This snippet for Broadcast shows how to prevent broadcasting to a blog depending on child blog ID and WPML language.
add_action( 'threewp_broadcast_broadcasting_after_switch_to_blog', 'my_threewp_broadcast_broadcasting_after_switch_to_blog', 100 );
/**
@brief Prevent a post from being broadcasted depending on child blog and language.
@since 2018-03-01 16:25:22
**/
function my_threewp_broadcast_broadcasting_after_switch_to_blog( $action )
{
// CONFIG STARTS
// -------------
/**
@brief These are blog IDs to which never to broadcast.
@since 2018-03-01 16:26:39
**/
$blog_ids_to_ignore = [
82,
533,
];
/**
@brief For WPML: These are the languages that are not to be broadcasted ever.
@since 2018-03-01 16:26:13
**/
$languages_to_ignore = [
'de', // Always ignore German posts
'fr', // Always ignore French posts
];
/**
@brief For WPML: These are language => blog_id languages to not broadcast.
@since 2018-03-01 16:27:30
**/
$blog_languages_to_ignore = [
'af' => [ 25, 98, 662 ], // Ignore Afrikaans to blogs 25, 98 and 663
'hu' => [ 45 ], // Ignore Hungarian to blog 45
];
// CONFIG ENDS
// -----------
// Are we on a blog to ignore?
if ( in_array( get_current_blog_id(), $blog_ids_to_ignore ) )
{
$action->broadcast_here = false;
return ThreeWP_Broadcast()->debug( 'Ignoring this blog due to blog_ids_to_ignore.' );
}
$bcd = $action->broadcasting_data;
// Is WPML installed?
if ( ! isset( $bcd->wpml ) )
return;
// Check whether we should ignore this language.
if ( in_array( $bcd->wpml->language, $languages_to_ignore ) )
{
$action->broadcast_here = false;
return ThreeWP_Broadcast()->debug( 'Ignoring this blog due to languages_to_ignore.' );
}
// And now the language / blog combo.
if ( isset( $blog_languages_to_ignore[ $bcd->wpml->language ] ) )
{
// Convenience.
$blog_ids = $blog_languages_to_ignore[ $bcd->wpml->language ];
if ( in_array( get_current_blog_id(), $blog_ids ) )
{
$action->broadcast_here = false;
return ThreeWP_Broadcast()->debug( 'Ignoring this blog due to language %s and blog %d.',
$bcd->wpml->language,
get_current_blog_id()
);
}
}
// We've gotten this far. Good to go! No changes needed to $broadcasting_data.
}