wp_check_comment_data_max_lengths

The timeline below displays how wordpress function wp_check_comment_data_max_lengths has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Compares the lengths of comment data against the maximum character limits.
 *
 * @since 4.7.0
 *
 * @param array $comment_data Array of arguments for inserting a comment.
 * @return WP_Error|true WP_Error when a comment field exceeds the limit,
 *                       otherwise true.
 */
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;
}

WordPress Version: 5.4

/**
 * Compares the lengths of comment data against the maximum character limits.
 *
 * @since 4.7.0
 *
 * @param array $comment_data Array of arguments for inserting a comment.
 * @return WP_Error|true WP_Error when a comment field exceeds the limit,
 *                       otherwise true.
 */
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;
}

WordPress Version: 4.7

/**
 * Compares the lengths of comment data against the maximum character limits.
 *
 * @since 4.7.0
 *
 * @param array $comment_data Array of arguments for inserting a comment.
 * @return WP_Error|true WP_Error when a comment field exceeds the limit,
 *                       otherwise true.
 */
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;
}