diff --git a/includes/class-uwp-recaptcha.php b/includes/class-uwp-recaptcha.php index 078f272..a94f24c 100644 --- a/includes/class-uwp-recaptcha.php +++ b/includes/class-uwp-recaptcha.php @@ -147,6 +147,9 @@ public function recaptcha_key_notices() { } public function add_captcha_for_uwp_forms($type){ + if(!uwp_recaptcha_enabled()){ + return; + } $enable_register_form = uwp_get_option('enable_recaptcha_in_register_form'); $enable_login_form = uwp_get_option('enable_recaptcha_in_login_form'); $enable_forgot_form = uwp_get_option('enable_recaptcha_in_forgot_form'); @@ -195,6 +198,10 @@ public function validate_recaptcha($result, $type, $data) { return $result; } + if ( uwp_recaptcha_check_role() ) { // disable captcha as per user role settings + return $result; + } + if(!uwp_recaptcha_enabled() || 1 != uwp_get_option('enable_recaptcha_in_'.$type.'_form') || is_wp_error($result)){ return $result; } diff --git a/includes/functions.php b/includes/functions.php index bc8d716..3c0f362 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -7,7 +7,7 @@ function uwp_recaptcha_check_role() { global $current_user; $role = !empty( $current_user ) && isset( $current_user->roles[0] ) ? $current_user->roles[0] : ''; - if ( $role != '' && ((int)uwp_get_option('disable_recaptcha_role_' . $role, 0) == 1 || in_array($role, uwp_get_option('disable_recaptcha_role_for', false)) )) { // disable captcha + if ( $role != '' && ((int)uwp_get_option('disable_recaptcha_role_' . $role, 0) == 1 || in_array($role, uwp_get_option('disable_recaptcha_role_for', array())) )) { // disable captcha return true; } else { // enable captcha @@ -178,6 +178,10 @@ function uwp_recaptcha_display( $form ) { function uwp_recaptcha_check( $form ) { + if ( uwp_recaptcha_check_role() ) { // disable captcha as per user role settings + return ''; + } + $secret_key = uwp_get_option('recaptcha_api_secret', ''); $remote_addr = filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP ); $response = uwp_recaptcha_get_response( $secret_key, $remote_addr ); @@ -252,6 +256,10 @@ function uwp_recaptcha_enabled(){ } function uwp_recaptcha_get_response( $privatekey, $remote_ip ) { + if(empty($_POST["g-recaptcha-response"])){ + return array('success' => false, 'error-codes' => 'missing-input-secret'); + } + $args = array( 'body' => array( 'secret' => $privatekey, diff --git a/languages/uwp-recaptcha-en_US.mo b/languages/uwp-recaptcha-en_US.mo index b3e4847..0444d02 100644 Binary files a/languages/uwp-recaptcha-en_US.mo and b/languages/uwp-recaptcha-en_US.mo differ diff --git a/languages/uwp-recaptcha-en_US.po b/languages/uwp-recaptcha-en_US.po index b94f54c..169dc05 100644 --- a/languages/uwp-recaptcha-en_US.po +++ b/languages/uwp-recaptcha-en_US.po @@ -1,9 +1,9 @@ msgid "" msgstr "" -"Project-Id-Version: UsersWP - ReCaptcha 1.0.4\n" +"Project-Id-Version: UsersWP - ReCaptcha 1.0.5\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-02 19:42+0530\n" -"PO-Revision-Date: 2019-05-02 19:43+0530\n" +"POT-Creation-Date: 2019-06-28 12:01+0530\n" +"PO-Revision-Date: 2019-06-28 12:01+0530\n" "Last-Translator: \n" "Language-Team: AyeCode \n" "Language: en_US\n" @@ -27,165 +27,189 @@ msgid "ReCaptcha Settings" msgstr "" #: admin/settings.php:27 -msgid "Google ReCaptcha API Key" +msgid "ReCaptcha version" msgstr "" #: admin/settings.php:28 msgid "" +"Select the ReCaptcha version. Heads Up! V2, V3 and " +"invisible recaptcha has different keys. So use keys based on version you " +"select here." +msgstr "" + +#: admin/settings.php:32 +msgid "Select Option" +msgstr "" + +#: admin/settings.php:38 +msgid "Google ReCaptcha API Key" +msgstr "" + +#: admin/settings.php:39 +msgid "" "Enter Re-Captcha site key that you get after site registration at here." +"\"_blank\" href=\"https://www.google.com/recaptcha/admin#list\">here. " +"Recaptcha V2 and V3 has different API key." msgstr "" -#: admin/settings.php:31 +#: admin/settings.php:42 msgid "Enter Google ReCaptcha API Key" msgstr "" -#: admin/settings.php:36 +#: admin/settings.php:47 msgid "Google ReCaptcha API Secret" msgstr "" -#: admin/settings.php:37 +#: admin/settings.php:48 msgid "" "Enter Re-Captcha secret key that you get after site registration at here" +"a>. Recaptcha V2 and V3 has different API secret" msgstr "" -#: admin/settings.php:40 +#: admin/settings.php:51 msgid "Enter Google ReCaptcha API Secret" msgstr "" -#: admin/settings.php:45 -msgid "ReCaptcha version" +#: admin/settings.php:56 +msgid "Minimum verification score" msgstr "" -#: admin/settings.php:46 +#: admin/settings.php:57 msgid "" -"Select the ReCaptcha version. Heads Up! V2 keys " -"will not work with invisible recaptcha, you will have to create new ones." -msgstr "" - -#: admin/settings.php:50 -msgid "Select Option" +"Set the minimum verification score from 0 to 1 (for Recaptcha V3 only). See " +"more here" msgstr "" -#: admin/settings.php:56 +#: admin/settings.php:70 msgid "Enable ReCaptcha in" msgstr "" -#: admin/settings.php:57 -msgid "UsersWP Register Form." +#: admin/settings.php:71 +msgid "UsersWP Register Form" msgstr "" -#: admin/settings.php:65 -msgid "UsersWP Login Form." +#: admin/settings.php:79 +msgid "UsersWP Login Form" msgstr "" -#: admin/settings.php:73 -msgid "UsersWP Forgot Form." +#: admin/settings.php:87 +msgid "UsersWP Forgot Form" msgstr "" -#: admin/settings.php:81 -msgid "UsersWP Account Form." +#: admin/settings.php:95 +msgid "UsersWP Account Form" msgstr "" -#: admin/settings.php:89 -msgid "WP Login Form." +#: admin/settings.php:103 +msgid "WordPress Login Form" msgstr "" -#: admin/settings.php:97 -msgid "WP Register Form." +#: admin/settings.php:111 +msgid "WordPress Registeration Form" msgstr "" -#: admin/settings.php:118 +#: admin/settings.php:132 msgid "Disable reCAPTCHA for" msgstr "" -#: admin/settings.php:119 +#: admin/settings.php:133 msgid "Select the roles to disable ReCaptcha for." msgstr "" -#: admin/settings.php:123 +#: admin/settings.php:137 msgid "Select Roles" msgstr "" -#: admin/settings.php:131 +#: admin/settings.php:145 msgid "Captcha Title" msgstr "" -#: admin/settings.php:132 +#: admin/settings.php:146 msgid "Captcha title to be displayed above captcha code, leave blank to hide." msgstr "" -#: admin/settings.php:140 +#: admin/settings.php:154 msgid "ReCaptcha Theme" msgstr "" -#: admin/settings.php:141 +#: admin/settings.php:155 #, php-format msgid "Select color theme of captcha widget. %sLearn more%s" msgstr "" -#: admin/settings.php:145 +#: admin/settings.php:159 msgid "Light" msgstr "" -#: admin/settings.php:146 +#: admin/settings.php:160 msgid "Dark" msgstr "" -#: admin/settings.php:163 +#: admin/settings.php:177 msgid "UsersWP - Recaptcha" msgstr "" -#: admin/settings.php:164 +#: admin/settings.php:178 msgid "Remove all data when deleted?" msgstr "" -#: admin/settings.php:175 +#: admin/settings.php:189 +msgid "ReCaptcha V3" +msgstr "" + +#: admin/settings.php:190 msgid "ReCaptcha V2" msgstr "" -#: admin/settings.php:176 +#: admin/settings.php:191 msgid "Invisible ReCaptcha" msgstr "" -#: includes/class-uwp-recaptcha.php:157 includes/class-uwp-recaptcha.php:181 -msgid "ERROR: reCAPTCHA verification failed. Try again." +#: includes/class-uwp-recaptcha.php:140 +#, php-format +msgid "" +"UsersWP ReCaptcha addon: API Key and API Secret not set. %sclick here%s to " +"set one." msgstr "" -#: includes/functions.php:121 +#: includes/class-uwp-recaptcha.php:142 #, php-format -msgid "" -"To use reCAPTCHA you must get an API key from here and enter keys in the " -"plugin settings page at here" +msgid "UsersWP ReCaptcha addon: API Key not set. %sclick here%s to set one." msgstr "" -#: includes/functions.php:123 +#: includes/class-uwp-recaptcha.php:144 +#, php-format +msgid "UsersWP ReCaptcha addon: API Secret not set. %sclick here%s to set one." +msgstr "" + +#: includes/functions.php:191 msgid "" -"Error: Something went wrong. Please contact site admin." +"ERROR: reCAPTCHA verification failed. Please try again." msgstr "" -#: includes/functions.php:143 -msgid "Error: reCAPTCHA verification failed. Try again." +#: includes/functions.php:208 +msgid "" +"reCAPTCHA ERROR: The secret parameter is missing or " +"invalid. Please try again." msgstr "" -#: includes/functions.php:328 -#, php-format +#: includes/functions.php:212 msgid "" -"UsersWP ReCaptcha addon: API Key and API Secret not set. %sclick here%s to " -"set one." +"reCAPTCHA ERROR: The response parameter is missing or " +"invalid. Please try again." msgstr "" -#: includes/functions.php:330 -#, php-format -msgid "UsersWP ReCaptcha addon: API Key not set. %sclick here%s to set one." +#: includes/functions.php:215 +msgid "" +"reCAPTCHA ERROR: The request is invalid. Please try again." msgstr "" -#: includes/functions.php:332 -#, php-format -msgid "UsersWP ReCaptcha addon: API Secret not set. %sclick here%s to set one." +#: includes/functions.php:218 +msgid "" +"reCAPTCHA ERROR: The response is no longer valid: either is " +"too old or has been used previously. Please try again." msgstr "" #: uwp_recaptcha.php:36 diff --git a/readme.txt b/readme.txt index 12b7f36..e75f651 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: http://userswp.io/ Tags: recaptcha, frontend, login, register, account, users, restrict, userswp Requires at least: 4.9 Tested up to: 5.2 -Stable tag: 1.0.4 +Stable tag: 1.0.5 License: GPLv3 License URI: http://www.gnu.org/licenses/gpl-3.0.html diff --git a/uwp_recaptcha.php b/uwp_recaptcha.php index 226bf1f..5f58d66 100644 --- a/uwp_recaptcha.php +++ b/uwp_recaptcha.php @@ -3,7 +3,7 @@ Plugin Name: UsersWP - ReCaptcha Plugin URI: https://userswp.io Description: ReCaptcha add-on for UsersWP. -Version: 1.0.4 +Version: 1.0.5 Author: AyeCode Ltd Author URI: https://userswp.io License: GPL-2.0+ @@ -16,7 +16,7 @@ // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; -define( 'UWP_RECAPTCHA_VERSION', '1.0.4' ); +define( 'UWP_RECAPTCHA_VERSION', '1.0.5' ); define( 'UWP_RECAPTCHA_PATH', plugin_dir_path( __FILE__ ) );