wp_notify_postauthor( int|WP_Comment $comment_id, string $deprecated = null ): bool
- Since
- 1.0.0
- Source
wp-includes/pluggable.php:1745
Compatibility
- WordPress
- since 1.0.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$comment_idint|WP_Comment- Comment ID or WP_Comment object.
$deprecatedstringoptional- Not used.Default:
null
Return value
bool- True on completion. False if no email addresses were specified.
Performance profile
How much work a call to wp_notify_postauthor() 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
- 11–130
- Plugin surface
- 5 hooks
- Called by
- 1
Sends 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 623.
Third-party callbacks on 'comment_notification_recipients', 'comment_notification_notify_author', 'comment_notification_headers' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- mailsends mail
wp_notify_postauthor()this function does it - querycontent query
get_post()called directly - hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_option()called directly - cacheobject cache
wp_cache_get()one call below wp_notify_postauthor() - serializeserialisation
maybe_unserialize()one call below wp_notify_postauthor()
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 · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_notify_postauthor() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$deprecated === null && empty($comment) | 11 | get_comment() |
$deprecated === null && !empty($comment) && $emails && !::WP_Http() | 119–130 | get_comment(), get_post(), get_userdata(), apply_filters(), array_filter(), array_flip(), apply_filters(), array_flip(), ::WP_Http(), get_option(), wp_specialchars_decode(), wp_specialchars_decode(), network_home_url(), wp_parse_url(), get_option(), apply_filters() |
$deprecated === null && !empty($comment) && $emails && ::WP_Http() && !isset($reply_to) | 125–126 | get_comment(), get_post(), get_userdata(), apply_filters(), array_filter(), array_flip(), apply_filters(), array_flip(), ::WP_Http(), gethostbyaddr(), get_option(), wp_specialchars_decode(), wp_specialchars_decode(), network_home_url(), wp_parse_url(), get_option(), apply_filters() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 622 | 11–130 | 35 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 623 | 11–130 | 35 | |
| 8.4 | 623 | 11–130 | 35 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 626 | 11–133 | 35 | |
| 8.2 | 626 | 11–133 | 35 | 1 more instruction than PHP 8.1 |
| 8.1 | 625 | 11–133 | 35 | |
| 7.4 | 625 | 11–133 | 35 |
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.
Hooks and filters fired · 5
5 hooks fire while wp_notify_postauthor() runs, in this order:
- apply_filters( comment_notification_recipients )filterline 1775 (+30 into the body)
Filters the list of email addresses to receive a comment notification.
- apply_filters( comment_notification_notify_author )filterline 1798 (+53 into the body)
Filters whether to notify comment authors of their comments on their own posts.
- apply_filters( comment_notification_headers )filterline 1863 (+118 into the body)
Filters the comment notification email headers.
- apply_filters( comment_notification_text )filterline 1968 (+223 into the body)
Filters the comment notification email text.
- apply_filters( comment_notification_subject )filterline 1978 (+233 into the body)
Filters the comment notification email subject.
Uses · 23
- _deprecated_argument()Marks a function argument as deprecated and inform when it has been used.
- get_comment()Retrieves comment data given a comment ID or comment object.
- get_post()Retrieves post data given a post ID or post object.
- get_userdata()Retrieves user info by user ID.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_current_user_id()Gets the current user's ID.
- user_can()Returns whether a particular user has the specified capability.
- wp_specialchars_decode()Converts a number of HTML entities into their special characters.
- get_option()Retrieves an option value based on an option name.
- wp_parse_url()A wrapper for PHP's parse_url() function that handles consistency in the return values across PHP versions.
- network_home_url()Retrieves the home URL for the current network.
- get_user_by()Retrieves user info by a given field.
Show all 23
- switch_to_user_locale()Switches the translations according to the given user's locale.
- switch_to_locale()Switches the translations according to the given locale.
- get_locale()Retrieves the current locale.
- __()Retrieves the translation of $text.
- admin_url()Retrieves the URL to the admin area for the current site.
- get_edit_post_link()Retrieves the edit post link for post.
- get_permalink()Retrieves the full permalink for the current post or post ID.
- get_comment_link()Retrieves the link to a given comment.
- wp_mail()Sends an email, similar to PHP's mail function.
- restore_previous_locale()Restores the translations according to the previous locale.
- WP_Http::is_ip_address()Determines if a specified string represents an IP address or not.
Used by · 1
- wp_new_comment_notify_postauthor()Sends a notification of a new comment to the post author.
Source code
function wp_notify_postauthor( $comment_id, $deprecated = null ) { if ( null !== $deprecated ) { _deprecated_argument( __FUNCTION__, '3.8.0' ); } $comment = get_comment( $comment_id ); if ( empty( $comment ) || empty( $comment->comment_post_ID ) ) { return false; } $post = get_post( $comment->comment_post_ID ); $author = get_userdata( $post->post_author ); // Who to notify? By default, just the post author, but others can be added. $emails = array(); if ( $author ) { $emails[] = $author->user_email; } /** * Filters the list of email addresses to receive a comment notification. * * By default, only post authors are notified of comments. This filter allows * others to be added. * * @since 3.7.0 * * @param string[] $emails An array of email addresses to receive a comment notification. * @param string $comment_id The comment ID as a numeric string. */ $emails = apply_filters( 'comment_notification_recipients', $emails, $comment->comment_ID ); $emails = array_filter( $emails ); // If there are no addresses to send the comment to, bail. if ( ! count( $emails ) ) { return false; } // Facilitate unsetting below without knowing the keys. $emails = array_flip( $emails ); /** * Filters whether to notify comment authors of their comments on their own posts. * * By default, comment authors aren't notified of their comments on their own * posts. This filter allows you to override that. * * @since 3.8.0 * * @param bool $notify Whether to notify the post author of their own comment. * Default false. * @param string $comment_id The comment ID as a numeric string. */ $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment->comment_ID ); // The comment was left by the author. if ( $author && ! $notify_author && (int) $comment->user_id === (int) $post->post_author ) { unset( $emails[ $author->user_email ] ); } // The author moderated a comment on their own post. if ( $author && ! $notify_author && get_current_user_id() === (int) $post->post_author ) { unset( $emails[ $author->user_email ] ); } // The post author is no longer a member of the blog. if ( $author && ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) { unset( $emails[ $author->user_email ] ); } // If there's no email to send the comment to, bail, otherwise flip array back around for use below. if ( ! count( $emails ) ) { return false; } else { $emails = array_flip( $emails ); } $comment_author_domain = ''; if ( WP_Http::is_ip_address( $comment->comment_author_IP ) ) { $comment_author_domain = gethostbyaddr( $comment->comment_author_IP );Changelog
Introduced in 1.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/pluggable.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.