wp_check_comment_disallowed_list( string $author, string $email, string $url, string $comment, string $user_ip, string $user_agent ): bool
- Since
- 5.5.0
- Source
wp-includes/comment.php:1325
Compatibility
- WordPress
- since 5.5.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
$authorstring- The author of the comment
$emailstring- The email of the comment
$urlstring- The url used in the comment
$commentstring- The comment content
$user_ipstring- The comment author's IP address
$user_agentstring- The author's browser user agent
Return value
bool- True if comment contains disallowed content, false if comment does not
Performance profile
How much work a call to wp_check_comment_disallowed_list() 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
- Heavy
- Scaling
- Scales with input
- Instructions
- 38–78
- Plugin surface
- 2 hooks
- Called by
- 2
Reads stored settings via get_option(), cached per request but not free on a cold cache.
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 81.
Third-party callbacks on 'wp_blacklist_check', 'wp_check_comment_disallowed_list' run inside this call, and their cost is not bounded by anything here.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
do_action_deprecated()called directly - optionoption read or write
get_option()called directly - cacheobject cache
wp_cache_get()one call below wp_check_comment_disallowed_list() - serializeserialisation
maybe_unserialize()one call below wp_check_comment_disallowed_list()
Further down the call graph this can also reach query and transient. Those are 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_check_comment_disallowed_list() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$mod_keys === "" | 38 | __(), do_action(), get_option() |
$mod_keys !== "" | 50–51 | __(), do_action(), get_option(), wp_strip_all_tags(), explode() |
$mod_keys !== "" && !$words && !empty($word) && $pattern | 66–78 | __(), do_action(), get_option(), wp_strip_all_tags(), explode(), preg_quote() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 81 | 38–78 | 11 | |
| 8.5 | 81 | 38–78 | 11 | |
| 8.4 | 81 | 38–78 | 11 | 26 fewer instructions than PHP 8.3 |
| 8.3 | 107 | 41–104 | 11 | |
| 8.2 | 107 | 41–104 | 11 | |
| 8.1 | 107 | 41–104 | 11 | |
| 7.4 | 107 | 41–104 | 11 |
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 · 2
2 hooks fire while wp_check_comment_disallowed_list() runs, in this order:
- do_action( wp_blacklist_check )action_deprecatedline 1339 (+14 into the body)
Fires before the comment is tested for disallowed characters or words.
- do_action( wp_check_comment_disallowed_list )actionline 1359 (+34 into the body)
Fires before the comment is tested for disallowed characters or words.
Uses · 5
- do_action_deprecated()Fires functions attached to a deprecated action hook.
- __()Retrieves the translation of $text.
- do_action()Calls the callback functions that have been added to an action hook.
- get_option()Retrieves an option value based on an option name.
- wp_strip_all_tags()Properly strips all HTML tags including 'script' and 'style'.
Used by · 2
- wp_blacklist_check()Does comment contain disallowed characters or words.
- wp_check_comment_data()Checks whether comment data passes internal checks or has disallowed content.
Source code
function wp_check_comment_disallowed_list( $author, $email, $url, $comment, $user_ip, $user_agent ) { /** * Fires before the comment is tested for disallowed characters or words. * * @since 1.5.0 * @deprecated 5.5.0 Use {@see 'wp_check_comment_disallowed_list'} instead. * * @param string $author Comment author. * @param string $email Comment author's email. * @param string $url Comment author's URL. * @param string $comment Comment content. * @param string $user_ip Comment author's IP address. * @param string $user_agent Comment author's browser user agent. */ do_action_deprecated( 'wp_blacklist_check', array( $author, $email, $url, $comment, $user_ip, $user_agent ), '5.5.0', 'wp_check_comment_disallowed_list', __( 'Please consider writing more inclusive code.' ) ); /** * Fires before the comment is tested for disallowed characters or words. * * @since 5.5.0 * * @param string $author Comment author. * @param string $email Comment author's email. * @param string $url Comment author's URL. * @param string $comment Comment content. * @param string $user_ip Comment author's IP address. * @param string $user_agent Comment author's browser user agent. */ do_action( 'wp_check_comment_disallowed_list', $author, $email, $url, $comment, $user_ip, $user_agent ); $mod_keys = trim( get_option( 'disallowed_keys' ) ); if ( '' === $mod_keys ) { return false; // If moderation keys are empty. } // Ensure HTML tags are not being used to bypass the list of disallowed characters and words. $comment_without_html = wp_strip_all_tags( $comment ); $words = explode( "\n", $mod_keys ); foreach ( (array) $words as $word ) { $word = trim( $word ); // Skip empty lines. if ( empty( $word ) ) { continue; } // Do some escaping magic so that '#' chars in the spam words don't break things: $word = preg_quote( $word, '#' ); $pattern = "#$word#iu"; if ( preg_match( $pattern, $author ) || preg_match( $pattern, $email ) || preg_match( $pattern, $url ) || preg_match( $pattern, $comment ) || preg_match( $pattern, $comment_without_html ) || preg_match( $pattern, $user_ip ) || preg_match( $pattern, $user_agent ) ) { return true; } } return false;}Changelog
Introduced in 5.5.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 6.7.7 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.