wp_check_comment_data_max_lengths( array $comment_data ): WP_Error|true
- Since
- 4.7.0
- Source
wp-includes/comment.php:1221
Compatibility
- WordPress
- since 4.7.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_dataarray- Array of arguments for inserting a comment.
Return value
WP_Error|true- WP_Error when a comment field exceeds the limit, otherwise true.
Performance profile
How much work a call to wp_check_comment_data_max_lengths() 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
- Trivial
- Scaling
- Constant
- Instructions
- 13–47
- Plugin surface
- None
- Called by
- 3
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 75.
Nothing here hands control to plugin code.
3 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()one call below wp_check_comment_data_max_lengths()
Further down the call graph this can also reach option, cache, serialize, 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 · 6 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_check_comment_data_max_lengths() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($comment_data) | 13–23 | wp_get_comment_fields_max_lengths() |
| always | 21–31 | wp_get_comment_fields_max_lengths(), mb_strlen() |
| always | 22–29 | wp_get_comment_fields_max_lengths(), __() |
isset($comment_data) | 23–39 | wp_get_comment_fields_max_lengths(), mb_strlen(), __() |
isset($comment_data) | 29–39 | wp_get_comment_fields_max_lengths(), mb_strlen(), mb_strlen() |
isset($comment_data) | 37–47 | wp_get_comment_fields_max_lengths(), mb_strlen(), mb_strlen(), __() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 77 | 13–49 | 8 | 2 more instructions than PHP 8.5 |
| 8.5 | 75 | 13–47 | 8 | |
| 8.4 | 75 | 13–47 | 8 | |
| 8.3 | 75 | 13–47 | 8 | |
| 8.2 | 75 | 13–47 | 8 | |
| 8.1 | 75 | 13–47 | 8 | |
| 7.4 | 75 | 13–47 | 8 |
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 · 4
- wp_get_comment_fields_max_lengths()Retrieves the maximum character lengths for the comment form fields.
- mb_strlen()Compat function to mimic mb_strlen().
- __()Retrieves the translation of $text.
- WP_Error::__construct()Initializes the error.
Used by · 3
- WP_REST_Comments_Controller::create_item()Creates a comment.
- WP_REST_Comments_Controller::update_item()Updates a comment.
- wp_handle_comment_submission()Handles the submission of a comment, usually posted to wp-comments-post.php via a comment form.
Source code
function wp_check_comment_data_max_lengths( $comment_data ) { $max_lengths = wp_get_comment_fields_max_lengths(); if ( isset( $comment_data['comment_author'] ) && mb_strlen( $comment_data['comment_author'], '8bit' ) > $max_lengths['comment_author'] ) { return new WP_Error( 'comment_author_column_length', __( '<strong>Error:</strong> Your name is too long.' ), 200 ); } if ( isset( $comment_data['comment_author_email'] ) && strlen( $comment_data['comment_author_email'] ) > $max_lengths['comment_author_email'] ) { return new WP_Error( 'comment_author_email_column_length', __( '<strong>Error:</strong> Your email address is too long.' ), 200 ); } if ( isset( $comment_data['comment_author_url'] ) && strlen( $comment_data['comment_author_url'] ) > $max_lengths['comment_author_url'] ) { return new WP_Error( 'comment_author_url_column_length', __( '<strong>Error:</strong> Your URL is too long.' ), 200 ); } if ( isset( $comment_data['comment_content'] ) && mb_strlen( $comment_data['comment_content'], '8bit' ) > $max_lengths['comment_content'] ) { return new WP_Error( 'comment_content_column_length', __( '<strong>Error:</strong> Your comment is too long.' ), 200 ); } return true;}Changelog
Introduced in 4.7.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.