google-captcha
Last commit date
bws_menu
2 months ago
css
2 months ago
includes
2 months ago
js
2 months ago
languages
2 months ago
google-captcha.php
2 months ago
readme.txt
2 months ago
screenshot-1.png
2 months ago
screenshot-2.png
2 months ago
screenshot-3.png
2 months ago
screenshot-4.png
2 months ago
screenshot-5.png
2 months ago
screenshot-6.png
2 months ago
screenshot-7.png
2 months ago
screenshot-8.png
2 months ago
google-captcha.php
1629 lines
| 1 | <?php |
| 2 | /** |
| 3 | Plugin Name: reCaptcha by BestWebSoft |
| 4 | Plugin URI: https://bestwebsoft.com/products/wordpress/plugins/google-captcha/ |
| 5 | Description: Protect WordPress website forms from spam entries with Google Captcha (reCaptcha). |
| 6 | Author: BestWebSoft |
| 7 | Text Domain: google-captcha |
| 8 | Domain Path: /languages |
| 9 | Version: 1.87 |
| 10 | Author URI: https://bestwebsoft.com/ |
| 11 | License: GPLv3 or later |
| 12 | */ |
| 13 | |
| 14 | /** |
| 15 | © Copyright 2022 BestWebSoft ( https://support.bestwebsoft.com ) |
| 16 | |
| 17 | This program is free software; you can redistribute it and/or modify |
| 18 | it under the terms of the GNU General Public License, version 2, as |
| 19 | published by the Free Software Foundation. |
| 20 | |
| 21 | This program is distributed in the hope that it will be useful, |
| 22 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | GNU General Public License for more details. |
| 25 | |
| 26 | You should have received a copy of the GNU General Public License |
| 27 | along with this program; if not, write to the Free Software |
| 28 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 29 | */ |
| 30 | |
| 31 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 32 | |
| 33 | require_once dirname( __FILE__ ) . '/includes/forms.php'; |
| 34 | |
| 35 | if ( ! function_exists( 'gglcptch_admin_menu' ) ) { |
| 36 | /** |
| 37 | * Add menu page |
| 38 | */ |
| 39 | function gglcptch_admin_menu() { |
| 40 | global $submenu, $wp_version, $gglcptch_plugin_info; |
| 41 | |
| 42 | if ( ! is_plugin_active( 'google-captcha-pro/google-captcha-pro.php' ) ) { |
| 43 | $settings_page = add_menu_page( |
| 44 | __( 'reCaptcha Settings', 'google-captcha' ), |
| 45 | 'reCaptcha', |
| 46 | 'manage_options', |
| 47 | 'google-captcha.php', |
| 48 | 'gglcptch_add_settings_page', |
| 49 | 'none' |
| 50 | ); |
| 51 | |
| 52 | add_submenu_page( |
| 53 | 'google-captcha.php', |
| 54 | __( 'reCaptcha Settings', 'google-captcha' ), |
| 55 | __( 'Settings', 'google-captcha' ), |
| 56 | 'manage_options', |
| 57 | 'google-captcha.php', |
| 58 | 'gglcptch_add_settings_page' |
| 59 | ); |
| 60 | |
| 61 | $allowlist_page = add_submenu_page( |
| 62 | 'google-captcha.php', |
| 63 | __( 'reCaptcha Allow List', 'google-captcha' ), |
| 64 | __( 'Allow List', 'google-captcha' ), |
| 65 | 'manage_options', |
| 66 | 'google-captcha-allowlist.php', |
| 67 | 'gglcptch_add_settings_page' |
| 68 | ); |
| 69 | |
| 70 | add_submenu_page( |
| 71 | 'google-captcha.php', |
| 72 | 'BWS Panel', |
| 73 | 'BWS Panel', |
| 74 | 'manage_options', |
| 75 | 'gglcptch-bws-panel', |
| 76 | 'bws_add_menu_render' |
| 77 | ); |
| 78 | if ( isset( $submenu['google-captcha.php'] ) ) { |
| 79 | $submenu['google-captcha.php'][] = array( |
| 80 | '<span style="color:#d86463"> ' . __( 'Upgrade to Pro', 'google-captcha' ) . '</span>', |
| 81 | 'manage_options', |
| 82 | 'https://bestwebsoft.com/products/wordpress/plugins/google-captcha/?k=b850d949ccc1239cab0da315c3c822ab&pn=109&v=' . $gglcptch_plugin_info['Version'] . '&wp_v=' . $wp_version, |
| 83 | ); |
| 84 | } |
| 85 | add_action( "load-{$settings_page}", 'gglcptch_add_tabs' ); |
| 86 | add_action( "load-{$allowlist_page}", 'gglcptch_add_tabs' ); |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | if ( ! function_exists( 'gglcptch_plugins_loaded' ) ) { |
| 92 | /** |
| 93 | * Load textdomain |
| 94 | */ |
| 95 | function gglcptch_plugins_loaded() { |
| 96 | load_plugin_textdomain( 'google-captcha', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
| 97 | |
| 98 | include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 99 | $is_user_logged_in = is_user_logged_in(); |
| 100 | |
| 101 | if ( ( is_plugin_active( 'formidable/formidable.php' ) || is_plugin_active( 'formidable-pro/formidable-pro.php' ) ) ) { |
| 102 | require_once( dirname( __FILE__ ) . '/includes/captcha-for-formidable.php' ); |
| 103 | } |
| 104 | |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | if ( ! function_exists( 'gglcptch_init' ) ) { |
| 109 | /** |
| 110 | * Main init function |
| 111 | */ |
| 112 | function gglcptch_init() { |
| 113 | global $gglcptch_plugin_info, $gglcptch_options, $pagenow; |
| 114 | |
| 115 | require_once dirname( __FILE__ ) . '/bws_menu/bws_include.php'; |
| 116 | bws_include_init( plugin_basename( __FILE__ ) ); |
| 117 | |
| 118 | if ( empty( $gglcptch_plugin_info ) ) { |
| 119 | if ( ! function_exists( 'get_plugin_data' ) ) { |
| 120 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 121 | } |
| 122 | $gglcptch_plugin_info = get_plugin_data( __FILE__ ); |
| 123 | } |
| 124 | |
| 125 | /* Function check if plugin is compatible with current WP version */ |
| 126 | bws_wp_min_version_check( plugin_basename( __FILE__ ), $gglcptch_plugin_info, '4.5' ); |
| 127 | |
| 128 | $is_user_edit_page = isset( $pagenow ) && 'user-edit.php' === $pagenow; |
| 129 | $is_admin = is_admin() && ( ! defined( 'DOING_AJAX' ) || ! $is_user_edit_page ); |
| 130 | |
| 131 | /* Call register settings function */ |
| 132 | if ( ! $is_admin || ( isset( $_GET['page'] ) && 'google-captcha.php' === sanitize_text_field( wp_unslash( $_GET['page'] ) ) ) ) { |
| 133 | register_gglcptch_settings(); |
| 134 | } |
| 135 | |
| 136 | /* Add hooks */ |
| 137 | if ( ! $is_admin && ! empty( $gglcptch_options['public_key'] ) && ! empty( $gglcptch_options['private_key'] ) ) { |
| 138 | gglcptch_add_actions(); |
| 139 | } |
| 140 | |
| 141 | if ( isset( $gglcptch_options['hide_login'] ) && 1 === $gglcptch_options['hide_login'] && isset( $gglcptch_options['slug_login'] ) && ! empty( $gglcptch_options['slug_login'] ) ) { |
| 142 | $request_url = sanitize_url( wp_unslash( $_SERVER['REQUEST_URI'] ) ); |
| 143 | add_filter( 'site_url', 'gglcptch_check_login_url', 10, 4 ); |
| 144 | add_action( 'login_init', 'gglcptch_login_head', 10 ); |
| 145 | add_action( 'login_form', 'gglcptch_add_field' ); |
| 146 | |
| 147 | add_filter( 'lostpassword_url', 'gglcptch_lostpassword', 10 ); |
| 148 | add_filter( 'lostpassword_redirect', 'gglcptch_lostpassword_redirect', 100 ); |
| 149 | |
| 150 | global $pagenow; |
| 151 | if ( ( false !== strpos( $request_url, '/admin' ) || false !== strpos( $request_url, '/wp-admin' ) || false !== strpos( $request_url, '/dashboard' ) ) && 'index.php' === $pagenow ) { |
| 152 | $url = get_site_url() . '/?' . $gglcptch_options['slug_login']; |
| 153 | wp_safe_redirect( $url ); |
| 154 | exit(); |
| 155 | } |
| 156 | |
| 157 | if ( false !== strpos( wp_parse_url( $request_url, PHP_URL_QUERY ), $gglcptch_options['slug_login'] ) && false === strpos( $request_url, 'wp-login.php' ) ) { |
| 158 | $pagenow = 'wp-login.php'; |
| 159 | require_once( ABSPATH . 'wp-login.php' ); |
| 160 | exit; |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | if ( ! function_exists( 'gglcptch_check_login_url' ) ) { |
| 167 | /** |
| 168 | * Change login URI |
| 169 | */ |
| 170 | function gglcptch_check_login_url( $url, $path, $scheme, $blog_id ) { |
| 171 | global $gglcptch_options; |
| 172 | $parsed_url = wp_parse_url( $url ); |
| 173 | |
| 174 | if ( strpos( $url, 'wp-login.php' ) === false || empty( $gglcptch_options['slug_login'] ) ) { |
| 175 | return $url; |
| 176 | } |
| 177 | |
| 178 | $args = explode( '?', $url ); |
| 179 | |
| 180 | if ( isset( $args[1] ) ) { |
| 181 | parse_str( $args[1], $args ); |
| 182 | if ( ! array_key_exists( $gglcptch_options['slug_login'], $args ) ) { |
| 183 | $args[ $gglcptch_options['slug_login'] ] = 1; |
| 184 | } |
| 185 | $url = add_query_arg( $args, get_site_url() . '/?' . $gglcptch_options['slug_login'] ); |
| 186 | } else { |
| 187 | $url = get_site_url() . '/?' . $gglcptch_options['slug_login']; |
| 188 | } |
| 189 | return $url; |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | if ( ! function_exists( 'gglcptch_login_head' ) ) { |
| 194 | /** |
| 195 | * Changed for login page |
| 196 | */ |
| 197 | function gglcptch_login_head() { |
| 198 | global $gglcptch_options; |
| 199 | if ( isset( $_GET['action'] ) && ( isset( $_GET['key'] ) || 'resetpass' === sanitize_text_field( wp_unslash( $_GET['action'] ) ) || 'rp' === sanitize_text_field( $_GET['action'] ) ) ) { |
| 200 | return; |
| 201 | } |
| 202 | |
| 203 | if ( isset( $_POST['redirect_slug'] ) && $gglcptch_options['slug_login'] === sanitize_text_field( wp_unslash( $_POST['redirect_slug'] ) ) ) { |
| 204 | return false; |
| 205 | } |
| 206 | |
| 207 | $request_url = sanitize_url( wp_unslash( $_SERVER['REQUEST_URI'] ) ); |
| 208 | |
| 209 | if ( false !== strpos( $request_url, 'action=logout' ) ) { |
| 210 | check_admin_referer( 'log-out' ); |
| 211 | wp_logout(); |
| 212 | wp_safe_redirect( home_url(), 302 ); |
| 213 | die; |
| 214 | } |
| 215 | if ( false === strpos( $request_url, $gglcptch_options['slug_login'] ) && ( false !== strpos( $request_url, 'wp-login' ) || false !== strpos( $request_url, 'login' ) ) ) { |
| 216 | wp_safe_redirect( home_url( $gglcptch_options['login_error_redirection'] ), 302 ); |
| 217 | exit(); |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | if ( ! function_exists( 'gglcptch_add_field' ) ) { |
| 223 | /** |
| 224 | * Add field for login form |
| 225 | */ |
| 226 | function gglcptch_add_field() { |
| 227 | global $gglcptch_options; |
| 228 | echo '<input type="hidden" name="redirect_slug" value="' . esc_attr( $gglcptch_options['slug_login'] ) . '" />'; |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | if ( ! function_exists( 'gglcptch_lostpassword_redirect' ) ) { |
| 233 | /** |
| 234 | * Change lost password link in email |
| 235 | */ |
| 236 | function gglcptch_lostpassword_redirect( $lostpassword_redirect ) { |
| 237 | global $gglcptch_options; |
| 238 | return 'wp-login.php?checkemail=confirm&redirect=false&' . $gglcptch_options['slug_login']; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | if ( ! function_exists( 'gglcptch_lostpassword' ) ) { |
| 243 | /** |
| 244 | * Change lost password link |
| 245 | */ |
| 246 | function gglcptch_lostpassword() { |
| 247 | global $gglcptch_options; |
| 248 | return site_url( 'wp-login.php?action=lostpassword&' . $gglcptch_options['slug_login'] . '&redirect=false' ); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | if ( ! function_exists( 'gglcptch_plugin_activate' ) ) { |
| 253 | /** |
| 254 | * Activation plugin function |
| 255 | */ |
| 256 | function gglcptch_plugin_activate() { |
| 257 | /* Activation function for network, check if it is a network activation - if so, run the activation function for each blog id */ |
| 258 | if ( is_multisite() ) { |
| 259 | switch_to_blog( 1 ); |
| 260 | register_uninstall_hook( __FILE__, 'gglcptch_delete_options' ); |
| 261 | restore_current_blog(); |
| 262 | } else { |
| 263 | register_uninstall_hook( __FILE__, 'gglcptch_delete_options' ); |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | if ( ! function_exists( 'gglcptch_admin_init' ) ) { |
| 269 | /** |
| 270 | * Init for dashboard |
| 271 | */ |
| 272 | function gglcptch_admin_init() { |
| 273 | global $pagenow, $bws_plugin_info, $gglcptch_plugin_info, $gglcptch_options; |
| 274 | |
| 275 | if ( empty( $bws_plugin_info ) ) { |
| 276 | $bws_plugin_info = array( |
| 277 | 'id' => '109', |
| 278 | 'version' => $gglcptch_plugin_info['Version'], |
| 279 | ); |
| 280 | } |
| 281 | |
| 282 | if ( 'plugins.php' === $pagenow ) { |
| 283 | if ( empty( $gglcptch_options ) ) { |
| 284 | register_gglcptch_settings(); |
| 285 | } |
| 286 | |
| 287 | if ( function_exists( 'bws_plugin_banner_go_pro' ) ) { |
| 288 | bws_plugin_banner_go_pro( $gglcptch_options, $gglcptch_plugin_info, 'gglcptch', 'google-captcha', '676d9558f9786ab41d7de35335cf5c4d', '109', 'google-captcha' ); |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | if ( ! function_exists( 'gglcptch_add_admin_script_styles' ) ) { |
| 295 | /** |
| 296 | * Add google captcha styles |
| 297 | */ |
| 298 | function gglcptch_add_admin_script_styles() { |
| 299 | global $gglcptch_plugin_info; |
| 300 | |
| 301 | /* Css for displaing an icon */ |
| 302 | wp_enqueue_style( 'gglcptch_admin_page_stylesheet', plugins_url( 'css/admin_page.css', __FILE__ ), false, $gglcptch_plugin_info['Version'] ); |
| 303 | |
| 304 | if ( isset( $_REQUEST['page'] ) && ( 'google-captcha.php' === sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ) || 'google-captcha-allowlist.php' === sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ) ) ) { |
| 305 | wp_enqueue_style( 'gglcptch_stylesheet', plugins_url( 'css/style.css', __FILE__ ), array(), $gglcptch_plugin_info['Version'] ); |
| 306 | wp_enqueue_script( 'gglcptch_admin_script', plugins_url( 'js/admin_script.js', __FILE__ ), array( 'jquery', 'jquery-ui-accordion' ), $gglcptch_plugin_info['Version'] . '.1', true ); |
| 307 | |
| 308 | bws_enqueue_settings_scripts(); |
| 309 | bws_plugins_include_codemirror(); |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | if ( ! function_exists( 'gglcptch_add_login_styles' ) ) { |
| 314 | /** |
| 315 | * Add reCaptcha styles for login page |
| 316 | */ |
| 317 | function gglcptch_add_login_styles() { |
| 318 | global $gglcptch_plugin_info, $gglcptch_options; |
| 319 | |
| 320 | wp_enqueue_style( 'gglcptch_stylesheet', plugins_url( 'css/login-style.css', __FILE__ ), array(), $gglcptch_plugin_info['Version'] ); |
| 321 | |
| 322 | if ( isset( $gglcptch_options['disable_view_source'] ) && 1 === $gglcptch_options['disable_view_source'] ) { |
| 323 | wp_enqueue_script( 'gglcptch_source_script', plugins_url( 'js/source-script.js', __FILE__ ), array( 'jquery' ), $gglcptch_plugin_info['Version'], true ); |
| 324 | |
| 325 | wp_localize_script( |
| 326 | 'gglcptch_source_script', |
| 327 | 'gglcptchSource', |
| 328 | array( |
| 329 | 'disable_view_source' => $gglcptch_options['disable_view_source'], |
| 330 | ) |
| 331 | ); |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | if ( ! function_exists( 'gglcptch_admin_footer' ) ) { |
| 337 | /** |
| 338 | * Add google captcha admin styles for test key |
| 339 | */ |
| 340 | function gglcptch_admin_footer() { |
| 341 | global $gglcptch_plugin_info, $gglcptch_options; |
| 342 | if ( isset( $_REQUEST['page'] ) && 'google-captcha.php' === sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ) ) { |
| 343 | |
| 344 | /* update $gglcptch_options */ |
| 345 | register_gglcptch_settings(); |
| 346 | |
| 347 | $api_url = gglcptch_get_api_url(); |
| 348 | |
| 349 | /* for gglcptch test key */ |
| 350 | if ( isset( $gglcptch_options['recaptcha_version'] ) && in_array( $gglcptch_options['recaptcha_version'], array( 'v2', 'invisible' ) ) ) { |
| 351 | $deps = ( ! empty( $gglcptch_options['disable_submit'] ) ) ? array( 'gglcptch_pre_api' ) : array( 'jquery' ); |
| 352 | } else { |
| 353 | $deps = array(); |
| 354 | } |
| 355 | wp_register_script( 'gglcptch_api', $api_url, $deps, $gglcptch_plugin_info['Version'], true ); |
| 356 | gglcptch_add_scripts(); |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | if ( ! function_exists( 'gglcptch_enqueue_scripts' ) ) { |
| 362 | /** |
| 363 | * Add google captcha to footer |
| 364 | */ |
| 365 | function gglcptch_enqueue_scripts() { |
| 366 | global $gglcptch_plugin_info, $gglcptch_options; |
| 367 | |
| 368 | if ( isset( $gglcptch_options['disable_view_source'] ) && 1 === $gglcptch_options['disable_view_source'] ) { |
| 369 | wp_enqueue_script( 'gglcptch_source_script', plugins_url( 'js/source-script.js', __FILE__ ), array( 'jquery' ), $gglcptch_plugin_info['Version'], true ); |
| 370 | |
| 371 | wp_localize_script( |
| 372 | 'gglcptch_source_script', |
| 373 | 'gglcptchSource', |
| 374 | array( |
| 375 | 'disable_view_source' => $gglcptch_options['disable_view_source'], |
| 376 | ) |
| 377 | ); |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | if ( ! function_exists( 'gglcptch_remove_dublicate_scripts' ) ) { |
| 383 | /** |
| 384 | * Remove dublicate scripts |
| 385 | */ |
| 386 | function gglcptch_remove_dublicate_scripts() { |
| 387 | global $wp_scripts; |
| 388 | |
| 389 | if ( ! is_object( $wp_scripts ) || empty( $wp_scripts ) ) { |
| 390 | return false; |
| 391 | } |
| 392 | |
| 393 | foreach ( $wp_scripts->registered as $script_name => $args ) { |
| 394 | if ( preg_match( '|google\.com/recaptcha/api\.js|', $args->src ) && 'gglcptch_api' !== $script_name ) { |
| 395 | /* remove a previously enqueued script */ |
| 396 | wp_dequeue_script( $script_name ); |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | |
| 403 | if ( ! function_exists( 'gglcptch_add_styles' ) ) { |
| 404 | /** |
| 405 | * Add google captcha styles |
| 406 | */ |
| 407 | function gglcptch_add_styles() { |
| 408 | global $gglcptch_plugin_info, $gglcptch_options; |
| 409 | wp_enqueue_style( 'gglcptch', plugins_url( 'css/gglcptch.css', __FILE__ ), array(), $gglcptch_plugin_info['Version'] ); |
| 410 | |
| 411 | if ( defined( 'BWS_ENQUEUE_ALL_SCRIPTS' ) && BWS_ENQUEUE_ALL_SCRIPTS ) { |
| 412 | if ( ! wp_script_is( 'gglcptch_api', 'registered' ) ) { |
| 413 | $api_url = gglcptch_get_api_url(); |
| 414 | if ( isset( $gglcptch_options['recaptcha_version'] ) && in_array( $gglcptch_options['recaptcha_version'], array( 'v2', 'invisible' ) ) ) { |
| 415 | $deps = ( ! empty( $gglcptch_options['disable_submit'] ) ) ? array( 'gglcptch_pre_api' ) : array( 'jquery' ); |
| 416 | } else { |
| 417 | $deps = array(); |
| 418 | } |
| 419 | |
| 420 | wp_register_script( 'gglcptch_api', $api_url, $deps, $gglcptch_plugin_info['Version'], true ); |
| 421 | |
| 422 | add_action( 'wp_footer', 'gglcptch_add_scripts' ); |
| 423 | if ( |
| 424 | $gglcptch_options['login_form'] || |
| 425 | $gglcptch_options['reset_pwd_form'] || |
| 426 | $gglcptch_options['registration_form'] |
| 427 | ) { |
| 428 | add_action( 'login_footer', 'gglcptch_add_scripts' ); |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | if ( ! function_exists( 'gglcptch_add_scripts' ) ) { |
| 436 | /** |
| 437 | * Add google captcha js scripts |
| 438 | */ |
| 439 | function gglcptch_add_scripts() { |
| 440 | global $gglcptch_options, $gglcptch_plugin_info; |
| 441 | |
| 442 | if ( empty( $gglcptch_options ) ) { |
| 443 | register_gglcptch_settings(); |
| 444 | } |
| 445 | |
| 446 | if ( isset( $gglcptch_options['recaptcha_version'] ) ) { |
| 447 | gglcptch_remove_dublicate_scripts(); |
| 448 | if ( ! empty( $gglcptch_options['disable_submit'] ) ) { |
| 449 | wp_enqueue_script( 'gglcptch_pre_api', plugins_url( 'js/pre-api-script.js', __FILE__ ), array( 'jquery' ), $gglcptch_plugin_info['Version'], true ); |
| 450 | wp_localize_script( |
| 451 | 'gglcptch_pre_api', |
| 452 | 'gglcptch_pre', |
| 453 | array( |
| 454 | 'messages' => array( |
| 455 | 'in_progress' => __( 'Please wait until Google reCAPTCHA is loaded.', 'google-captcha' ), |
| 456 | 'timeout' => __( 'Failed to load Google reCAPTCHA. Please check your internet connection and reload this page.', 'google-captcha' ), |
| 457 | ), |
| 458 | 'custom_callback' => apply_filters( 'gglcptch_custom_callback', '' ), |
| 459 | ) |
| 460 | ); |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | wp_enqueue_script( 'gglcptch_script', plugins_url( 'js/script.js', __FILE__ ), array( 'jquery', 'gglcptch_api' ), $gglcptch_plugin_info['Version'], true ); |
| 465 | |
| 466 | do_action( 'gglcptch_custom_enqueue_script' ); |
| 467 | |
| 468 | $options = array( |
| 469 | 'version' => $gglcptch_options['recaptcha_version'], |
| 470 | 'sitekey' => $gglcptch_options['public_key'], |
| 471 | 'error' => sprintf( '<strong>%s</strong>: %s', __( 'Warning', 'google-captcha' ), gglcptch_get_message( 'multiple_blocks' ) ), |
| 472 | 'disable' => $gglcptch_options['disable_submit_button'], |
| 473 | ); |
| 474 | |
| 475 | if ( 'v2' === $gglcptch_options['recaptcha_version'] ) { |
| 476 | $options['theme'] = $gglcptch_options['theme_v2']; |
| 477 | } |
| 478 | |
| 479 | wp_localize_script( |
| 480 | 'gglcptch_script', |
| 481 | 'gglcptch', |
| 482 | array( |
| 483 | 'options' => $options, |
| 484 | 'vars' => array( |
| 485 | 'visibility' => ( 'login_footer' === current_filter() ), |
| 486 | ), |
| 487 | ) |
| 488 | ); |
| 489 | |
| 490 | if ( $gglcptch_options['hide_badge'] ) { |
| 491 | wp_enqueue_style( 'gglcptch_hide', plugins_url( 'css/hide_badge.css', __FILE__ ), array(), $gglcptch_plugin_info['Version'] ); |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | if ( ! function_exists( 'gglcptch_pagination_callback' ) ) { |
| 497 | /** |
| 498 | * Callback function |
| 499 | * |
| 500 | * @param string $content Content from for pagination plugin. |
| 501 | * |
| 502 | * @return string $content |
| 503 | */ |
| 504 | function gglcptch_pagination_callback( $content ) { |
| 505 | $content .= "if ( typeof Recaptcha != 'undefined' || typeof grecaptcha != 'undefined' ) { gglcptch.prepare(); }"; |
| 506 | return $content; |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | |
| 511 | if ( ! function_exists( 'gglcptch_add_async_attribute' ) ) { |
| 512 | /** |
| 513 | * Add the "async" attribute to our registered script. |
| 514 | * |
| 515 | * @param string $tag Tag for link. |
| 516 | * @param string $handle Id for link. |
| 517 | * |
| 518 | * @return string $tag |
| 519 | */ |
| 520 | function gglcptch_add_async_attribute( $tag, $handle ) { |
| 521 | if ( 'gglcptch_api' === $handle ) { |
| 522 | $tag = str_replace( ' src', ' data-cfasync="false" async="async" defer="defer" src', $tag ); |
| 523 | } |
| 524 | return $tag; |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | if ( ! function_exists( 'gglcptch_create_table' ) ) { |
| 529 | /** |
| 530 | * Create table in db |
| 531 | */ |
| 532 | function gglcptch_create_table() { |
| 533 | global $wpdb; |
| 534 | require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 535 | |
| 536 | $sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}gglcptch_allowlist` ( |
| 537 | `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, |
| 538 | `ip` CHAR(31) NOT NULL, |
| 539 | `ip_from_int` BIGINT, |
| 540 | `ip_to_int` BIGINT, |
| 541 | `add_time` DATETIME, |
| 542 | PRIMARY KEY (`id`) |
| 543 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; |
| 544 | dbDelta( $sql ); |
| 545 | |
| 546 | /* add unique key */ |
| 547 | if ( ! $wpdb->query( "SHOW KEYS FROM `{$wpdb->prefix}gglcptch_allowlist` WHERE Key_name='ip'" ) ) { |
| 548 | $wpdb->query( "ALTER TABLE `{$wpdb->prefix}gglcptch_allowlist` ADD UNIQUE(`ip`);" ); |
| 549 | } |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | if ( ! function_exists( 'register_gglcptch_settings' ) ) { |
| 554 | /** |
| 555 | * Google catpcha settings |
| 556 | */ |
| 557 | function register_gglcptch_settings() { |
| 558 | global $wpdb, $gglcptch_options, $gglcptch_plugin_info; |
| 559 | |
| 560 | if ( empty( $gglcptch_plugin_info ) ) { |
| 561 | if ( ! function_exists( 'get_plugin_data' ) ) { |
| 562 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 563 | } |
| 564 | $gglcptch_plugin_info = get_plugin_data( __FILE__ ); |
| 565 | } |
| 566 | |
| 567 | $plugin_db_version = '0.2'; |
| 568 | |
| 569 | /* Install the option defaults */ |
| 570 | if ( ! get_option( 'gglcptch_options' ) ) { |
| 571 | add_option( 'gglcptch_options', gglcptch_get_default_options() ); |
| 572 | } |
| 573 | /* Get options from the database */ |
| 574 | $gglcptch_options = get_option( 'gglcptch_options' ); |
| 575 | |
| 576 | /* Update tables when update plugin and tables changes*/ |
| 577 | if ( ! isset( $gglcptch_options['plugin_db_version'] ) || $gglcptch_options['plugin_db_version'] !== $plugin_db_version ) { |
| 578 | |
| 579 | if ( ! isset( $gglcptch_options['plugin_db_version'] ) ) { |
| 580 | gglcptch_create_table(); |
| 581 | } |
| 582 | |
| 583 | /** |
| 584 | * @deprecated since 1.59 |
| 585 | * @todo remove after 01.05.2021 |
| 586 | */ |
| 587 | if ( isset( $gglcptch_options['plugin_option_version'] ) && version_compare( $gglcptch_options['plugin_option_version'], '1.59', '<' ) ) { |
| 588 | $prefix = $wpdb->prefix . 'gglcptch_'; |
| 589 | /* Renaming a table */ |
| 590 | $wpdb->query( 'RENAME TABLE `' . $prefix . 'whitelist` TO `' . $prefix . 'allowlist`' ); |
| 591 | |
| 592 | /* Renaming old options to DB */ |
| 593 | $gglcptch_options['allowlist_is_empty'] = $gglcptch_options['whitelist_is_empty']; |
| 594 | $gglcptch_options['allowlist_message'] = $gglcptch_options['whitelist_message']; |
| 595 | } |
| 596 | /* end deprecated */ |
| 597 | |
| 598 | $gglcptch_options['plugin_db_version'] = $plugin_db_version; |
| 599 | update_option( 'gglcptch_options', $gglcptch_options ); |
| 600 | } |
| 601 | |
| 602 | /* Array merge incase this version has added new options */ |
| 603 | if ( ! isset( $gglcptch_options['plugin_option_version'] ) || $gglcptch_options['plugin_option_version'] !== $gglcptch_plugin_info['Version'] ) { |
| 604 | $gglcptch_options = array_merge( gglcptch_get_default_options(), $gglcptch_options ); |
| 605 | $gglcptch_options['plugin_option_version'] = $gglcptch_plugin_info['Version']; |
| 606 | |
| 607 | /* show pro features */ |
| 608 | $gglcptch_options['hide_premium_options'] = array(); |
| 609 | |
| 610 | if ( is_multisite() ) { |
| 611 | switch_to_blog( 1 ); |
| 612 | register_uninstall_hook( __FILE__, 'gglcptch_delete_options' ); |
| 613 | restore_current_blog(); |
| 614 | } else { |
| 615 | register_uninstall_hook( __FILE__, 'gglcptch_delete_options' ); |
| 616 | } |
| 617 | update_option( 'gglcptch_options', $gglcptch_options ); |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | if ( ! function_exists( 'gglcptch_get_default_options' ) ) { |
| 623 | /** |
| 624 | * Default options for plugin |
| 625 | */ |
| 626 | function gglcptch_get_default_options() { |
| 627 | global $gglcptch_plugin_info; |
| 628 | |
| 629 | $default_options = array( |
| 630 | 'allowlist_message' => __( 'You are in the allow list', 'google-captcha' ), |
| 631 | 'error_message' => __( 'The reCaptcha verification failed. Please try again.', 'google-captcha' ), |
| 632 | 'empty_error_message' => __( 'The reCaptcha verification failed. Please try again.', 'google-captcha' ), |
| 633 | 'public_key' => '', |
| 634 | 'private_key' => '', |
| 635 | 'login_form' => 0, |
| 636 | 'registration_form' => 0, |
| 637 | 'reset_pwd_form' => 1, |
| 638 | 'password_form' => 0, |
| 639 | 'comments_form' => 0, |
| 640 | 'contact_form' => 0, |
| 641 | 'testimonials' => 0, |
| 642 | 'frm_contact_form' => 0, |
| 643 | 'theme_v2' => 'light', |
| 644 | 'recaptcha_version' => 'v2', |
| 645 | 'plugin_option_version' => $gglcptch_plugin_info['Version'], |
| 646 | 'first_install' => strtotime( 'now' ), |
| 647 | 'display_settings_notice' => 1, |
| 648 | 'suggest_feature_banner' => 1, |
| 649 | 'score_v3' => 0.5, |
| 650 | 'hide_badge' => 0, |
| 651 | 'disable_submit_button' => 0, |
| 652 | 'use_globally' => 0, |
| 653 | 'weekdays' => array( 1, 2, 3, 4, 5, 6, 7 ), |
| 654 | 'all_day' => array( 1, 2, 3, 4, 5, 6, 7 ), |
| 655 | 'hours' => array(), |
| 656 | 'hide_login' => 0, |
| 657 | 'slug_login' => '', |
| 658 | 'login_error_redirection' => '404', |
| 659 | 'fsp_enable' => 0, |
| 660 | 'fsp_length' => 12, |
| 661 | 'fsp_error_message' => __( 'Password must be at least {min_length} characters long and include uppercase and lowercase letters, numbers and symbols.', 'google-captcha' ), |
| 662 | 'disable_view_source' => 0, |
| 663 | ); |
| 664 | |
| 665 | if ( function_exists( 'get_editable_roles' ) ) { |
| 666 | foreach ( get_editable_roles() as $role => $fields ) { |
| 667 | $default_options[ $role ] = '0'; |
| 668 | } |
| 669 | } |
| 670 | return $default_options; |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | if ( ! function_exists( 'gglcptch_plugin_status' ) ) { |
| 675 | /** |
| 676 | * Status for plugin |
| 677 | * |
| 678 | * @param array $plugins BWS plugins. |
| 679 | * @param array $all_plugins All plugins on the site. |
| 680 | * @param bool $is_network Flag for network. |
| 681 | * |
| 682 | * @return array $result |
| 683 | */ |
| 684 | function gglcptch_plugin_status( $plugins, $all_plugins, $is_network ) { |
| 685 | $result = array( |
| 686 | 'status' => '', |
| 687 | 'plugin' => '', |
| 688 | 'plugin_info' => array(), |
| 689 | ); |
| 690 | foreach ( (array) $plugins as $plugin ) { |
| 691 | if ( array_key_exists( $plugin, $all_plugins ) ) { |
| 692 | if ( |
| 693 | ( $is_network && is_plugin_active_for_network( $plugin ) ) || |
| 694 | ( ! $is_network && is_plugin_active( $plugin ) ) |
| 695 | ) { |
| 696 | $result['status'] = 'activated'; |
| 697 | $result['plugin'] = $plugin; |
| 698 | $result['plugin_info'] = $all_plugins[ $plugin ]; |
| 699 | break; |
| 700 | } else { |
| 701 | $result['status'] = 'deactivated'; |
| 702 | $result['plugin'] = $plugin; |
| 703 | $result['plugin_info'] = $all_plugins[ $plugin ]; |
| 704 | } |
| 705 | } |
| 706 | } |
| 707 | if ( empty( $result['status'] ) ) { |
| 708 | $result['status'] = 'not_installed'; |
| 709 | } |
| 710 | return $result; |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | if ( ! function_exists( 'gglcptch_allowlisted_ip' ) ) { |
| 715 | /** |
| 716 | * Check IP in allow table |
| 717 | */ |
| 718 | function gglcptch_allowlisted_ip() { |
| 719 | global $wpdb, $gglcptch_options; |
| 720 | $checked = false; |
| 721 | if ( empty( $gglcptch_options ) ) { |
| 722 | $gglcptch_options = get_option( 'gglcptch_options' ); |
| 723 | } |
| 724 | $allowlist_exist = $wpdb->query( "SHOW TABLES LIKE '{$wpdb->prefix}gglcptch_allowlist'" ); |
| 725 | if ( 1 === $allowlist_exist ) { |
| 726 | $ip = gglcptch_get_ip(); |
| 727 | |
| 728 | if ( ! empty( $ip ) ) { |
| 729 | $ip_int = sprintf( '%u', ip2long( $ip ) ); |
| 730 | $result = $wpdb->get_var( |
| 731 | $wpdb->prepare( |
| 732 | 'SELECT `id` |
| 733 | FROM `' . $wpdb->prefix . 'gglcptch_allowlist` |
| 734 | WHERE ( `ip_from_int` <= %d AND `ip_to_int` >= %d ) OR `ip` LIKE %s LIMIT 1;', |
| 735 | $ip_int, |
| 736 | $ip_int, |
| 737 | $ip |
| 738 | ) |
| 739 | ); |
| 740 | $checked = is_null( $result ) || ! $result ? false : true; |
| 741 | } |
| 742 | } |
| 743 | return $checked; |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | if ( ! function_exists( 'gglcptch_add_settings_page' ) ) { |
| 748 | /** |
| 749 | * Display settings page |
| 750 | */ |
| 751 | function gglcptch_add_settings_page() { |
| 752 | global $gglcptch_plugin_info; |
| 753 | /*pls */ |
| 754 | require_once dirname( __FILE__ ) . '/includes/pro_banners.php'; |
| 755 | /* pls*/ |
| 756 | if ( 'google-captcha.php' === sanitize_text_field( wp_unslash( $_GET['page'] ) ) ) { |
| 757 | if ( ! class_exists( 'Bws_Settings_Tabs' ) ) { |
| 758 | require_once dirname( __FILE__ ) . '/bws_menu/class-bws-settings.php'; |
| 759 | } |
| 760 | require_once dirname( __FILE__ ) . '/includes/class-gglcptch-settings-tabs.php'; |
| 761 | $page = new Gglcptch_Settings_Tabs( plugin_basename( __FILE__ ) ); |
| 762 | if ( method_exists( $page, 'add_request_feature' ) ) { |
| 763 | $page->add_request_feature(); |
| 764 | } |
| 765 | } ?> |
| 766 | <div class="wrap"> |
| 767 | <?php if ( 'google-captcha.php' === sanitize_text_field( wp_unslash( $_GET['page'] ) ) ) { ?> |
| 768 | <h1><?php esc_html_e( 'reCaptcha Settings', 'google-captcha' ); ?></h1> |
| 769 | <noscript><div class="error below-h2"><p><strong><?php esc_html_e( 'Please enable JavaScript in your browser.', 'google-captcha' ); ?></strong></p></div></noscript> |
| 770 | <?php |
| 771 | if ( function_exists( 'bws_plugin_promo_banner' ) ) { |
| 772 | echo bws_plugin_promo_banner( $gglcptch_plugin_info, 'gglcptch_options', 'google-captcha', 'https://bestwebsoft.com/products/wordpress/plugins/google-captcha/?utm_source=wordpress&utm_medium=plugin_banner&utm_campaign=upgrade' ); |
| 773 | } |
| 774 | ?> |
| 775 | <?php |
| 776 | $page->display_content(); |
| 777 | } else { |
| 778 | require_once dirname( __FILE__ ) . '/includes/allowlist.php'; |
| 779 | $page = new Gglcptch_Allowlist( plugin_basename( __FILE__ ) ); |
| 780 | if ( is_object( $page ) ) { |
| 781 | $page->display_content(); |
| 782 | } |
| 783 | bws_plugin_reviews_block( $gglcptch_plugin_info['Name'], 'google-captcha' ); |
| 784 | } |
| 785 | ?> |
| 786 | </div> |
| 787 | <?php |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | if ( ! function_exists( 'gglcptch_is_recaptcha_required' ) ) { |
| 792 | /** |
| 793 | * Check the need for recaptcha for the form |
| 794 | * |
| 795 | * @param string $form_slug (Optional) Slug for form. |
| 796 | * @param bool $is_user_logged_in (Optional) Flag is user logged in. |
| 797 | * |
| 798 | * @return bool $result |
| 799 | */ |
| 800 | function gglcptch_is_recaptcha_required( $form_slug = '', $is_user_logged_in = null ) { |
| 801 | global $gglcptch_options; |
| 802 | |
| 803 | global $gglcptch_options; |
| 804 | |
| 805 | if ( strstr( $_SERVER['REQUEST_URI'], '/jwt-auth' ) ) { |
| 806 | return false; |
| 807 | } |
| 808 | |
| 809 | if ( is_null( $is_user_logged_in ) ) { |
| 810 | $is_user_logged_in = is_user_logged_in(); |
| 811 | } |
| 812 | |
| 813 | if ( empty( $gglcptch_options ) ) { |
| 814 | $gglcptch_options = get_option( 'gglcptch_options' ); |
| 815 | if ( empty( $gglcptch_options ) ) { |
| 816 | register_gglcptch_settings(); |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | $result = isset( $gglcptch_options[ $form_slug ] ) && ( |
| 821 | ( ! empty( $gglcptch_options[ $form_slug ] ) && is_admin() && ( ! wp_doing_ajax() || ( isset( $_POST['action'] ) && 'wpforms_new_field_gglcptch' === $_POST['action'] ) ) ) || |
| 822 | ( ! empty( $gglcptch_options[ $form_slug ] ) && |
| 823 | ( ! $is_user_logged_in || ! gglcptch_is_hidden_for_role() ) |
| 824 | ) |
| 825 | ); |
| 826 | return apply_filters( 'gglcptch_is_recaptcha_required', $result, $form_slug, $is_user_logged_in ); |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | /* Checking current user role */ |
| 831 | if ( ! function_exists( 'gglcptch_is_hidden_for_role' ) ) { |
| 832 | /** |
| 833 | * Check the need for recaptcha for the user role |
| 834 | */ |
| 835 | function gglcptch_is_hidden_for_role() { |
| 836 | global $current_user, $gglcptch_options; |
| 837 | |
| 838 | if ( ! is_user_logged_in() ) { |
| 839 | return false; |
| 840 | } |
| 841 | |
| 842 | if ( ! empty( $current_user->roles[0] ) ) { |
| 843 | $role = $current_user->roles[0]; |
| 844 | if ( empty( $gglcptch_options ) ) { |
| 845 | register_gglcptch_settings(); |
| 846 | } |
| 847 | return ! empty( $gglcptch_options[ $role ] ); |
| 848 | } else { |
| 849 | return false; |
| 850 | } |
| 851 | } |
| 852 | } |
| 853 | |
| 854 | if ( ! function_exists( 'gglcptch_display' ) ) { |
| 855 | /** |
| 856 | * Display google captcha |
| 857 | * |
| 858 | * @param string $content (Optional) Post content. |
| 859 | * |
| 860 | * @return string $content |
| 861 | */ |
| 862 | function gglcptch_display( $attr = array(), $content = false, $custom = false ) { |
| 863 | global $gglcptch_options, $gglcptch_count, $gglcptch_plugin_info; |
| 864 | |
| 865 | if ( empty( $gglcptch_options ) ) { |
| 866 | register_gglcptch_settings(); |
| 867 | } |
| 868 | |
| 869 | $weekdays_flag = true; |
| 870 | if ( isset( $gglcptch_options['weekdays'] ) ) { |
| 871 | $week_day = date( 'N' ); |
| 872 | $hour = date( 'G' ); |
| 873 | if ( ! in_array( $week_day, $gglcptch_options['weekdays'] ) || ( ! in_array( $week_day, $gglcptch_options['all_day'] ) && ! in_array( $hour, $gglcptch_options['hours'][ $week_day ] ) ) ) { |
| 874 | $weekdays_flag = false; |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | if ( ! gglcptch_allowlisted_ip() && true === $weekdays_flag || ( isset( $_GET['action'] ) && 'gglcptch-test-keys' === sanitize_text_field( wp_unslash( $_GET['action'] ) ) ) ) { |
| 879 | |
| 880 | if ( ! $gglcptch_count ) { |
| 881 | $gglcptch_count = 1; |
| 882 | } |
| 883 | |
| 884 | if ( true === $custom ) { |
| 885 | $content .= '<div class="gglcptch gglcptch_' . $gglcptch_options['recaptcha_version'] . ' gglcptch_custom">'; |
| 886 | } else { |
| 887 | $content .= '<div class="gglcptch gglcptch_' . $gglcptch_options['recaptcha_version'] . '">'; |
| 888 | } |
| 889 | |
| 890 | if ( $gglcptch_options['hide_badge'] && 'v2' !== $gglcptch_options['recaptcha_version'] ) { |
| 891 | $content .= sprintf( |
| 892 | '<div class="google-captcha-notice">%s<a href="https://policies.google.com/privacy" target="_blank">%s</a>%s<a href="https://policies.google.com/terms" target="_blank">%s</a>%s</div>', |
| 893 | esc_html__( 'This site is protected by reCAPTCHA and the Google ', 'google-captcha' ), |
| 894 | esc_html__( 'Privacy Policy', 'google-captcha' ), |
| 895 | esc_html__( ' and ', 'google-captcha' ), |
| 896 | esc_html__( 'Terms of Service', 'google-captcha' ), |
| 897 | esc_html__( ' apply.', 'google-captcha' ) |
| 898 | ); |
| 899 | } |
| 900 | if ( ! $gglcptch_options['private_key'] || ! $gglcptch_options['public_key'] ) { |
| 901 | if ( current_user_can( 'manage_options' ) ) { |
| 902 | $content .= sprintf( |
| 903 | '<strong>%s <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s <a target="_blank" href="%s">%s</a>.</strong>', |
| 904 | esc_html__( 'To use reCaptcha you must get the keys from', 'google-captcha' ), |
| 905 | esc_html__( 'here', 'google-captcha' ), |
| 906 | esc_html__( 'and enter them on the', 'google-captcha' ), |
| 907 | esc_url( admin_url( '/admin.php?page=google-captcha.php' ) ), |
| 908 | esc_html__( 'plugin setting page', 'google-captcha' ) |
| 909 | ); |
| 910 | } |
| 911 | $content .= '</div>'; |
| 912 | $gglcptch_count++; |
| 913 | return $content; |
| 914 | } |
| 915 | |
| 916 | $api_url = gglcptch_get_api_url(); |
| 917 | |
| 918 | /* generating random id value in case of getting content with pagination plugin for not getting duplicate id values */ |
| 919 | $id = wp_rand(); |
| 920 | if ( isset( $gglcptch_options['recaptcha_version'] ) && in_array( $gglcptch_options['recaptcha_version'], array( 'v2', 'invisible' ) ) ) { |
| 921 | if ( true === $custom ) { |
| 922 | $content .= '<input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px !important; height: 40px !important; border: 1px solid #c1c1c1 !important; margin: 10px 25px !important; padding: 0px !important; resize: none !important;">'; |
| 923 | } |
| 924 | $content .= '<div id="gglcptch_recaptcha_' . esc_attr( $id ) . '" class="gglcptch_recaptcha"></div> |
| 925 | <noscript> |
| 926 | <div style="width: 302px;"> |
| 927 | <div style="width: 302px; height: 422px; position: relative;"> |
| 928 | <div style="width: 302px; height: 422px; position: absolute;"> |
| 929 | <iframe src="https://www.google.com/recaptcha/api/fallback?k=' . esc_html( $gglcptch_options['public_key'] ) . '" frameborder="0" scrolling="no" style="width: 302px; height:422px; border-style: none;"></iframe> |
| 930 | </div> |
| 931 | </div> |
| 932 | <div style="border-style: none; bottom: 12px; left: 25px; margin: 0px; padding: 0px; right: 25px; background: #f9f9f9; border: 1px solid #c1c1c1; border-radius: 3px; height: 60px; width: 300px;"> |
| 933 | <input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px !important; height: 40px !important; border: 1px solid #c1c1c1 !important; margin: 10px 25px !important; padding: 0px !important; resize: none !important;"> |
| 934 | </div> |
| 935 | </div> |
| 936 | </noscript>'; |
| 937 | |
| 938 | $deps = ( ! empty( $gglcptch_options['disable_submit'] ) ) ? array( 'gglcptch_pre_api' ) : array( 'jquery' ); |
| 939 | } elseif ( isset( $gglcptch_options['recaptcha_version'] ) && 'v3' === $gglcptch_options['recaptcha_version'] ) { |
| 940 | $content .= '<input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response" /><br /><div class="gglcptch_error_text">' . esc_html__( 'The reCAPTCHA verification period has expired. Please reload the page.', 'google-captcha' ) . '</div>'; |
| 941 | } |
| 942 | $content .= '</div>'; |
| 943 | $gglcptch_count++; |
| 944 | |
| 945 | /* register reCAPTCHA script */ |
| 946 | if ( ! wp_script_is( 'gglcptch_api', 'registered' ) ) { |
| 947 | |
| 948 | if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v3' === $gglcptch_options['recaptcha_version'] ) { |
| 949 | wp_register_script( 'gglcptch_api', $api_url, false, null, false ); |
| 950 | } else { |
| 951 | wp_register_script( 'gglcptch_api', $api_url, $deps, $gglcptch_plugin_info['Version'], true ); |
| 952 | } |
| 953 | add_action( 'wp_footer', 'gglcptch_add_scripts' ); |
| 954 | if ( |
| 955 | $gglcptch_options['login_form'] || |
| 956 | $gglcptch_options['reset_pwd_form'] || |
| 957 | $gglcptch_options['registration_form'] |
| 958 | ) { |
| 959 | add_action( 'login_footer', 'gglcptch_add_scripts' ); |
| 960 | } |
| 961 | } |
| 962 | if ( |
| 963 | ( ! isset( $_SERVER['REQUEST_URI'] ) ) || |
| 964 | ( ! strstr( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), '/wp-login.php' ) ) || |
| 965 | ( '/wp-login.php?action=register' === sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) && $gglcptch_options['registration_form'] ) || |
| 966 | ( '/wp-login.php?action=lostpassword' === sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) && $gglcptch_options['reset_pwd_form'] ) || |
| 967 | ( '/wp-login.php' === sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) && $gglcptch_options['login_form'] ) || |
| 968 | ( strstr( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), '/wp-login.php' ) && strstr( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'loggedout' ) && $gglcptch_options['login_form'] ) |
| 969 | ) { |
| 970 | gglcptch_add_styles(); |
| 971 | } |
| 972 | } elseif ( gglcptch_allowlisted_ip() && ! empty( $gglcptch_options['allowlist_message'] ) ) { |
| 973 | $content .= '<label class="gglcptch_allowlist_message" style="display: block;">' . esc_html( $gglcptch_options['allowlist_message'] ) . '</label>'; |
| 974 | } |
| 975 | |
| 976 | return $content; |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | if ( ! function_exists( 'gglcptch_display_custom' ) ) { |
| 981 | /** |
| 982 | * Return google captcha content for custom form |
| 983 | * |
| 984 | * @param string $content (Optional) Post content. |
| 985 | * @param string $form_slug (Optional) Form slug. |
| 986 | * |
| 987 | * @return string $content |
| 988 | */ |
| 989 | function gglcptch_display_custom( $content = '', $form_slug = '' ) { |
| 990 | if ( gglcptch_is_recaptcha_required( $form_slug ) ) { |
| 991 | $content = gglcptch_display( array(), $content, true ); |
| 992 | } |
| 993 | |
| 994 | return $content; |
| 995 | } |
| 996 | } |
| 997 | |
| 998 | if ( ! function_exists( 'gglcptch_get_api_url' ) ) { |
| 999 | /** |
| 1000 | * Get the reCAPTCHA api js url that corresponds to the reCAPTCHA version. |
| 1001 | */ |
| 1002 | function gglcptch_get_api_url() { |
| 1003 | global $gglcptch_options; |
| 1004 | $use_globally = $gglcptch_options['use_globally'] ? 'recaptcha.net' : 'google.com'; |
| 1005 | |
| 1006 | switch ( true ) { |
| 1007 | case ( |
| 1008 | isset( $gglcptch_options['recaptcha_version'] ) && |
| 1009 | in_array( $gglcptch_options['recaptcha_version'], array( 'v2', 'invisible' ) ) |
| 1010 | ): |
| 1011 | $callback = ( ! empty( $gglcptch_options['disable_submit'] ) ) ? 'onload=gglcptch_onload_callback&' : ''; |
| 1012 | $api_url = sprintf( 'https://www.' . $use_globally . '/recaptcha/api.js?%srender=explicit', $callback ); |
| 1013 | break; |
| 1014 | case ( |
| 1015 | isset( $gglcptch_options['recaptcha_version'] ) && |
| 1016 | 'v3' === $gglcptch_options['recaptcha_version'] |
| 1017 | ): |
| 1018 | $api_url = sprintf( 'https://www.' . $use_globally . '/recaptcha/api.js?render=%s', $gglcptch_options['public_key'] ); |
| 1019 | break; |
| 1020 | default: |
| 1021 | $api_url = 'https://www.google.com/recaptcha/api/js/recaptcha_ajax.js'; |
| 1022 | } |
| 1023 | return $api_url; |
| 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | if ( ! function_exists( 'gglcptch_get_response' ) ) { |
| 1028 | /** |
| 1029 | * Get the reCAPTCHA response |
| 1030 | * |
| 1031 | * @param string $privatekey Private key for reCaptcha. |
| 1032 | * @param string $remote_ip User IP. |
| 1033 | * |
| 1034 | * @return string $result |
| 1035 | */ |
| 1036 | function gglcptch_get_response( $privatekey, $remote_ip ) { |
| 1037 | $args = array( |
| 1038 | 'body' => array( |
| 1039 | 'secret' => $privatekey, |
| 1040 | 'response' => isset( $_POST['g-recaptcha-response'] ) ? sanitize_text_field( wp_unslash( $_POST['g-recaptcha-response'] ) ) : '', |
| 1041 | 'remoteip' => $remote_ip, |
| 1042 | ), |
| 1043 | 'sslverify' => false, |
| 1044 | ); |
| 1045 | $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $args ); |
| 1046 | return json_decode( wp_remote_retrieve_body( $resp ), true ); |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | if ( ! function_exists( 'gglcptch_check' ) ) { |
| 1051 | /** |
| 1052 | * Check google captcha |
| 1053 | * |
| 1054 | * @param string $form (Optional) Form slug. |
| 1055 | * @param bool $debug (Optional) Flag for debug mode. |
| 1056 | * |
| 1057 | * @return array $result |
| 1058 | */ |
| 1059 | function gglcptch_check( $form = 'general', $debug = false ) { |
| 1060 | global $gglcptch_options; |
| 1061 | |
| 1062 | if ( 'reset_pwd_form' === $form && empty( $_REQUEST ) && empty( $_SERVER['REQUEST_URI'] ) ) { |
| 1063 | $result = array( |
| 1064 | 'response' => true, |
| 1065 | 'reason' => '', |
| 1066 | ); |
| 1067 | return $result; |
| 1068 | } |
| 1069 | |
| 1070 | $weekdays_flag = true; |
| 1071 | if ( isset( $gglcptch_options['weekdays'] ) ) { |
| 1072 | $week_day = date( 'N' ); |
| 1073 | $hour = date( 'G' ); |
| 1074 | if ( ! in_array( $week_day, $gglcptch_options['weekdays'] ) || ( ! in_array( $week_day, $gglcptch_options['all_day'] ) && ! in_array( $hour, $gglcptch_options['hours'][ $week_day ] ) ) ) { |
| 1075 | $weekdays_flag = false; |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | if ( ( gglcptch_allowlisted_ip() && 'gglcptch_test' !== $form ) || false === $weekdays_flag ) { |
| 1080 | $result = array( |
| 1081 | 'response' => true, |
| 1082 | 'reason' => '', |
| 1083 | ); |
| 1084 | return $result; |
| 1085 | } |
| 1086 | |
| 1087 | if ( empty( $gglcptch_options ) ) { |
| 1088 | register_gglcptch_settings(); |
| 1089 | } |
| 1090 | |
| 1091 | if ( ! $gglcptch_options['public_key'] || ! $gglcptch_options['private_key'] ) { |
| 1092 | $errors = new WP_Error(); |
| 1093 | $errors->add( 'gglcptch_error', gglcptch_get_message() ); |
| 1094 | return array( |
| 1095 | 'response' => false, |
| 1096 | 'reason' => 'ERROR_NO_KEYS', |
| 1097 | 'errors' => $errors, |
| 1098 | ); |
| 1099 | } |
| 1100 | |
| 1101 | $gglcptch_remote_addr = filter_var( sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ), FILTER_VALIDATE_IP ); |
| 1102 | |
| 1103 | if ( |
| 1104 | isset( $gglcptch_options['recaptcha_version'] ) && |
| 1105 | in_array( $gglcptch_options['recaptcha_version'], array( 'v2', 'invisible', 'v3' ) ) |
| 1106 | ) { |
| 1107 | if ( ! isset( $_POST['g-recaptcha-response'] ) ) { |
| 1108 | $result = array( |
| 1109 | 'response' => false, |
| 1110 | 'reason' => 'RECAPTCHA_NO_RESPONSE', |
| 1111 | ); |
| 1112 | } elseif ( empty( $_POST['g-recaptcha-response'] ) ) { |
| 1113 | $result = array( |
| 1114 | 'response' => false, |
| 1115 | 'reason' => 'RECAPTCHA_EMPTY_RESPONSE', |
| 1116 | ); |
| 1117 | } else { |
| 1118 | $response = gglcptch_get_response( $gglcptch_options['private_key'], $gglcptch_remote_addr ); |
| 1119 | if ( empty( $response ) ) { |
| 1120 | $result = array( |
| 1121 | 'response' => false, |
| 1122 | 'reason' => $debug ? __( 'Response is empty', 'google-captcha' ) : 'VERIFICATION_FAILED', |
| 1123 | ); |
| 1124 | } elseif ( isset( $response['success'] ) && ! ! $response['success'] ) { |
| 1125 | if ( 'v3' === $gglcptch_options['recaptcha_version'] && $response['score'] < $gglcptch_options['score_v3'] ) { |
| 1126 | $result = array( |
| 1127 | 'response' => false, |
| 1128 | 'reason' => 'RECAPTCHA_SMALL_SCORE', |
| 1129 | ); |
| 1130 | } else { |
| 1131 | $result = array( |
| 1132 | 'response' => true, |
| 1133 | 'reason' => '', |
| 1134 | ); |
| 1135 | } |
| 1136 | } else { |
| 1137 | if ( |
| 1138 | ! $debug && |
| 1139 | ( |
| 1140 | in_array( 'missing-input-secret', $response['error-codes'] ) || |
| 1141 | in_array( 'invalid-input-secret', $response['error-codes'] ) |
| 1142 | ) |
| 1143 | ) { |
| 1144 | $result = array( |
| 1145 | 'response' => false, |
| 1146 | 'reason' => 'ERROR_WRONG_SECRET', |
| 1147 | ); |
| 1148 | } else { |
| 1149 | $result = array( |
| 1150 | 'response' => false, |
| 1151 | 'reason' => $debug ? $response['error-codes'] : 'VERIFICATION_FAILED', |
| 1152 | ); |
| 1153 | } |
| 1154 | } |
| 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | if ( ! $result['response'] ) { |
| 1159 | $result['errors'] = new WP_Error(); |
| 1160 | if ( ! $debug && ! in_array( $result['reason'], array( 'ERROR_WRONG_SECRET', 'ERROR_NO_KEYS' ) ) ) { |
| 1161 | $result['errors']->add( 'gglcptch_error', gglcptch_get_message( $result['reason'] ) ); |
| 1162 | } |
| 1163 | } |
| 1164 | $result = apply_filters( 'gglcptch_limit_attempts_check', $result, $form ); |
| 1165 | return $result; |
| 1166 | } |
| 1167 | } |
| 1168 | |
| 1169 | if ( ! function_exists( 'gglcptch_check_custom' ) ) { |
| 1170 | /** |
| 1171 | * Check google captcha for custom form |
| 1172 | * |
| 1173 | * @since 1.32 |
| 1174 | * @param bool $allow (Optional) initial value wheter the previous verification is passed. |
| 1175 | * @param string $return_format (Optional) The type of variable to be returned when recaptcha is failed. |
| 1176 | * @param string $form_slug (Optional) The slug of the form to check. |
| 1177 | * Default is empty string. When specified, the reCAPTCHA check may be skipped if the form is disabled on the plugin settings page. |
| 1178 | * @return mixed $allow True if ReCapthca is successfully completed, error message string, WP_Error object or false otherwise, depending on the $return_format value. |
| 1179 | */ |
| 1180 | function gglcptch_check_custom( $allow = true, $return_format = 'bool', $form_slug = '' ) { |
| 1181 | |
| 1182 | if ( true !== $allow ) { |
| 1183 | return $allow; |
| 1184 | } |
| 1185 | |
| 1186 | if ( gglcptch_is_recaptcha_required( $form_slug ) ) { |
| 1187 | $gglcptch_check = gglcptch_check(); |
| 1188 | |
| 1189 | if ( ! $gglcptch_check['response'] && 'ERROR_NO_KEYS' === $gglcptch_check['reason'] ) { |
| 1190 | return $allow; |
| 1191 | } |
| 1192 | |
| 1193 | $la_result = ( ! empty( $form_slug ) ) ? gglcptch_handle_by_limit_attempts( $gglcptch_check['response'], $form_slug ) : true; |
| 1194 | |
| 1195 | if ( ! $gglcptch_check['response'] || true !== $la_result ) { |
| 1196 | if ( ! in_array( $return_format, array( 'bool', 'string', 'wp_error' ) ) ) { |
| 1197 | $return_format = 'bool'; |
| 1198 | } |
| 1199 | |
| 1200 | switch ( $return_format ) { |
| 1201 | case 'string': |
| 1202 | $allow = ''; |
| 1203 | if ( true !== $la_result ) { |
| 1204 | if ( is_wp_error( $la_result ) ) { |
| 1205 | $allow .= $la_result->get_error_message(); |
| 1206 | } elseif ( is_string( $la_result ) ) { |
| 1207 | $allow .= $la_result; |
| 1208 | } |
| 1209 | } |
| 1210 | if ( ! $gglcptch_check['response'] ) { |
| 1211 | $allow .= ( ( '' !== $allow ) ? ' ' : '' ) . gglcptch_get_message(); |
| 1212 | } |
| 1213 | break; |
| 1214 | case 'wp_error': |
| 1215 | $allow = new WP_Error(); |
| 1216 | if ( true !== $la_result ) { |
| 1217 | if ( is_wp_error( $la_result ) ) { |
| 1218 | $allow = $la_result; |
| 1219 | } elseif ( is_string( $la_result ) ) { |
| 1220 | $allow->add( 'gglcptch_la_error', $la_result ); |
| 1221 | } |
| 1222 | } |
| 1223 | if ( ! $gglcptch_check['response'] ) { |
| 1224 | $error_message = sprintf( '<strong>%s</strong>: %s', __( 'Error', 'google-captcha' ), gglcptch_get_message() ); |
| 1225 | $allow->add( 'gglcptch_error', $error_message ); |
| 1226 | } |
| 1227 | break; |
| 1228 | case 'bool': |
| 1229 | default: |
| 1230 | $allow = false; |
| 1231 | break; |
| 1232 | } |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | return $allow; |
| 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | if ( ! function_exists( 'gglcptch_limit_attempts_check' ) ) { |
| 1241 | /** |
| 1242 | * Limit Attempts plugin check |
| 1243 | * |
| 1244 | * @param array $gglcptch_check reCaptcha response. |
| 1245 | * @param string $form Form slug. |
| 1246 | * |
| 1247 | * @return array $gglcptch_check |
| 1248 | */ |
| 1249 | function gglcptch_limit_attempts_check( $gglcptch_check, $form ) { |
| 1250 | |
| 1251 | $result = gglcptch_handle_by_limit_attempts( $gglcptch_check['response'], $form ); |
| 1252 | |
| 1253 | if ( true !== $result ) { |
| 1254 | $gglcptch_check['response'] = false; |
| 1255 | if ( 'login_form' !== $form ) { |
| 1256 | if ( is_wp_error( $result ) ) { |
| 1257 | $gglcptch_check['errors'] = $result; |
| 1258 | } elseif ( is_string( $result ) ) { |
| 1259 | $gglcptch_check['errors']->add( 'lmttmpts_error', $result ); |
| 1260 | } |
| 1261 | } |
| 1262 | return $gglcptch_check; |
| 1263 | } else { |
| 1264 | if ( 'contact_form' === $form ) { |
| 1265 | $gglcptch_check['response'] = true; |
| 1266 | } |
| 1267 | return $gglcptch_check; |
| 1268 | } |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | /** |
| 1273 | * |
| 1274 | * @since 1.32 |
| 1275 | */ |
| 1276 | if ( ! function_exists( 'gglcptch_handle_by_limit_attempts' ) ) { |
| 1277 | /** |
| 1278 | * Limit Attempts plugin |
| 1279 | * |
| 1280 | * @param object $check_result reCaptcha check result. |
| 1281 | * @param string $form_slug Form slug. |
| 1282 | * |
| 1283 | * @return object $check_result |
| 1284 | */ |
| 1285 | function gglcptch_handle_by_limit_attempts( $check_result, $form_slug = 'login_form' ) { |
| 1286 | global $gglcptch_forms; |
| 1287 | |
| 1288 | if ( ! has_filter( 'lmtttmpts_check_ip' ) ) { |
| 1289 | return $check_result; |
| 1290 | } |
| 1291 | |
| 1292 | if ( empty( $gglcptch_forms ) ) { |
| 1293 | $gglcptch_forms = gglcptch_get_forms(); |
| 1294 | } |
| 1295 | |
| 1296 | $la_form_slug = "{$form_slug}_captcha_check"; |
| 1297 | |
| 1298 | /* if reCAPTCHA answer is right */ |
| 1299 | if ( true === $check_result ) { |
| 1300 | /* check if user IP is blocked in the Limit Attempts plugin lists */ |
| 1301 | $check_result = apply_filters( 'lmtttmpts_check_ip', $check_result ); |
| 1302 | do_action( 'lmtttmpts_form_success', $la_form_slug, gglcptch_get_ip(), array( 'form_name' => $gglcptch_forms[ $form_slug ]['form_name'] ) ); |
| 1303 | } else { |
| 1304 | /* if reCAPTCHA answer is wrong */ |
| 1305 | $form_data = array( 'form_name' => $gglcptch_forms[ $form_slug ]['form_name'] ); |
| 1306 | |
| 1307 | if ( 'login_form_captcha_check' !== $form_slug ) { |
| 1308 | $la_error = apply_filters( 'lmtttmpts_form_fail', $la_form_slug, '', $form_data ); |
| 1309 | } |
| 1310 | |
| 1311 | if ( ! empty( $la_error ) && $la_form_slug !== $la_error ) { |
| 1312 | if ( is_wp_error( $check_result ) ) { |
| 1313 | $check_result->add( 'gglcptch_error_lmttmpts', $la_error ); |
| 1314 | } elseif ( is_string( $check_result ) ) { |
| 1315 | $check_result .= '<br />' . $la_error; |
| 1316 | } else { |
| 1317 | $check_result = $la_error; |
| 1318 | } |
| 1319 | } |
| 1320 | } |
| 1321 | |
| 1322 | return $check_result; |
| 1323 | } |
| 1324 | } |
| 1325 | |
| 1326 | if ( ! function_exists( 'gglcptch_get_ip' ) ) { |
| 1327 | /** |
| 1328 | * Get IP from server vars |
| 1329 | */ |
| 1330 | function gglcptch_get_ip() { |
| 1331 | $ip = ''; |
| 1332 | if ( isset( $_SERVER ) ) { |
| 1333 | $server_vars = array( 'HTTP_X_REAL_IP', 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'REMOTE_ADDR' ); |
| 1334 | foreach ( $server_vars as $var ) { |
| 1335 | if ( ! empty( $_SERVER[ $var ] ) ) { |
| 1336 | if ( filter_var( sanitize_text_field( wp_unslash( $_SERVER[ $var ] ) ), FILTER_VALIDATE_IP ) ) { |
| 1337 | $ip = sanitize_text_field( wp_unslash( $_SERVER[ $var ] ) ); |
| 1338 | if ( 0 < sprintf( '%u', ip2long( $ip ) ) ) { |
| 1339 | break; |
| 1340 | } |
| 1341 | } else { /* if proxy */ |
| 1342 | $ip_array = explode( ',', sanitize_text_field( wp_unslash( $_SERVER[ $var ] ) ) ); |
| 1343 | if ( is_array( $ip_array ) && ! empty( $ip_array ) && filter_var( $ip_array[0], FILTER_VALIDATE_IP ) ) { |
| 1344 | $ip = $ip_array[0]; |
| 1345 | if ( 0 < sprintf( '%u', ip2long( $ip ) ) ) { |
| 1346 | break; |
| 1347 | } |
| 1348 | } |
| 1349 | } |
| 1350 | } |
| 1351 | } |
| 1352 | } |
| 1353 | return $ip; |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | if ( ! function_exists( 'gglcptch_get_message' ) ) { |
| 1358 | /** |
| 1359 | * Retrieve the message that corresponds to its message code |
| 1360 | * |
| 1361 | * @since 1.29 |
| 1362 | * @param string $message_code used to switch the corresponding message. |
| 1363 | * @param boolean $echo 'false' is default. If 'false' - returns a message, if 'true' - first, echo a message and then return it. |
| 1364 | * @return string $message Returned message. |
| 1365 | */ |
| 1366 | function gglcptch_get_message( $message_code = 'incorrect', $echo = false ) { |
| 1367 | global $gglcptch_options; |
| 1368 | $message = ''; |
| 1369 | |
| 1370 | $messages = array( |
| 1371 | /* custom error */ |
| 1372 | 'RECAPTCHA_EMPTY_RESPONSE' => isset( $gglcptch_options['empty_error_message'] ) ? $gglcptch_options['empty_error_message'] : __( 'The reCaptcha verification failed. Please try again.', 'google-captcha' ), |
| 1373 | /* v2 error */ |
| 1374 | 'missing-input-secret' => __( 'Secret Key is missing.', 'google-captcha' ), |
| 1375 | 'invalid-input-secret' => sprintf( |
| 1376 | '<strong>%s</strong> <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s.', |
| 1377 | __( 'Secret Key is invalid.', 'google-captcha' ), |
| 1378 | __( 'Check your domain configurations', 'google-captcha' ), |
| 1379 | __( 'and enter it again', 'google-captcha' ) |
| 1380 | ), |
| 1381 | 'incorrect-captcha-sol' => __( 'User response is invalid', 'google-captcha' ), |
| 1382 | 'incorrect' => isset( $gglcptch_options['error_message'] ) ? $gglcptch_options['error_message'] : __( 'The reCaptcha verification failed. Please try again.', 'google-captcha' ), |
| 1383 | 'multiple_blocks' => __( 'More than one reCAPTCHA has been found in the current form. Please remove all unnecessary reCAPTCHA fields to make it work properly.', 'google-captcha' ), |
| 1384 | /* v3 error */ |
| 1385 | 'RECAPTCHA_SMALL_SCORE' => __( 'reCaptcha v3 test failed', 'google-captcha' ), |
| 1386 | ); |
| 1387 | |
| 1388 | if ( isset( $messages[ $message_code ] ) ) { |
| 1389 | $message = $messages[ $message_code ]; |
| 1390 | } else { |
| 1391 | $message = $messages['incorrect']; |
| 1392 | } |
| 1393 | |
| 1394 | if ( $echo ) { |
| 1395 | echo wp_kses_post( $message ); |
| 1396 | } |
| 1397 | |
| 1398 | return $message; |
| 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | if ( ! function_exists( 'gglcptch_is_woocommerce_page' ) ) { |
| 1403 | /** |
| 1404 | * Check WC page |
| 1405 | */ |
| 1406 | function gglcptch_is_woocommerce_page() { |
| 1407 | $traces = debug_backtrace(); |
| 1408 | |
| 1409 | foreach ( $traces as $trace ) { |
| 1410 | if ( isset( $trace['file'] ) && false !== strpos( $trace['file'], 'woocommerce' ) ) { |
| 1411 | return true; |
| 1412 | } |
| 1413 | } |
| 1414 | return false; |
| 1415 | } |
| 1416 | } |
| 1417 | |
| 1418 | if ( ! function_exists( 'gglcptch_test_keys' ) ) { |
| 1419 | /** |
| 1420 | * Test reCaptcha key |
| 1421 | */ |
| 1422 | function gglcptch_test_keys() { |
| 1423 | global $gglcptch_options; |
| 1424 | if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ), sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) ) ) { |
| 1425 | header( 'Content-Type: text/html' ); |
| 1426 | register_gglcptch_settings(); |
| 1427 | ?> |
| 1428 | <p> |
| 1429 | <?php |
| 1430 | if ( 'invisible' === $gglcptch_options['recaptcha_version'] || 'v3' === $gglcptch_options['recaptcha_version'] ) { |
| 1431 | esc_html_e( 'Please submit "Test verification"', 'google-captcha' ); |
| 1432 | } else { |
| 1433 | esc_html_e( 'Please complete the captcha and submit "Test verification"', 'google-captcha' ); |
| 1434 | } |
| 1435 | ?> |
| 1436 | </p> |
| 1437 | <?php echo gglcptch_display(); ?> |
| 1438 | <p> |
| 1439 | <input type="hidden" name="gglcptch_test_keys_verification-nonce" value="<?php echo esc_attr( wp_create_nonce( 'gglcptch_test_keys_verification' ) ); ?>" /> |
| 1440 | <button id="gglcptch_test_keys_verification" name="action" class="button-primary cptch_loading" value="gglcptch_test_keys_verification" disabled="disabled"><?php esc_html_e( 'Test verification', 'google-captcha' ); ?></button> |
| 1441 | </p> |
| 1442 | <?php |
| 1443 | } |
| 1444 | die(); |
| 1445 | } |
| 1446 | } |
| 1447 | |
| 1448 | if ( ! function_exists( 'gglcptch_test_keys_verification' ) ) { |
| 1449 | /** |
| 1450 | * Test reCaptcha verification |
| 1451 | */ |
| 1452 | function gglcptch_test_keys_verification() { |
| 1453 | if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ), sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) ) ) { |
| 1454 | $result = gglcptch_check( 'gglcptch_test', true ); |
| 1455 | |
| 1456 | if ( ! $result['response'] ) { |
| 1457 | if ( isset( $result['reason'] ) ) { |
| 1458 | foreach ( (array) $result['reason'] as $error ) { |
| 1459 | ?> |
| 1460 | <div class="error gglcptch-test-results"><p> |
| 1461 | <?php gglcptch_get_message( $error, true ); ?> |
| 1462 | </p></div> |
| 1463 | <?php |
| 1464 | } |
| 1465 | } |
| 1466 | } else { |
| 1467 | ?> |
| 1468 | <div class="updated gglcptch-test-results"><p><?php esc_html_e( 'The verification is successfully completed.', 'google-captcha' ); ?></p></div> |
| 1469 | <?php |
| 1470 | $gglcptch_options = get_option( 'gglcptch_options' ); |
| 1471 | $gglcptch_options['keys_verified'] = true; |
| 1472 | unset( $gglcptch_options['need_keys_verified_check'] ); |
| 1473 | update_option( 'gglcptch_options', $gglcptch_options ); |
| 1474 | } |
| 1475 | } |
| 1476 | die(); |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | if ( ! function_exists( 'gglcptch_action_links' ) ) { |
| 1481 | /** |
| 1482 | * Add action links |
| 1483 | * |
| 1484 | * @param array $links Action link array. |
| 1485 | * @param file $file Plugin file. |
| 1486 | * @return array $links Returned link array. |
| 1487 | */ |
| 1488 | function gglcptch_action_links( $links, $file ) { |
| 1489 | if ( ! is_network_admin() ) { |
| 1490 | static $this_plugin; |
| 1491 | if ( ! $this_plugin ) { |
| 1492 | $this_plugin = plugin_basename( __FILE__ ); |
| 1493 | } |
| 1494 | |
| 1495 | if ( $file === $this_plugin ) { |
| 1496 | $settings_link = '<a href="admin.php?page=google-captcha.php">' . __( 'Settings', 'google-captcha' ) . '</a>'; |
| 1497 | array_unshift( $links, $settings_link ); |
| 1498 | } |
| 1499 | } |
| 1500 | return $links; |
| 1501 | } |
| 1502 | } |
| 1503 | |
| 1504 | if ( ! function_exists( 'gglcptch_links' ) ) { |
| 1505 | /** |
| 1506 | * Add Settings and Support links |
| 1507 | * |
| 1508 | * @param array $links Action link array. |
| 1509 | * @param file $file Plugin file. |
| 1510 | * @return array $links Returned link array. |
| 1511 | */ |
| 1512 | function gglcptch_links( $links, $file ) { |
| 1513 | $base = plugin_basename( __FILE__ ); |
| 1514 | if ( $file === $base ) { |
| 1515 | if ( ! is_network_admin() ) { |
| 1516 | $links[] = '<a href="admin.php?page=google-captcha.php">' . __( 'Settings', 'google-captcha' ) . '</a>'; |
| 1517 | } |
| 1518 | $links[] = '<a href="https://support.bestwebsoft.com/hc/en-us/sections/200538719" target="_blank">' . __( 'FAQ', 'google-captcha' ) . '</a>'; |
| 1519 | $links[] = '<a href="https://support.bestwebsoft.com">' . __( 'Support', 'google-captcha' ) . '</a>'; |
| 1520 | } |
| 1521 | return $links; |
| 1522 | } |
| 1523 | } |
| 1524 | |
| 1525 | if ( ! function_exists( 'gglcptch_plugin_banner' ) ) { |
| 1526 | /** |
| 1527 | * Dispaly plugins banner |
| 1528 | */ |
| 1529 | function gglcptch_plugin_banner() { |
| 1530 | global $hook_suffix, $gglcptch_plugin_info, $gglcptch_options; |
| 1531 | if ( 'plugins.php' === $hook_suffix ) { |
| 1532 | if ( empty( $gglcptch_options ) ) { |
| 1533 | register_gglcptch_settings(); |
| 1534 | } |
| 1535 | bws_plugin_banner_to_settings( $gglcptch_plugin_info, 'gglcptch_options', 'google-captcha', 'admin.php?page=google-captcha.php' ); |
| 1536 | if ( function_exists( 'bws_plugin_banner_to_promo' ) ) { |
| 1537 | bws_plugin_banner_to_promo( $gglcptch_plugin_info, 'gglcptch_options', 'google-captcha', 'admin.php?page=google-captcha.php', array( __( 'Double-Check Your reCAPTCHA Keys', 'bestwebsoft' ), __( "Ensure your keys are correctly configured for maximum protection. Click “Test Keys” button. Check your settings now!", 'bestwebsoft' ) ) ); |
| 1538 | } |
| 1539 | } |
| 1540 | |
| 1541 | if ( isset( $_GET['page'] ) && 'google-captcha.php' === sanitize_text_field( wp_unslash( $_GET['page'] ) ) ) { |
| 1542 | bws_plugin_suggest_feature_banner( $gglcptch_plugin_info, 'gglcptch_options', 'google-captcha' ); |
| 1543 | } |
| 1544 | } |
| 1545 | } |
| 1546 | |
| 1547 | if ( ! function_exists( 'gglcptch_add_tabs' ) ) { |
| 1548 | /** |
| 1549 | * Add help tab |
| 1550 | */ |
| 1551 | function gglcptch_add_tabs() { |
| 1552 | $screen = get_current_screen(); |
| 1553 | $args = array( |
| 1554 | 'id' => 'gglcptch', |
| 1555 | 'section' => '200538719', |
| 1556 | ); |
| 1557 | bws_help_tab( $screen, $args ); |
| 1558 | } |
| 1559 | } |
| 1560 | |
| 1561 | if ( ! function_exists( 'gglcptch_delete_options' ) ) { |
| 1562 | /** |
| 1563 | * Delete option |
| 1564 | */ |
| 1565 | function gglcptch_delete_options() { |
| 1566 | if ( ! function_exists( 'get_plugins' ) ) { |
| 1567 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 1568 | } |
| 1569 | $all_plugins = get_plugins(); |
| 1570 | |
| 1571 | if ( ! array_key_exists( 'google-captcha-pro/google-captcha-pro.php', $all_plugins ) ) { |
| 1572 | global $wpdb; |
| 1573 | if ( function_exists( 'is_multisite' ) && is_multisite() ) { |
| 1574 | $old_blog = $wpdb->blogid; |
| 1575 | /* Get all blog ids */ |
| 1576 | $blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" ); |
| 1577 | foreach ( $blogids as $blog_id ) { |
| 1578 | switch_to_blog( $blog_id ); |
| 1579 | $wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}gglcptch_whitelist`;" ); |
| 1580 | delete_option( 'gglcptch_options' ); |
| 1581 | } |
| 1582 | switch_to_blog( $old_blog ); |
| 1583 | delete_site_option( 'gglcptch_options' ); |
| 1584 | } else { |
| 1585 | $wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}gglcptch_whitelist`;" ); |
| 1586 | delete_option( 'gglcptch_options' ); |
| 1587 | } |
| 1588 | } |
| 1589 | |
| 1590 | require_once dirname( __FILE__ ) . '/bws_menu/bws_include.php'; |
| 1591 | bws_include_init( plugin_basename( __FILE__ ) ); |
| 1592 | bws_delete_plugin( plugin_basename( __FILE__ ) ); |
| 1593 | } |
| 1594 | } |
| 1595 | |
| 1596 | register_activation_hook( __FILE__, 'gglcptch_plugin_activate' ); |
| 1597 | |
| 1598 | add_action( 'admin_menu', 'gglcptch_admin_menu' ); |
| 1599 | |
| 1600 | add_action( 'init', 'gglcptch_init', 10 ); |
| 1601 | add_action( 'admin_init', 'gglcptch_admin_init' ); |
| 1602 | |
| 1603 | add_action( 'plugins_loaded', 'gglcptch_plugins_loaded' ); |
| 1604 | |
| 1605 | add_action( 'admin_enqueue_scripts', 'gglcptch_add_admin_script_styles' ); |
| 1606 | add_action( 'login_enqueue_scripts', 'gglcptch_add_login_styles' ); |
| 1607 | add_filter( 'script_loader_tag', 'gglcptch_add_async_attribute', 10, 2 ); |
| 1608 | add_action( 'admin_footer', 'gglcptch_admin_footer' ); |
| 1609 | add_action( 'wp_enqueue_scripts', 'gglcptch_enqueue_scripts' ); |
| 1610 | add_filter( 'pgntn_callback', 'gglcptch_pagination_callback' ); |
| 1611 | |
| 1612 | add_filter( 'lmtttmpts_plugin_forms', 'gglcptch_add_lmtttmpts_forms', 10, 1 ); |
| 1613 | |
| 1614 | add_shortcode( 'bws_google_captcha', 'gglcptch_display' ); |
| 1615 | add_filter( 'widget_text', 'do_shortcode' ); |
| 1616 | |
| 1617 | add_filter( 'gglcptch_display_recaptcha', 'gglcptch_display_custom', 10, 2 ); |
| 1618 | add_filter( 'gglcptch_verify_recaptcha', 'gglcptch_check_custom', 10, 3 ); |
| 1619 | |
| 1620 | add_filter( 'gglcptch_limit_attempts_check', 'gglcptch_limit_attempts_check', 10, 2 ); |
| 1621 | |
| 1622 | add_filter( 'plugin_action_links', 'gglcptch_action_links', 10, 2 ); |
| 1623 | add_filter( 'plugin_row_meta', 'gglcptch_links', 10, 2 ); |
| 1624 | |
| 1625 | add_action( 'admin_notices', 'gglcptch_plugin_banner' ); |
| 1626 | |
| 1627 | add_action( 'wp_ajax_gglcptch-test-keys', 'gglcptch_test_keys' ); |
| 1628 | add_action( 'wp_ajax_gglcptch_test_keys_verification', 'gglcptch_test_keys_verification' ); |
| 1629 |