Wordpress 增加了先前批准的评论数量
Wordpress increase number of previously approved comment
在 Wordpress -> 设置 -> 讨论中有一个名为 "Comment author must have a previously approved comment"
的参数
用户必须在评论之前获得批准才能自动批准之后的评论。我怎样才能增加这个参数,这意味着用户之前必须有 5 条评论被批准?
谢谢
在您的 functions.php 中使用以下代码片段
根据 Comment author must have a previously approved comment
的值,它会检查用户是否有 5 条评论被批准。如果不是那么它将 return false 否则它将 return true.
function pre_comment_approved_callback($approved, $commentdata){
global $wpdb;
$author = $commentdata['comment_author'];
$email = $commentdata['comment_author_email'];
$comment_type = $commentdata['comment_type'];
$mod_keys = trim( get_option( 'moderation_keys' ) );
if ( 1 == get_option( 'comment_previously_approved' ) ) {
if ( 'trackback' !== $comment_type && 'pingback' !== $comment_type && '' !== $author && '' !== $email ) {
$comment_user = get_user_by( 'email', wp_unslash( $email ) );
if ( ! empty( $comment_user->ID ) ) {
$ok_to_comment = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_approved) FROM $wpdb->comments WHERE user_id = %d AND comment_approved = '1' LIMIT 5", $comment_user->ID ) );
} else {
// expected_slashed ($author, $email)
$ok_to_comment = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_approved) FROM $wpdb->comments WHERE comment_author = %s AND comment_author_email = %s and comment_approved = '1' LIMIT 5", $author, $email ) );
}
if ( ( 5 == $ok_to_comment ) &&
( empty( $mod_keys ) || false === strpos( $email, $mod_keys ) ) ) {
return true;
} else {
return false;
}
} else {
return false;
}
}
return $approved;
}
add_filter('pre_comment_approved', 'pre_comment_approved_callback', 10, 2);
在 Wordpress -> 设置 -> 讨论中有一个名为 "Comment author must have a previously approved comment"
用户必须在评论之前获得批准才能自动批准之后的评论。我怎样才能增加这个参数,这意味着用户之前必须有 5 条评论被批准?
谢谢
在您的 functions.php 中使用以下代码片段
根据 Comment author must have a previously approved comment
的值,它会检查用户是否有 5 条评论被批准。如果不是那么它将 return false 否则它将 return true.
function pre_comment_approved_callback($approved, $commentdata){
global $wpdb;
$author = $commentdata['comment_author'];
$email = $commentdata['comment_author_email'];
$comment_type = $commentdata['comment_type'];
$mod_keys = trim( get_option( 'moderation_keys' ) );
if ( 1 == get_option( 'comment_previously_approved' ) ) {
if ( 'trackback' !== $comment_type && 'pingback' !== $comment_type && '' !== $author && '' !== $email ) {
$comment_user = get_user_by( 'email', wp_unslash( $email ) );
if ( ! empty( $comment_user->ID ) ) {
$ok_to_comment = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_approved) FROM $wpdb->comments WHERE user_id = %d AND comment_approved = '1' LIMIT 5", $comment_user->ID ) );
} else {
// expected_slashed ($author, $email)
$ok_to_comment = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_approved) FROM $wpdb->comments WHERE comment_author = %s AND comment_author_email = %s and comment_approved = '1' LIMIT 5", $author, $email ) );
}
if ( ( 5 == $ok_to_comment ) &&
( empty( $mod_keys ) || false === strpos( $email, $mod_keys ) ) ) {
return true;
} else {
return false;
}
} else {
return false;
}
}
return $approved;
}
add_filter('pre_comment_approved', 'pre_comment_approved_callback', 10, 2);