I found a better solution a notification when a new article is created and visible to all
add_filter( 'um_notifications_core_log_types', 'add_new_article_notification_type', 200 );
function add_new_article_notification_type( $array ) {
$array['new_article'] = array(
'title' => 'Nouvel article publié',
'template' => 'Un nouvel article intitulé "{article_title}" a été publié par {member}.',
'account_desc' => 'Quand un nouvel article est publié sur le site',
);
return $array;
}
add_filter( 'um_notifications_get_icon', 'add_new_article_notification_icon', 10, 2 );
function add_new_article_notification_icon( $output, $type ) {
if ( $type == 'new_article' ) {
$output = '<i class="um-icon-article" style="color: #336699"></i>';
}
return $output;
}
add_action( 'publish_post', 'send_new_article_notification', 10, 2 );
function send_new_article_notification( $ID, $post ) {
$author_id = $post->post_author;
$title = $post->post_title;
$permalink = get_permalink( $ID );
um_fetch_user( $author_id );
$author_name = um_user( 'display_name' );
$vars = array(
'article_title' => $title,
'member' => $author_name,
'notification_uri' => $permalink,
);
// Envoyer une notification à tous les utilisateurs du site
$users = get_users();
foreach ( $users as $user ) {
UM()->Notifications_API()->api()->store_notification( $user->ID, 'new_article', $vars );
}
}