Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email validation for non logged in users. #8114

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/wp-comments-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@

nocache_headers();

// Check if user is not logged in and email exists in the comment form
if ( ! is_user_logged_in() && isset( $_POST['email'] ) && ! empty( $_POST['email'] ) ) {
$email = sanitize_email( wp_unslash( $_POST['email'] ) );

// Check if the email belongs to a registered user
if ( email_exists( $email ) ) {
wp_die(
'<p>' . __( 'The email address you entered is already associated with a registered account. Please log in to continue.' ) . '</p>',
__( 'Email Address Error' ),
array(
'response' => 403,
'back_link' => true,
)
);
}
}

$comment = wp_handle_comment_submission( wp_unslash( $_POST ) );
if ( is_wp_error( $comment ) ) {
$data = (int) $comment->get_error_data();
Expand Down
Loading