我知道我不能保证没有注册的电子邮件是有效的,但我注意到一个有问题的用户想要使用troll@example.com
电子邮件地址。
我如何为评论作者维护此类域的黑名单?具体来说,如果使用了这样的域,我如何立即拒绝评论,并以此通知用户?
A.wp_die(\'you must use a real email\');
可能会成功,但应该在什么时候进行检查?
我知道我不能保证没有注册的电子邮件是有效的,但我注意到一个有问题的用户想要使用troll@example.com
电子邮件地址。
我如何为评论作者维护此类域的黑名单?具体来说,如果使用了这样的域,我如何立即拒绝评论,并以此通知用户?
A.wp_die(\'you must use a real email\');
可能会成功,但应该在什么时候进行检查?
以下是过滤器的建议:
/**
* Filters a comment\'s approval status before it is set.
*
* @since 2.1.0
* @since 4.9.0 Returning a WP_Error value from the filter will shortcircuit comment insertion and
* allow skipping further processing.
*
* @param bool|string|WP_Error $approved The approval status. Accepts 1, 0, \'spam\' or WP_Error.
* @param array $commentdata Comment data.
*/
$approved = apply_filters( \'pre_comment_approved\', $approved, $commentdata );
我们可以通过以下方式尝试电子邮件域解析器Gabriel Livan:add_filter( \'pre_comment_approved\', function( $approved, $commentdata ) {
$domain = substr( strrchr( $commentdata[\'comment_author_email\'], \'@\' ), 1 );
$banned_domains = [
\'example.com\',
\'example.org\',
\'example.net\',
\'localhost\'
];
if ( in_array( $domain, $banned_domains ) ) {
wp_die( __( \'Please use a real email!\' ) );
//return new WP_Error( \'comment_real_email\', __( \'Please use a real email!\' ) );
}
return $approved;
}, 10, 2 );
在哪里$banned_domains
是要在保存到数据库之前停止的电子邮件域列表。另一个较早触发的是:
/**
* Filters a comment\'s data before it is sanitized and inserted into the database.
*
* @since 1.5.0
*
* @param array $commentdata Comment data.
*/
$commentdata = apply_filters( \'preprocess_comment\', $commentdata );
在WordPress中,注释间距不起作用。当我使用  在间距注释中,WordPress会在前端显示这些内容。其他html标记正在工作,但此标记不工作<如有任何建议,我们将不胜感激。