wppaste
WordPress

wp_send_note_notification( WP_User $user, WP_Comment $comment, WP_Post|null $post ): bool

Since
7.1.0
Source
wp-includes/comment.php:2727
Sends a single note mention notification email.

Description

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.

Compatibility

WordPress
since 7.1.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in 1 of the 5 tracked releases, added in 7.1.0, and compiles on PHP 7.4 through 8.6-dev.

Parameters

$userWP_User
The recipient.
$commentWP_Comment
The note that triggered the notification.
$postWP_Post|null
The post the note belongs to.

Return value

bool
Whether the email was accepted for delivery by wp_mail().

Performance profile

How much work a call to wp_send_note_notification() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Expensive

Sends mail via wp_mail().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
79–121

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 124.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • optionoption read or writeget_option()called directly
  • mailsends mailwp_mail()called directly
  • hookthird-party callbacksapply_filters()one call below wp_send_note_notification()
  • querycontent queryget_post()one call below wp_send_note_notification()
  • cacheobject cachewp_cache_get()one call below wp_send_note_notification()
  • serializeserialisationmaybe_unserialize()one call below wp_send_note_notification()

Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 32 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_send_note_notification() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
$comment79–81switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), get_option(), wp_mail()
!$comment81–83switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), __(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), get_option(), wp_mail()
$comment81–83switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), get_option(), wp_mail(), restore_previous_locale()
!$comment83–85switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), __(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), get_option(), wp_mail(), restore_previous_locale()
$comment87–89switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), get_the_title(), wp_specialchars_decode(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), get_option(), wp_mail()
$comment88–90switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), __(), get_option(), wp_mail()
!$comment89–91switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), get_the_title(), wp_specialchars_decode(), __(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), get_option(), wp_mail()
$comment89–91switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), get_the_title(), wp_specialchars_decode(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), get_option(), wp_mail(), restore_previous_locale()
!$comment90–92switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), __(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), __(), get_option(), wp_mail()
$comment90–92switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), __(), get_option(), wp_mail(), restore_previous_locale()
!$comment91–93switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), get_the_title(), wp_specialchars_decode(), __(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), get_option(), wp_mail(), restore_previous_locale()
!$comment92–94switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), __(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), __(), get_option(), wp_mail(), restore_previous_locale()
20 further outcomes, up to 121 instructions
$comment96–98switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), get_the_title(), wp_specialchars_decode(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), __(), get_option(), wp_mail()
$comment98–100switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), wp_strip_all_tags(), wp_specialchars_decode(), get_current_user_id(), wp_set_current_user(), get_edit_post_link(), wp_set_current_user(), __(), sprintf(), __(), sprintf(), get_option(), wp_mail()
!$comment98–100switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), get_the_title(), wp_specialchars_decode(), __(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), __(), get_option(), wp_mail()
$comment98–100switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), get_the_title(), wp_specialchars_decode(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), __(), get_option(), wp_mail(), restore_previous_locale()
!$comment100–102switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), __(), wp_strip_all_tags(), wp_specialchars_decode(), get_current_user_id(), wp_set_current_user(), get_edit_post_link(), wp_set_current_user(), __(), sprintf(), __(), sprintf(), get_option(), wp_mail()
$comment100–102switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), wp_strip_all_tags(), wp_specialchars_decode(), get_current_user_id(), wp_set_current_user(), get_edit_post_link(), wp_set_current_user(), __(), sprintf(), __(), sprintf(), get_option(), wp_mail(), restore_previous_locale()
!$comment100–102switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), get_the_title(), wp_specialchars_decode(), __(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), __(), get_option(), wp_mail(), restore_previous_locale()
!$comment102–104switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), __(), wp_strip_all_tags(), wp_specialchars_decode(), get_current_user_id(), wp_set_current_user(), get_edit_post_link(), wp_set_current_user(), __(), sprintf(), __(), sprintf(), get_option(), wp_mail(), restore_previous_locale()
$comment106–108switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), get_the_title(), wp_specialchars_decode(), wp_strip_all_tags(), wp_specialchars_decode(), get_current_user_id(), wp_set_current_user(), get_edit_post_link(), wp_set_current_user(), __(), sprintf(), __(), sprintf(), get_option(), wp_mail()
$comment107–109switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), wp_strip_all_tags(), wp_specialchars_decode(), get_current_user_id(), wp_set_current_user(), get_edit_post_link(), wp_set_current_user(), __(), sprintf(), __(), sprintf(), __(), get_option(), wp_mail()
!$comment108–110switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), get_the_title(), wp_specialchars_decode(), __(), wp_strip_all_tags(), wp_specialchars_decode(), get_current_user_id(), wp_set_current_user(), get_edit_post_link(), wp_set_current_user(), __(), sprintf(), __(), sprintf(), get_option(), wp_mail()
$comment108–110switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), get_the_title(), wp_specialchars_decode(), wp_strip_all_tags(), wp_specialchars_decode(), get_current_user_id(), wp_set_current_user(), get_edit_post_link(), wp_set_current_user(), __(), sprintf(), __(), sprintf(), get_option(), wp_mail(), restore_previous_locale()
!$comment109–111switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), __(), wp_strip_all_tags(), wp_specialchars_decode(), get_current_user_id(), wp_set_current_user(), get_edit_post_link(), wp_set_current_user(), __(), sprintf(), __(), sprintf(), __(), get_option(), wp_mail()
$comment109–111switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), wp_strip_all_tags(), wp_specialchars_decode(), get_current_user_id(), wp_set_current_user(), get_edit_post_link(), wp_set_current_user(), __(), sprintf(), __(), sprintf(), __(), get_option(), wp_mail(), restore_previous_locale()
!$comment110–112switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), get_the_title(), wp_specialchars_decode(), __(), wp_strip_all_tags(), wp_specialchars_decode(), get_current_user_id(), wp_set_current_user(), get_edit_post_link(), wp_set_current_user(), __(), sprintf(), __(), sprintf(), get_option(), wp_mail(), restore_previous_locale()
!$comment111–113switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), __(), wp_strip_all_tags(), wp_specialchars_decode(), get_current_user_id(), wp_set_current_user(), get_edit_post_link(), wp_set_current_user(), __(), sprintf(), __(), sprintf(), __(), get_option(), wp_mail(), restore_previous_locale()
$comment115–117switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), get_the_title(), wp_specialchars_decode(), wp_strip_all_tags(), wp_specialchars_decode(), get_current_user_id(), wp_set_current_user(), get_edit_post_link(), wp_set_current_user(), __(), sprintf(), __(), sprintf(), __(), get_option(), wp_mail()
!$comment117–119switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), get_the_title(), wp_specialchars_decode(), __(), wp_strip_all_tags(), wp_specialchars_decode(), get_current_user_id(), wp_set_current_user(), get_edit_post_link(), wp_set_current_user(), __(), sprintf(), __(), sprintf(), __(), get_option(), wp_mail()
$comment117–119switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), get_the_title(), wp_specialchars_decode(), wp_strip_all_tags(), wp_specialchars_decode(), get_current_user_id(), wp_set_current_user(), get_edit_post_link(), wp_set_current_user(), __(), sprintf(), __(), sprintf(), __(), get_option(), wp_mail(), restore_previous_locale()
!$comment119–121switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), get_the_title(), wp_specialchars_decode(), __(), wp_strip_all_tags(), wp_specialchars_decode(), get_current_user_id(), wp_set_current_user(), get_edit_post_link(), wp_set_current_user(), __(), sprintf(), __(), sprintf(), __(), get_option(), wp_mail(), restore_previous_locale()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev12279–11962 fewer instructions than PHP 8.5
8.512479–1216
8.412479–12163 fewer instructions than PHP 8.3
8.312782–1246
8.212782–1246
8.112782–12461 fewer instruction than PHP 7.4
7.412883–1246

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 12

Used by · 1

Source code

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;}

Changelog

Introduced in 7.1.0.

Signature, return type and hooks compared across 1 parsed release.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/comment.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.