wp_notify_note_mentions( WP_Comment|null $comment, mixed $request = null, bool $creating = true )
- Since
- 7.1.0
- Source
wp-includes/comment.php:2654
Description
Runs on 'rest_insert_comment' alongside the post author notification.
The recipient set is the users mentioned in this note, minus the note's own author (a user is not notified about their own note) and the post author, who is already notified about every note by wp_new_comment_via_rest_notify_postauthor().
Only fires when a note is created, not when an existing one is edited, so correcting a note does not re-notify everyone who already received it.
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
$commentWP_Comment|null- The note that was just inserted. (May only be null as an edge case.)
$requestmixedoptional- The REST request. Unused.Default:
null $creatingbooloptional- Whether this is a create (true) or update (false).Default:
true
Performance profile
How much work a call to wp_notify_note_mentions() 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
- Scales with input
- Instructions
- 5–39
- Plugin surface
- None
- Called by
- 0
Sends mail via wp_mail().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 69.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- optionoption read or write
get_option()called directly - querycontent query
get_post()called directly - hookthird-party callbacks
apply_filters()one call below wp_notify_note_mentions() - cacheobject cache
wp_cache_get()one call below wp_notify_note_mentions() - serializeserialisation
maybe_unserialize()one call below wp_notify_note_mentions() - mailsends mail
wp_mail()one call below wp_notify_note_mentions()
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 · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_notify_note_mentions() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 5–9 | none |
!get_option() | 14 | get_option() |
get_option() | 32–35 | get_option(), wp_get_note_mentioned_user_ids() |
get_option() | 36–39 | get_option(), wp_get_note_mentioned_user_ids(), get_post() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 68 | 5–38 | 13 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 69 | 5–39 | 13 | |
| 8.4 | 69 | 5–39 | 13 | |
| 8.3 | 69 | 5–39 | 13 | |
| 8.2 | 69 | 5–39 | 13 | |
| 8.1 | 69 | 5–39 | 13 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 70 | 5–40 | 13 |
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 · 6
- get_option()Retrieves an option value based on an option name.
- wp_get_note_mentioned_user_ids()Extracts the mentioned user IDs from note content.
- get_post()Retrieves post data given a post ID or post object.
- get_userdata()Retrieves user info by user ID.
- user_can()Returns whether a particular user has the specified capability.
- wp_send_note_notification()Sends a single note mention notification email.
Source code
function wp_notify_note_mentions( ?WP_Comment $comment, $request = null, bool $creating = true ): void { if ( ! $creating || ! $comment ) { return; } if ( 'note' !== $comment->comment_type ) { return; } // Share the single user-facing notes notification preference. if ( ! get_option( 'wp_notes_notify', 1 ) ) { return; } $mentioned = wp_get_note_mentioned_user_ids( $comment->comment_content ); $author_id = (int) $comment->user_id; $comment_post_id = (int) $comment->comment_post_ID; $post = $comment_post_id ? get_post( $comment_post_id ) : null; $post_author_id = $post ? (int) $post->post_author : 0; /* * The recipient set is bounded and small (one note's mentions), so emails * are sent synchronously here. If notification volume ever warrants it, * the right fix is to offload delivery to a background queue rather than * throttle within the request. */ foreach ( $mentioned as $user_id ) { // Never notify the author about their own note. if ( $user_id === $author_id ) { continue; } // The post author is already notified of every note. if ( $user_id === $post_author_id ) { continue; } $user = get_userdata( $user_id ); if ( ! $user || empty( $user->user_email ) ) { continue; } /* * Only notify users who can actually read the note. Notes are * internal: WP_REST_Comments_Controller::check_read_permission() * only exposes a note to its author or to users who can edit it, so * the email audience is held to the same bar. A plain read_post * check would leak note content to, for example, subscribers on a * public post, who cannot see the note in the editor. */ if ( ! user_can( $user_id, 'edit_comment', $comment->comment_ID ) ) { continue; } wp_send_note_notification( $user, $comment, $post ); }}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.