get_settings(); if ( empty( $settings['notifications_enabled'] ) ) { return; } $post = get_post( $post_id ); if ( ! $post ) { return; } /* Les destinataires : l'auteur assigne, puis les co-auteurs. On DEDOUBLONNE par * identifiant avant de resoudre les adresses — un co-auteur peut etre l'assigne. */ $user_ids = array(); if ( is_object( $assignment ) && ! empty( $assignment->user_id ) ) { $user_ids[] = (int) $assignment->user_id; } foreach ( $db->get_coauthors_for_post( $post_id ) as $coauthor ) { if ( ! empty( $coauthor->user_id ) ) { $user_ids[] = (int) $coauthor->user_id; } } $user_ids = array_values( array_unique( array_filter( $user_ids ) ) ); if ( empty( $user_ids ) ) { return; } $workflow = Aiforya_Multi_Author_Workflow::get_instance(); $labels = $workflow->get_status_labels(); $label = isset( $labels[ $new_status ] ) ? $labels[ $new_status ] : $new_status; $titre = get_the_title( $post_id ); $lien = get_edit_post_link( $post_id, 'raw' ); /* translators: %s: post title. */ $sujet = sprintf( __( 'Status updated: %s', 'aiforya-multi-author' ), $titre ); foreach ( $user_ids as $user_id ) { $user = get_userdata( $user_id ); if ( ! $user || empty( $user->user_email ) ) { continue; } $lignes = array( /* translators: %s: recipient display name. */ sprintf( __( 'Hello %s,', 'aiforya-multi-author' ), $user->display_name ), '', /* translators: 1: post title, 2: new editorial status. */ sprintf( __( 'The post "%1$s" has moved to the status "%2$s".', 'aiforya-multi-author' ), $titre, $label ), ); if ( $lien ) { $lignes[] = ''; $lignes[] = __( 'Open it here:', 'aiforya-multi-author' ) . ' ' . $lien; } $lignes[] = ''; $lignes[] = __( 'You are receiving this because you are an author or co-author of this post.', 'aiforya-multi-author' ); /* ⚠ `wp_mail` rend false sans lever : on n'en fait PAS un echec silencieux du * changement de statut, qui lui a bien eu lieu. Le statut prime, la notification * est un a-cote — l'inverse ferait qu'un serveur SMTP en panne bloque la redaction. */ wp_mail( $user->user_email, $sujet, implode( "\n", $lignes ) ); } } }