wp_check_comment_data_max_lengths() - WordPress 函数参考中文文档

返回介绍

wp_check_comment_data_max_lengths()

发布于 2017-09-11 字数2859 浏览 907 评论 0

wp_check_comment_data_max_lengths( array $comment_data )

Compares the lengths of comment data against the maximum character limits.


描述


参数

$comment_data

(array)
(Required)
Array of arguments for inserting a comment.


返回值

(WP_Error|true) WP_Error when a comment field exceeds the limit, otherwise true.


源代码

File: wp-includes/comment.php

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;
}

更新日志

Version 描述
4.7.0 Introduced.

相关函数

Uses

  • wp-includes/comment.php:
    wp_get_comment_fields_max_lengths()
  • wp-includes/l10n.php:
    __()
  • wp-includes/class-wp-error.php:
    WP_Error::__construct()

Used By

  • wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php:
    WP_REST_Comments_Controller::update_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php:
    WP_REST_Comments_Controller::create_item()
  • wp-includes/comment.php:
    wp_handle_comment_submission()

User Contributed Notes

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!