Skip to content

Commit

Permalink
change order of checks in login integrations and add meaningful error (
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinfuchs authored Jun 26, 2023
1 parent 177431c commit 4d24447
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
10 changes: 5 additions & 5 deletions friendly-captcha/modules/wordpress/wordpress_comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ function frcaptcha_wp_comments_validate($comment) {
return $comment;
}

if ( empty( $_POST ) ) {
return;
}

$plugin = FriendlyCaptcha_Plugin::$instance;
if (!$plugin->is_configured() or (!$plugin->get_wp_comments_active() && !$plugin->get_wp_comments_logged_in_active())) {
return $comment;
}

$errorPrefix = '<strong>' . __( 'Error', 'wp-captcha' ) . '</strong> : ';
if ( empty( $_POST ) ) {
return new WP_Error("frcaptcha-empty-error", $errorPrefix . FriendlyCaptcha_Plugin::default_error_user_message() . __(" (empty body)", "frcaptcha") );
}

// Guest user
if ($comment["user_id"] == 0 && !$plugin->get_wp_comments_active()) {
return $comment;
Expand All @@ -57,7 +58,6 @@ function frcaptcha_wp_comments_validate($comment) {
return $comment;
}

$errorPrefix = '<strong>' . __( 'Error', 'wp-captcha' ) . '</strong> : ';
$solution = frcaptcha_get_sanitized_frcaptcha_solution_from_post();

if (empty( $solution )) {
Expand Down
9 changes: 4 additions & 5 deletions friendly-captcha/modules/wordpress/wordpress_login.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ function frcaptcha_wp_login_show_widget() {
add_filter( 'authenticate', 'frcaptcha_wp_login_validate', 20, 3 );

function frcaptcha_wp_login_validate($user, $username, $password) {

if ( empty( $_POST ) ) {
return;
}

$plugin = FriendlyCaptcha_Plugin::$instance;
if (!$plugin->is_configured() or !$plugin->get_wp_login_active()) {
return $user;
}

$errorPrefix = '<strong>' . __( 'Error', 'wp-captcha' ) . '</strong> : ';
if ( empty( $_POST ) ) {
return new WP_Error("frcaptcha-empty-error", $errorPrefix . FriendlyCaptcha_Plugin::default_error_user_message() . __(" (empty body)", "frcaptcha") );
}

$solution = frcaptcha_get_sanitized_frcaptcha_solution_from_post();

if ( empty( $solution ) ) {
Expand Down
9 changes: 4 additions & 5 deletions friendly-captcha/modules/wordpress/wordpress_register.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ function frcaptcha_wp_register_show_widget() {
add_action( 'register_post', 'frcaptcha_wp_register_validate', 10, 3 );

function frcaptcha_wp_register_validate($user_login, $user_email, $errors) {

if ( empty( $_POST ) ) {
return;
}

$plugin = FriendlyCaptcha_Plugin::$instance;
if (!$plugin->is_configured() or !$plugin->get_wp_register_active()) {
return $errors;
}

$errorPrefix = '<strong>' . __( 'Error', 'wp-captcha' ) . '</strong> : ';
if ( empty( $_POST ) ) {
return new WP_Error("frcaptcha-empty-error", $errorPrefix . FriendlyCaptcha_Plugin::default_error_user_message() . __(" (empty body)", "frcaptcha") );
}

$solution = frcaptcha_get_sanitized_frcaptcha_solution_from_post();

if ( empty( $solution ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ function frcaptcha_wp_reset_password_show_widget() {
add_filter( 'lostpassword_post', 'frcaptcha_wp_reset_password_validate', 10, 1 );

function frcaptcha_wp_reset_password_validate($val) {

if ( empty( $_POST ) ) {
return;
}

$plugin = FriendlyCaptcha_Plugin::$instance;
if (!$plugin->is_configured() or !$plugin->get_wp_reset_password_active()) {
return $val;
}

$errorPrefix = '<strong>' . __( 'Error', 'wp-captcha' ) . '</strong> : ';
if ( empty( $_POST ) ) {
return new WP_Error("frcaptcha-empty-error", $errorPrefix . FriendlyCaptcha_Plugin::default_error_user_message() . __(" (empty body)", "frcaptcha") );
}

$solution = frcaptcha_get_sanitized_frcaptcha_solution_from_post();

if ( empty( $solution ) ) {
Expand Down

0 comments on commit 4d24447

Please sign in to comment.