wppaste
WordPress

wp_notify_postauthor( int|WP_Comment $comment_id, string $deprecated = null ): bool

Since
1.0.0
Source
wp-includes/pluggable.php:1741
Notifies an author (and/or others) of a comment/trackback/pingback on a post.

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

Sends mail.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
11–130

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

Plugin surface
5 hooks

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.

Called by
1

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

What it touches

  • mailsends mailwp_notify_postauthor()this function does it
  • querycontent queryget_post()called directly
  • hookthird-party callbacksapply_filters()called directly
  • optionoption read or writeget_option()called directly
  • cacheobject cachewp_cache_get()one call below wp_notify_postauthor()
  • serializeserialisationmaybe_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.

WhenInstructionsCalls it makes
$deprecated === null && empty($comment)11get_comment()
$deprecated === null && !empty($comment) && $emails && !::WP_Http()119–130get_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–126get_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

PHPCompiledExecutedBranchesNotes
8.6-dev62211–130351 fewer instruction than PHP 8.5
8.562311–13035
8.462311–130353 fewer instructions than PHP 8.3
8.362611–13335
8.262611–133351 more instruction than PHP 8.1
8.162511–13335
7.462511–13335

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:

  1. apply_filters( comment_notification_recipients )filterline 1771 (+30 into the body)

    Filters the list of email addresses to receive a comment notification.

  2. apply_filters( comment_notification_notify_author )filterline 1794 (+53 into the body)

    Filters whether to notify comment authors of their comments on their own posts.

  3. apply_filters( comment_notification_headers )filterline 1859 (+118 into the body)

    Filters the comment notification email headers.

  4. apply_filters( comment_notification_text )filterline 1964 (+223 into the body)

    Filters the comment notification email text.

  5. apply_filters( comment_notification_subject )filterline 1974 (+233 into the body)

    Filters the comment notification email subject.

Uses · 23

Show all 23

Used by · 1

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 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.