wp_notify_moderator( int $comment_id ): true
- Since
- 1.0.0
- Source
wp-includes/pluggable.php:2005
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- Comment ID.
Return value
true- Always returns true.
Performance profile
How much work a call to wp_notify_moderator() 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
- 14–108
- 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 427.
Third-party callbacks on 'notify_moderator', 'comment_moderation_recipients', 'comment_moderation_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_moderator()this function does it - optionoption read or write
get_option()called directly - hookthird-party callbacks
apply_filters()called directly - querycontent query
get_post()called directly - sqldatabase query
->get_var()called directly - cacheobject cache
wp_cache_get()one call below wp_notify_moderator() - serializeserialisation
maybe_unserialize()one call below wp_notify_moderator()
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 · 7 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_notify_moderator() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 14 | get_option(), apply_filters() |
!::WP_Http() | 79–80 | get_option(), apply_filters(), get_comment(), get_post(), get_userdata(), get_option(), ::WP_Http(), ->get_var(), get_option(), wp_specialchars_decode(), wp_specialchars_decode(), apply_filters(), apply_filters() |
::WP_Http() | 84–85 | get_option(), apply_filters(), get_comment(), get_post(), get_userdata(), get_option(), ::WP_Http(), gethostbyaddr(), ->get_var(), get_option(), wp_specialchars_decode(), wp_specialchars_decode(), apply_filters(), apply_filters() |
!::WP_Http() | 87–90 | get_option(), apply_filters(), get_comment(), get_post(), get_userdata(), get_option(), user_can(), ::WP_Http(), ->get_var(), get_option(), wp_specialchars_decode(), wp_specialchars_decode(), apply_filters(), apply_filters() |
::WP_Http() | 92–95 | get_option(), apply_filters(), get_comment(), get_post(), get_userdata(), get_option(), user_can(), ::WP_Http(), gethostbyaddr(), ->get_var(), get_option(), wp_specialchars_decode(), wp_specialchars_decode(), apply_filters(), apply_filters() |
user_can() && !empty($user) && !::WP_Http() | 99–103 | get_option(), apply_filters(), get_comment(), get_post(), get_userdata(), get_option(), user_can(), get_option(), strcasecmp(), ::WP_Http(), ->get_var(), get_option(), wp_specialchars_decode(), wp_specialchars_decode(), apply_filters(), apply_filters() |
user_can() && !empty($user) && ::WP_Http() | 104–108 | get_option(), apply_filters(), get_comment(), get_post(), get_userdata(), get_option(), user_can(), get_option(), strcasecmp(), ::WP_Http(), gethostbyaddr(), ->get_var(), get_option(), wp_specialchars_decode(), wp_specialchars_decode(), apply_filters(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 427 | 14–108 | 15 | |
| 8.5 | 427 | 14–108 | 15 | |
| 8.4 | 427 | 14–108 | 15 | |
| 8.3 | 427 | 14–108 | 15 | |
| 8.2 | 427 | 14–108 | 15 | 1 more instruction than PHP 8.1 |
| 8.1 | 426 | 14–108 | 15 | |
| 7.4 | 426 | 14–108 | 15 |
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_moderator() runs, in this order:
- apply_filters( notify_moderator )filterline 2018 (+13 into the body)
Filters whether to send the site moderator email notifications, overriding the site setting.
- apply_filters( comment_moderation_recipients )filterline 2059 (+54 into the body)
Filters the list of recipients for comment moderation emails.
- apply_filters( comment_moderation_headers )filterline 2069 (+64 into the body)
Filters the comment moderation email headers.
- apply_filters( comment_moderation_text )filterline 2160 (+155 into the body)
Filters the comment moderation email text.
- apply_filters( comment_moderation_subject )filterline 2170 (+165 into the body)
Filters the comment moderation email subject.
Uses · 19
- get_option()Retrieves an option value based on an option name.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- 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.
- 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_user_by()Retrieves user info by a given field.
- 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.
Show all 19
- get_permalink()Retrieves the full permalink for the current post or post ID.
- admin_url()Retrieves the URL to the admin area for the current site.
- _n()Translates and retrieves the singular or plural form based on the supplied number.
- number_format_i18n()Converts float number to format based on the locale.
- 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_moderator()Sends a comment moderation notification to the comment moderator.
Source code
function wp_notify_moderator( $comment_id ) { global $wpdb; $maybe_notify = get_option( 'moderation_notify' ); /** * Filters whether to send the site moderator email notifications, overriding the site setting. * * @since 4.4.0 * * @param bool $maybe_notify Whether to notify blog moderator. * @param int $comment_id The ID of the comment for the notification. */ $maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_id ); if ( ! $maybe_notify ) { return true; } $comment = get_comment( $comment_id ); $post = get_post( $comment->comment_post_ID ); $user = get_userdata( $post->post_author ); // Send to the administration and to the post author if the author can modify the comment. $emails = array( get_option( 'admin_email' ) ); if ( $user && user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) { if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) { $emails[] = $user->user_email; } } $comment_author_domain = ''; if ( WP_Http::is_ip_address( $comment->comment_author_IP ) ) { $comment_author_domain = gethostbyaddr( $comment->comment_author_IP ); } $comments_waiting = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'" ); /* * The blogname option is escaped with esc_html() on the way into the database in sanitize_option(). * We want to reverse this for the plain text arena of emails. */ $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); $comment_content = wp_specialchars_decode( $comment->comment_content ); $message_headers = ''; /** * Filters the list of recipients for comment moderation emails. * * @since 3.7.0 * * @param string[] $emails List of email addresses to notify for comment moderation. * @param int $comment_id Comment ID. */ $emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id ); /** * Filters the comment moderation email headers. * * @since 2.8.0 * * @param string $message_headers Headers for the comment moderation email. * @param int $comment_id Comment ID. */ $message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id ); foreach ( $emails as $email ) { $user = get_user_by( 'email', $email ); if ( $user ) { $switched_locale = switch_to_user_locale( $user->ID ); } else { $switched_locale = switch_to_locale( get_locale() ); } switch ( $comment->comment_type ) { case 'trackback': /* translators: %s: Post title. */ $notify_message = sprintf( __( 'A new trackback on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n"; $notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n";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.