wp_check_comment_data_max_lengths

函数
wp_check_comment_data_max_lengths ( $comment_data )
参数
  • (array) $comment_data Array of arguments for inserting a comment.
    Required:
返回值
  • (WP_Error|true) WP_Error when a comment field exceeds the limit, otherwise true.
定义位置
相关方法
wp_get_comment_fields_max_lengthswp_check_comment_disallowed_listwp_check_comment_floodwp_get_comment_statuswp_set_comment_status
引入
4.7.0
弃用
-

wp_check_comment_data_max_lengths: 这是一个过滤器钩子,用于设置评论数据的最大长度。它可以用来确保评论不会太长,不会超过允许的最大长度。

将注释数据的长度与最大字符限制进行比较。

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

常见问题

FAQs
查看更多 >
闪电侠

(工作日 10:00 - 18:30 为您服务)

2025-12-06 16:33:22

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

您也可选择聊天工具与我们即时沟通或点击查看:

您的工单我们已经收到,我们将会尽快跟您联系!
取消
选择聊天工具: