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
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
- Scaling
- Constant
- Instructions
- 79–121
- Plugin surface
- None
- Called by
- 1
Sends mail via wp_mail().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 124.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionoption read or write
get_option()called directly - mailsends mail
wp_mail()called directly - hookthird-party callbacks
apply_filters()one call below wp_send_note_notification() - querycontent query
get_post()one call below wp_send_note_notification() - cacheobject cache
wp_cache_get()one call below wp_send_note_notification() - serializeserialisation
maybe_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.
| When | Instructions | Calls it makes |
|---|---|---|
$comment | 79–81 | switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), get_option(), wp_mail() |
!$comment | 81–83 | switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), __(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), get_option(), wp_mail() |
$comment | 81–83 | switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), get_option(), wp_mail(), restore_previous_locale() |
!$comment | 83–85 | switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), __(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), get_option(), wp_mail(), restore_previous_locale() |
$comment | 87–89 | switch_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() |
$comment | 88–90 | switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), __(), get_option(), wp_mail() |
!$comment | 89–91 | switch_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() |
$comment | 89–91 | switch_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() |
!$comment | 90–92 | switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), __(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), __(), get_option(), wp_mail() |
$comment | 90–92 | switch_to_user_locale(), get_bloginfo(), wp_specialchars_decode(), wp_strip_all_tags(), wp_specialchars_decode(), __(), sprintf(), __(), sprintf(), __(), get_option(), wp_mail(), restore_previous_locale() |
!$comment | 91–93 | switch_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() |
!$comment | 92–94 | switch_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
$comment | 96–98 | switch_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() |
$comment | 98–100 | switch_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() |
!$comment | 98–100 | switch_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() |
$comment | 98–100 | switch_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() |
!$comment | 100–102 | switch_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() |
$comment | 100–102 | switch_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() |
!$comment | 100–102 | switch_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() |
!$comment | 102–104 | switch_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() |
$comment | 106–108 | switch_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() |
$comment | 107–109 | switch_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() |
!$comment | 108–110 | switch_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() |
$comment | 108–110 | switch_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() |
!$comment | 109–111 | switch_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() |
$comment | 109–111 | switch_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() |
!$comment | 110–112 | switch_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() |
!$comment | 111–113 | switch_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() |
$comment | 115–117 | switch_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() |
!$comment | 117–119 | switch_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() |
$comment | 117–119 | switch_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() |
!$comment | 119–121 | switch_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 122 | 79–119 | 6 | 2 fewer instructions than PHP 8.5 |
| 8.5 | 124 | 79–121 | 6 | |
| 8.4 | 124 | 79–121 | 6 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 127 | 82–124 | 6 | |
| 8.2 | 127 | 82–124 | 6 | |
| 8.1 | 127 | 82–124 | 6 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 128 | 83–124 | 6 |
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
- switch_to_user_locale()Switches the translations according to the given user's locale.
- wp_specialchars_decode()Converts a number of HTML entities into their special characters.
- get_bloginfo()Retrieves information about the current site.
- get_the_title()Retrieves the post title.
- __()Retrieves the translation of $text.
- wp_strip_all_tags()Properly strips all HTML tags including 'script' and 'style'.
- get_current_user_id()Gets the current user's ID.
- wp_set_current_user()Changes the current user by ID or name.
- get_edit_post_link()Retrieves the edit post link for post.
- get_option()Retrieves an option value based on an option name.
- wp_mail()Sends an email, similar to PHP's mail function.
- restore_previous_locale()Restores the translations according to the previous locale.
Used by · 1
- wp_notify_note_mentions()Notifies mentioned users about a new note.
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.