wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
wp_send_note_notification › WordPress Function
Seit7.1.0
Veraltetn/v
› wp_send_note_notification ( $user, $comment, $post )
| Parameter: (3) |
|
| Gibt zurück: |
|
| Definiert in: |
|
| Codex: |
Sends a single note mention notification email.
The email is composed in the recipient's locale, matching how other user-directed notifications are composed, and links to the post editor the same way the post author's note notification does.Quellcode
function wp_send_note_notification( WP_User $user, WP_Comment $comment, ?WP_Post $post ): bool {
$switched_locale = switch_to_user_locale( $user->ID );
/*
* The site title and the post title are escaped on the way into the database,
* and note content is stored as HTML. Both are reversed once here for the
* plain text arena of emails. Decoding a second time would go too far and
* resolve entities the author meant to be read literally.
*/
$blogname = wp_specialchars_decode( get_bloginfo( 'name', 'display' ), ENT_QUOTES );
$post_title = $post ? wp_specialchars_decode( get_the_title( $post ), ENT_QUOTES ) : '';
$author_name = $comment->comment_author ? $comment->comment_author : __( 'Someone' );
$content = wp_specialchars_decode( wp_strip_all_tags( $comment->comment_content ) );
/*
* The rest of the message is composed for the recipient, and so is the editor
* link: get_edit_post_link() answers for whoever is current, which here is the
* note's author over REST and nobody at all under WP-Cron.
*/
$edit_link = '';
if ( $post ) {
$previous_user_id = get_current_user_id();
wp_set_current_user( $user->ID );
$edit_link = (string) get_edit_post_link( $post->ID, 'url' );
wp_set_current_user( $previous_user_id );
}
/* translators: 1: Note author's name, 2: Post title. */
$message = sprintf( __( '%1$s mentioned you in a note on "%2$s".' ), $author_name, $post_title );
/* translators: Note mention notification email subject. 1: Site title, 2: Post title. */
$subject = sprintf( __( '[%1$s] You were mentioned in a note on "%2$s"' ), $blogname, $post_title );
$lines = array( $message, '' );
if ( '' !== $content ) {
$lines[] = $content;
}
if ( $edit_link ) {
$lines[] = '';
$lines[] = __( 'Edit This' ) . ': ' . $edit_link;
}
// Declared explicitly so a filtered default cannot turn the message into HTML.
$headers = 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . '"';
$sent = wp_mail( $user->user_email, $subject, implode( "\n", $lines ), $headers );
if ( $switched_locale ) {
restore_previous_locale();
}
return $sent;
}