以下是过滤器的建议:
/**
* 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 );