BlackStar1991 Asked:2023-10-06 15:51:59 +0800 CST2023-10-06 15:51:59 +0800 CST 2023-10-06 15:51:59 +0800 CST WP 如何判断用户是否通过验证才能发表评论? 772 有WordPress一个开关可确保如果用户批准了一条评论,则无需事先审核即可发布下一条评论。 请告诉我,数据库中当前用户“已验证”的参数在哪里?(由$user_id) *我的任务是,如果允许用户发表评论,则“已验证用户”徽章将显示在他旁边 wordpress 1 个回答 Voted Best Answer KAGG Design 2023-10-06T20:55:38+08:002023-10-06T20:55:38+08:00 这是从 check_comment() 中提取代码的函数。 您需要将您的电子邮件和用户名(如果您尚未注册)转移到其中。如果用户的评论被批准,它将返回 true。 已针对现有用户测试代码。 /** * Check if user is approved for commenting. * Extracted from check_comment() WP Core function. * * Check if the option to approve comments by previously-approved authors is enabled. * * If it is enabled, check whether the comment author has a previously-approved comment, * as well as whether there are any moderation keywords (if set) present in the author * email address. If both checks pass, return true. Otherwise, return false. * * @param string $email Email. * @param string $author Author name. * * @return bool */ function is_user_approved( $email, $author = '' ) { global $wpdb; if ( 1 !== (int) get_option( 'comment_previously_approved' ) ) { return false; } $comment_user = get_user_by( 'email', wp_unslash( $email ) ); // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching if ( ! empty( $comment_user->ID ) ) { $ok_to_comment = $wpdb->get_var( $wpdb->prepare( "SELECT comment_approved FROM $wpdb->comments WHERE user_id = %d AND comment_approved = '1' LIMIT 1", $comment_user->ID ) ); } else { // Variables $author and $email are expected to be slashed. $ok_to_comment = $wpdb->get_var( $wpdb->prepare( "SELECT comment_approved FROM $wpdb->comments WHERE comment_author = %s AND comment_author_email = %s and comment_approved = '1' LIMIT 1", $author, $email ) ); } // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $mod_keys = trim( get_option( 'moderation_keys' ) ); return ( ( 1 === (int) $ok_to_comment ) && ( empty( $mod_keys ) || ! str_contains( $email, $mod_keys ) ) ); }
这是从 check_comment() 中提取代码的函数。
您需要将您的电子邮件和用户名(如果您尚未注册)转移到其中。如果用户的评论被批准,它将返回 true。
已针对现有用户测试代码。