google-captcha
Last commit date
bws_menu
9 years ago
css
9 years ago
images
9 years ago
includes
9 years ago
js
9 years ago
languages
9 years ago
lib
9 years ago
google-captcha.php
9 years ago
readme.txt
9 years ago
screenshot-1.png
9 years ago
screenshot-2.png
9 years ago
screenshot-3.png
9 years ago
screenshot-4.png
9 years ago
screenshot-5.png
9 years ago
screenshot-6.png
9 years ago
screenshot-7.png
9 years ago
screenshot-8.png
9 years ago
screenshot-9.png
9 years ago
google-captcha.php
1374 lines
| 1 | <?php |
| 2 | /* |
| 3 | Plugin Name: Google Captcha (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.28 |
| 10 | Author URI: https://bestwebsoft.com/ |
| 11 | License: GPLv3 or later |
| 12 | */ |
| 13 | |
| 14 | /* © Copyright 2017 BestWebSoft ( https://support.bestwebsoft.com ) |
| 15 | |
| 16 | This program is free software; you can redistribute it and/or modify |
| 17 | it under the terms of the GNU General Public License, version 2, as |
| 18 | published by the Free Software Foundation. |
| 19 | |
| 20 | This program is distributed in the hope that it will be useful, |
| 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | GNU General Public License for more details. |
| 24 | |
| 25 | You should have received a copy of the GNU General Public License |
| 26 | along with this program; if not, write to the Free Software |
| 27 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 28 | */ |
| 29 | |
| 30 | /* Add menu page */ |
| 31 | if ( ! function_exists( 'gglcptch_admin_menu' ) ) { |
| 32 | function gglcptch_admin_menu() { |
| 33 | bws_general_menu(); |
| 34 | $gglcptch_settings = add_submenu_page( 'bws_panel', __( 'Google Captcha Settings', 'google-captcha' ), 'Google Captcha', 'manage_options', 'google-captcha.php', 'gglcptch_add_settings_page' ); |
| 35 | add_action( 'load-' . $gglcptch_settings, 'gglcptch_add_tabs' ); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | if ( ! function_exists( 'gglcptch_plugins_loaded' ) ) { |
| 40 | function gglcptch_plugins_loaded() { |
| 41 | /* Internationalization, first(!) */ |
| 42 | load_plugin_textdomain( 'google-captcha', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | if ( ! function_exists( 'gglcptch_init' ) ) { |
| 47 | function gglcptch_init() { |
| 48 | global $gglcptch_plugin_info, $gglcptch_options, $gglcptch_ip_in_whitelist;; |
| 49 | |
| 50 | require_once( dirname( __FILE__ ) . '/bws_menu/bws_include.php' ); |
| 51 | bws_include_init( plugin_basename( __FILE__ ) ); |
| 52 | |
| 53 | if ( empty( $gglcptch_plugin_info ) ) { |
| 54 | if ( ! function_exists( 'get_plugin_data' ) ) |
| 55 | require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 56 | $gglcptch_plugin_info = get_plugin_data( __FILE__ ); |
| 57 | } |
| 58 | |
| 59 | /* Function check if plugin is compatible with current WP version */ |
| 60 | bws_wp_min_version_check( plugin_basename( __FILE__ ), $gglcptch_plugin_info, '3.8' ); |
| 61 | |
| 62 | $is_admin = is_admin() && ! defined( 'DOING_AJAX' ); |
| 63 | /* Call register settings function */ |
| 64 | if ( ! $is_admin || ( isset( $_GET['page'] ) && 'google-captcha.php' == $_GET['page'] ) ) |
| 65 | register_gglcptch_settings(); |
| 66 | |
| 67 | if ( empty( $gglcptch_ip_in_whitelist ) ) |
| 68 | $gglcptch_ip_in_whitelist = gglcptch_whitelisted_ip(); |
| 69 | |
| 70 | /* Add hooks */ |
| 71 | if ( ! $is_admin ) { |
| 72 | /* Add hooks */ |
| 73 | if ( '1' == $gglcptch_options['login_form'] || '1' == $gglcptch_options['reset_pwd_form'] || '1' == $gglcptch_options['registration_form'] ) { |
| 74 | add_action( 'login_enqueue_scripts', 'gglcptch_add_styles' ); |
| 75 | |
| 76 | if ( '1' == $gglcptch_options['login_form'] ) { |
| 77 | add_action( 'login_form', 'gglcptch_login_display' ); |
| 78 | if ( ! $gglcptch_ip_in_whitelist ) |
| 79 | add_action( 'authenticate', 'gglcptch_login_check', 21, 1 ); |
| 80 | } |
| 81 | |
| 82 | if ( '1' == $gglcptch_options['reset_pwd_form'] ) { |
| 83 | add_action( 'lostpassword_form', 'gglcptch_login_display' ); |
| 84 | if ( ! $gglcptch_ip_in_whitelist ) |
| 85 | add_action( 'allow_password_reset', 'gglcptch_lostpassword_check' ); |
| 86 | } |
| 87 | |
| 88 | if ( '1' == $gglcptch_options['registration_form'] ) { |
| 89 | if ( ! is_multisite() ) { |
| 90 | add_action( 'register_form', 'gglcptch_login_display', 99 ); |
| 91 | if ( ! $gglcptch_ip_in_whitelist ) |
| 92 | add_action( 'registration_errors', 'gglcptch_lostpassword_check' ); |
| 93 | } else { |
| 94 | add_action( 'signup_extra_fields', 'gglcptch_signup_display' ); |
| 95 | add_action( 'signup_blogform', 'gglcptch_signup_display' ); |
| 96 | if ( ! $gglcptch_ip_in_whitelist ) |
| 97 | add_filter( 'wpmu_validate_user_signup', 'gglcptch_signup_check' ); |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | if ( '1' == $gglcptch_options['comments_form'] ) { |
| 103 | add_action( 'comment_form_after_fields', 'gglcptch_commentform_display' ); |
| 104 | add_action( 'comment_form_logged_in_after', 'gglcptch_commentform_display' ); |
| 105 | if ( ! $gglcptch_ip_in_whitelist ) |
| 106 | add_action( 'pre_comment_on_post', 'gglcptch_commentform_check' ); |
| 107 | } |
| 108 | |
| 109 | if ( '1' == $gglcptch_options['contact_form'] ) { |
| 110 | add_filter( 'cntctfrm_display_captcha', 'gglcptch_cf_display', 10, 2 ); |
| 111 | if ( ! $gglcptch_ip_in_whitelist ) |
| 112 | add_filter( 'cntctfrm_check_form', 'gglcptch_recaptcha_check' ); |
| 113 | /** |
| 114 | * this filters are necessary for compatibility |
| 115 | * with old Contact Form Pro by BestWebsoft versions |
| 116 | * @deprecated since 1.0.4 |
| 117 | * @todo remove after 25.02.2017 |
| 118 | */ |
| 119 | add_filter( 'cntctfrmpr_display_captcha', 'gglcptch_cf_display', 10, 2 ); |
| 120 | if ( ! $gglcptch_ip_in_whitelist ) |
| 121 | add_filter( 'cntctfrmpr_check_form', 'gglcptch_recaptcha_check' ); |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Activation plugin function |
| 129 | */ |
| 130 | if ( ! function_exists( 'gglcptch_plugin_activate' ) ) { |
| 131 | function gglcptch_plugin_activate( $networkwide ) { |
| 132 | global $wpdb; |
| 133 | /* Activation function for network, check if it is a network activation - if so, run the activation function for each blog id */ |
| 134 | if ( is_multisite() ) { |
| 135 | switch_to_blog( 1 ); |
| 136 | register_uninstall_hook( __FILE__, 'gglcptch_delete_options' ); |
| 137 | restore_current_blog(); |
| 138 | } else { |
| 139 | register_uninstall_hook( __FILE__, 'gglcptch_delete_options' ); |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | if ( ! function_exists( 'gglcptch_admin_init' ) ) { |
| 145 | function gglcptch_admin_init() { |
| 146 | global $bws_plugin_info, $gglcptch_plugin_info, $bws_shortcode_list; |
| 147 | |
| 148 | if ( empty( $bws_plugin_info ) ) |
| 149 | $bws_plugin_info = array( 'id' => '109', 'version' => $gglcptch_plugin_info["Version"] ); |
| 150 | |
| 151 | /* add google captcha to global $bws_shortcode_list */ |
| 152 | $bws_shortcode_list['gglcptch'] = array( 'name' => 'Google Captcha (reCAPTCHA)' ); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | /* Add google captcha styles */ |
| 157 | if ( ! function_exists( 'gglcptch_add_admin_script_styles' ) ) { |
| 158 | function gglcptch_add_admin_script_styles() { |
| 159 | if ( isset( $_REQUEST['page'] ) && 'google-captcha.php' == $_REQUEST['page'] ) { |
| 160 | wp_enqueue_style( 'gglcptch_stylesheet', plugins_url( 'css/style.css', __FILE__ ) ); |
| 161 | wp_enqueue_script( 'gglcptch_admin_script', plugins_url( 'js/admin_script.js', __FILE__ ), array( 'jquery' ) ); |
| 162 | |
| 163 | if ( isset( $_GET['action'] ) && 'custom_code' == $_GET['action'] ) |
| 164 | bws_plugins_include_codemirror(); |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | /* Add google captcha admin styles for test key */ |
| 170 | if ( ! function_exists( 'gglcptch_admin_footer' ) ) { |
| 171 | function gglcptch_admin_footer() { |
| 172 | if ( isset( $_REQUEST['page'] ) && 'google-captcha.php' == $_REQUEST['page'] ) { |
| 173 | /* for gglcptch test key */ |
| 174 | global $gglcptch_options; |
| 175 | if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) { |
| 176 | $api_url = "https://www.google.com/recaptcha/api.js"; |
| 177 | } else { |
| 178 | $api_url = "https://www.google.com/recaptcha/api/js/recaptcha_ajax.js"; |
| 179 | } |
| 180 | wp_register_script( 'gglcptch_api', $api_url, false, false, true ); |
| 181 | gglcptch_add_scripts(); |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Remove dublicate scripts |
| 188 | */ |
| 189 | if ( ! function_exists( 'gglcptch_remove_dublicate_scripts' ) ) { |
| 190 | function gglcptch_remove_dublicate_scripts() { |
| 191 | global $wp_scripts; |
| 192 | |
| 193 | if ( ! is_object( $wp_scripts ) || empty( $wp_scripts ) ) |
| 194 | return false; |
| 195 | |
| 196 | foreach ( $wp_scripts->registered as $script_name => $args ) { |
| 197 | if ( preg_match( "|google\.com/recaptcha/api\.js|", $args->src ) && 'gglcptch_api' != $script_name ) |
| 198 | /* remove a previously enqueued script */ |
| 199 | wp_dequeue_script( $script_name ); |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Add google captcha styles |
| 206 | */ |
| 207 | if ( ! function_exists( 'gglcptch_add_styles' ) ) { |
| 208 | function gglcptch_add_styles() { |
| 209 | global $gglcptch_plugin_info, $gglcptch_options; |
| 210 | wp_enqueue_style( 'gglcptch', plugins_url( 'css/gglcptch.css', __FILE__ ), false, $gglcptch_plugin_info["Version"] ); |
| 211 | |
| 212 | if ( defined( 'BWS_ENQUEUE_ALL_SCRIPTS' ) && BWS_ENQUEUE_ALL_SCRIPTS ) { |
| 213 | if ( ! wp_script_is( 'gglcptch_api', 'registered' ) ) { |
| 214 | if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) { |
| 215 | $api_url = "https://www.google.com/recaptcha/api.js"; |
| 216 | } else { |
| 217 | $api_url = "https://www.google.com/recaptcha/api/js/recaptcha_ajax.js"; |
| 218 | } |
| 219 | wp_register_script( 'gglcptch_api', $api_url, false, false, true ); |
| 220 | add_action( 'wp_footer', 'gglcptch_add_scripts' ); |
| 221 | if ( |
| 222 | '1' == $gglcptch_options['login_form'] || |
| 223 | '1' == $gglcptch_options['reset_pwd_form'] || |
| 224 | '1' == $gglcptch_options['registration_form'] |
| 225 | ) |
| 226 | add_action( 'login_footer', 'gglcptch_add_scripts' ); |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Add google captcha js scripts |
| 234 | */ |
| 235 | if ( ! function_exists( 'gglcptch_add_scripts' ) ) { |
| 236 | function gglcptch_add_scripts() { |
| 237 | global $gglcptch_options; |
| 238 | |
| 239 | if ( empty( $gglcptch_options ) ) |
| 240 | register_gglcptch_settings(); |
| 241 | |
| 242 | if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) |
| 243 | gglcptch_remove_dublicate_scripts(); |
| 244 | |
| 245 | wp_enqueue_script( 'gglcptch_script', plugins_url( 'js/script.js', __FILE__ ), array( 'jquery', 'gglcptch_api' ), false, true ); |
| 246 | |
| 247 | $version = $gglcptch_options['recaptcha_version'] == 'v2' ? '_v2' : ''; |
| 248 | |
| 249 | wp_localize_script( 'gglcptch_script', 'gglcptch', array( |
| 250 | 'options' => array( |
| 251 | 'version' => $gglcptch_options['recaptcha_version'], |
| 252 | 'sitekey' => $gglcptch_options['public_key'], |
| 253 | 'theme' => $gglcptch_options[ 'theme' . $version ], |
| 254 | 'error' => "<strong>" . __( 'Warning', 'google-captcha' ) . ":</strong> " . __( 'It has been found more than one reCAPTCHA in current form. In this case reCAPTCHA will not work properly. Please remove all unnecessary reCAPTCHA blocks.', 'google-captcha' ) |
| 255 | ), |
| 256 | 'vars' => array( |
| 257 | 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 258 | 'error_msg' => __( 'Error: You have entered an incorrect reCAPTCHA value', 'google-captcha' ), |
| 259 | 'nonce' => wp_create_nonce( 'gglcptch_recaptcha_nonce' ), |
| 260 | 'visibility' => ( 'login_footer' == current_filter() ) ? true : false |
| 261 | ) |
| 262 | ) ); |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | if ( ! function_exists( 'gglcptch_pagination_callback' ) ) { |
| 267 | function gglcptch_pagination_callback( $content ) { |
| 268 | $content .= "if ( typeof Recaptcha != 'undefined' || typeof grecaptcha != 'undefined' ) { gglcptch.prepare(); }"; |
| 269 | return $content; |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Add the "async" attribute to our registered script. |
| 275 | */ |
| 276 | if ( ! function_exists( 'gglcptch_add_async_attribute' ) ) { |
| 277 | function gglcptch_add_async_attribute( $tag, $handle ) { |
| 278 | if ( 'gglcptch_api' == $handle ) |
| 279 | $tag = str_replace( ' src', ' data-cfasync="false" async="async" defer="defer" src', $tag ); |
| 280 | return $tag; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | if ( ! function_exists( 'gglcptch_create_table' ) ) { |
| 285 | function gglcptch_create_table() { |
| 286 | global $wpdb; |
| 287 | require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 288 | $whitelist_exist = $wpdb->query( "SHOW TABLES LIKE '{$wpdb->prefix}gglcptch_whitelist';" ); |
| 289 | if ( ! $whitelist_exist ) { |
| 290 | $sql = "CREATE TABLE `{$wpdb->prefix}gglcptch_whitelist` ( |
| 291 | `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, |
| 292 | `ip` CHAR(31) NOT NULL, |
| 293 | `ip_from_int` BIGINT, |
| 294 | `ip_to_int` BIGINT, |
| 295 | `add_time` DATETIME, |
| 296 | PRIMARY KEY (`id`) |
| 297 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; |
| 298 | dbDelta( $sql ); |
| 299 | |
| 300 | /* add unique key */ |
| 301 | if ( 0 == $wpdb->query( "SHOW KEYS FROM `{$wpdb->prefix}gglcptch_whitelist` WHERE Key_name='ip'" ) ) |
| 302 | $wpdb->query( "ALTER TABLE `{$wpdb->prefix}gglcptch_whitelist` ADD UNIQUE(`ip`);" ); |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | /* Google catpcha settings */ |
| 308 | if ( ! function_exists( 'register_gglcptch_settings' ) ) { |
| 309 | function register_gglcptch_settings() { |
| 310 | global $gglcptch_options, $bws_plugin_info, $gglcptch_plugin_info; |
| 311 | |
| 312 | $plugin_db_version = '0.1'; |
| 313 | |
| 314 | /* Install the option defaults */ |
| 315 | if ( ! get_option( 'gglcptch_options' ) ) |
| 316 | add_option( 'gglcptch_options', gglcptch_get_default_options() ); |
| 317 | /* Get options from the database */ |
| 318 | $gglcptch_options = get_option( 'gglcptch_options' ); |
| 319 | |
| 320 | /* Array merge incase this version has added new options */ |
| 321 | if ( ! isset( $gglcptch_options['plugin_option_version'] ) || $gglcptch_options['plugin_option_version'] != $gglcptch_plugin_info["Version"] ) { |
| 322 | $gglcptch_options = array_merge( gglcptch_get_default_options(), $gglcptch_options ); |
| 323 | $gglcptch_options['plugin_option_version'] = $gglcptch_plugin_info["Version"]; |
| 324 | /* show pro features */ |
| 325 | $gglcptch_options['hide_premium_options'] = array(); |
| 326 | |
| 327 | if ( is_multisite() ) { |
| 328 | switch_to_blog( 1 ); |
| 329 | register_uninstall_hook( __FILE__, 'gglcptch_delete_options' ); |
| 330 | restore_current_blog(); |
| 331 | } else { |
| 332 | register_uninstall_hook( __FILE__, 'gglcptch_delete_options' ); |
| 333 | } |
| 334 | update_option( 'gglcptch_options', $gglcptch_options ); |
| 335 | } |
| 336 | /* Update tables when update plugin and tables changes*/ |
| 337 | if ( |
| 338 | ! isset( $gglcptch_options['plugin_db_version'] ) || |
| 339 | ( isset( $gglcptch_options['plugin_db_version'] ) && $gglcptch_options['plugin_db_version'] != $plugin_db_version ) |
| 340 | ) { |
| 341 | if ( ! isset( $gglcptch_options['plugin_db_version'] ) ) { |
| 342 | gglcptch_create_table(); |
| 343 | } |
| 344 | $gglcptch_options['plugin_db_version'] = $plugin_db_version; |
| 345 | update_option( 'gglcptch_options', $gglcptch_options ); |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | if ( ! function_exists( 'gglcptch_get_default_options' ) ) { |
| 351 | function gglcptch_get_default_options() { |
| 352 | global $gglcptch_plugin_info; |
| 353 | |
| 354 | $default_options = array( |
| 355 | 'whitelist_message' => __( 'You are in the whitelist', 'google-captcha' ), |
| 356 | 'public_key' => '', |
| 357 | 'private_key' => '', |
| 358 | 'login_form' => '1', |
| 359 | 'registration_form' => '1', |
| 360 | 'reset_pwd_form' => '1', |
| 361 | 'comments_form' => '1', |
| 362 | 'contact_form' => '0', |
| 363 | 'theme' => 'red', |
| 364 | 'theme_v2' => 'light', |
| 365 | 'recaptcha_version' => 'v2', |
| 366 | 'plugin_option_version' => $gglcptch_plugin_info["Version"], |
| 367 | 'first_install' => strtotime( "now" ), |
| 368 | 'display_settings_notice' => 1, |
| 369 | 'suggest_feature_banner' => 1, |
| 370 | ); |
| 371 | |
| 372 | if ( function_exists( 'get_editable_roles' ) ) { |
| 373 | foreach ( get_editable_roles() as $role => $fields ) { |
| 374 | $default_options[ $role ] = '0'; |
| 375 | } |
| 376 | } |
| 377 | return $default_options; |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | if ( ! function_exists( 'gglcptch_plugin_status' ) ) { |
| 382 | function gglcptch_plugin_status( $plugins, $all_plugins, $is_network ) { |
| 383 | $result = array( |
| 384 | 'status' => '', |
| 385 | 'plugin' => '', |
| 386 | 'plugin_info' => array(), |
| 387 | ); |
| 388 | foreach ( (array)$plugins as $plugin ) { |
| 389 | if ( array_key_exists( $plugin, $all_plugins ) ) { |
| 390 | if ( |
| 391 | ( $is_network && is_plugin_active_for_network( $plugin ) ) || |
| 392 | ( ! $is_network && is_plugin_active( $plugin ) ) |
| 393 | ) { |
| 394 | $result['status'] = 'actived'; |
| 395 | $result['plugin'] = $plugin; |
| 396 | $result['plugin_info'] = $all_plugins[$plugin]; |
| 397 | break; |
| 398 | } else { |
| 399 | $result['status'] = 'deactivated'; |
| 400 | $result['plugin'] = $plugin; |
| 401 | $result['plugin_info'] = $all_plugins[$plugin]; |
| 402 | } |
| 403 | |
| 404 | } |
| 405 | } |
| 406 | if ( empty( $result['status'] ) ) |
| 407 | $result['status'] = 'not_installed'; |
| 408 | return $result; |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | if ( ! function_exists( 'gglcptch_whitelisted_ip' ) ) { |
| 413 | function gglcptch_whitelisted_ip() { |
| 414 | global $wpdb, $gglcptch_options; |
| 415 | $checked = false; |
| 416 | if ( empty( $gglcptch_options ) ) |
| 417 | $gglcptch_options = get_option( 'gglcptch_options' ); |
| 418 | $whitelist_exist = $wpdb->query( "SHOW TABLES LIKE '{$wpdb->prefix}gglcptch_whitelist'" ); |
| 419 | if ( 1 === $whitelist_exist ) { |
| 420 | $ip = ''; |
| 421 | if ( isset( $_SERVER ) ) { |
| 422 | $server_vars = array( 'HTTP_X_REAL_IP', 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'REMOTE_ADDR' ); |
| 423 | foreach( $server_vars as $var ) { |
| 424 | if ( isset( $_SERVER[ $var ] ) && ! empty( $_SERVER[ $var ] ) ) { |
| 425 | if ( filter_var( $_SERVER[ $var ], FILTER_VALIDATE_IP ) ) { |
| 426 | $ip = $_SERVER[ $var ]; |
| 427 | break; |
| 428 | } else { /* if proxy */ |
| 429 | $ip_array = explode( ',', $_SERVER[ $var ] ); |
| 430 | if ( is_array( $ip_array ) && ! empty( $ip_array ) && filter_var( $ip_array[0], FILTER_VALIDATE_IP ) ) { |
| 431 | $ip = $ip_array[0]; |
| 432 | break; |
| 433 | } |
| 434 | } |
| 435 | } |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | if ( ! empty( $ip ) ) { |
| 440 | $ip_int = sprintf( '%u', ip2long( $ip ) ); |
| 441 | $result = $wpdb->get_var( |
| 442 | "SELECT `id` |
| 443 | FROM `{$wpdb->prefix}gglcptch_whitelist` |
| 444 | WHERE ( `ip_from_int` <= {$ip_int} AND `ip_to_int` >= {$ip_int} ) OR `ip` LIKE '{$ip}' LIMIT 1;" |
| 445 | ); |
| 446 | $checked = is_null( $result ) || ! $result ? false : true; |
| 447 | } else { |
| 448 | $checked = false; |
| 449 | } |
| 450 | } |
| 451 | return $checked; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | /* Display settings page */ |
| 456 | if ( ! function_exists( 'gglcptch_add_settings_page' ) ) { |
| 457 | function gglcptch_add_settings_page() { |
| 458 | global $gglcptch_options, $gglcptch_plugin_info, $wp_version; |
| 459 | require_once( dirname( __FILE__ ) . '/includes/pro_banners.php' ); |
| 460 | |
| 461 | $plugin_basename = plugin_basename( __FILE__ ); |
| 462 | $message = $error = ''; |
| 463 | |
| 464 | $all_plugins = get_plugins(); |
| 465 | $is_network = is_multisite() && is_network_admin(); |
| 466 | $is_main_site = is_main_site( get_current_blog_id() ); |
| 467 | $admin_url = $is_network ? network_admin_url( '/' ) : admin_url( '/' ); |
| 468 | $bws_contact_form = gglcptch_plugin_status( array( 'contact-form-plugin/contact_form.php', 'contact-form-pro/contact_form_pro.php' ), $all_plugins, $is_network ); |
| 469 | |
| 470 | if ( isset( $_POST['bws_hide_premium_options'] ) && check_admin_referer( $plugin_basename, 'gglcptch_nonce_name' ) ) { |
| 471 | $result = bws_hide_premium_options( $gglcptch_options ); |
| 472 | $gglcptch_options = $result['options']; |
| 473 | update_option( 'gglcptch_options', $gglcptch_options ); |
| 474 | } |
| 475 | if ( ! isset( $_GET['action'] ) ) { |
| 476 | |
| 477 | $all_plugins = get_plugins(); |
| 478 | |
| 479 | /* Private and public keys */ |
| 480 | $gglcptch_keys = array( |
| 481 | 'public' => array( |
| 482 | 'display_name' => __( 'Site key', 'google-captcha' ), |
| 483 | 'form_name' => 'gglcptch_public_key', |
| 484 | 'error_msg' => '', |
| 485 | ), |
| 486 | 'private' => array( |
| 487 | 'display_name' => __( 'Secret Key', 'google-captcha' ), |
| 488 | 'form_name' => 'gglcptch_private_key', |
| 489 | 'error_msg' => '', |
| 490 | ), |
| 491 | ); |
| 492 | |
| 493 | /* Checked forms */ |
| 494 | $gglcptch_forms = array( |
| 495 | array( 'login_form', __( 'Login form', 'google-captcha' ) ), |
| 496 | array( 'registration_form', __( 'Registration form', 'google-captcha' ) ), |
| 497 | array( 'reset_pwd_form', __( 'Reset password form', 'google-captcha' ) ), |
| 498 | array( 'comments_form', __( 'Comments form', 'google-captcha' ) ), |
| 499 | ); |
| 500 | |
| 501 | /* Google captcha themes */ |
| 502 | $gglcptch_themes = array( |
| 503 | array( 'red', 'Red' ), |
| 504 | array( 'white', 'White' ), |
| 505 | array( 'blackglass', 'Blackglass' ), |
| 506 | array( 'clean', 'Clean' ), |
| 507 | ); |
| 508 | |
| 509 | /* Save data for settings page */ |
| 510 | if ( isset( $_POST['gglcptch_form_submit'] ) && check_admin_referer( $plugin_basename, 'gglcptch_nonce_name' ) ) { |
| 511 | if ( isset( $_POST['bws_hide_premium_options'] ) ) { |
| 512 | $hide_result = bws_hide_premium_options( $gglcptch_options ); |
| 513 | $gglcptch_options = $hide_result['options']; |
| 514 | } |
| 515 | |
| 516 | if ( ! $_POST['gglcptch_public_key'] || '' == $_POST['gglcptch_public_key'] ) { |
| 517 | $gglcptch_keys['public']['error_msg'] = __( 'Enter site key', 'google-captcha' ); |
| 518 | $error = __( "WARNING: The captcha will not display while you don't fill key fields.", 'google-captcha' ); |
| 519 | } else |
| 520 | $gglcptch_keys['public']['error_msg'] = ''; |
| 521 | |
| 522 | if ( ! $_POST['gglcptch_private_key'] || '' == $_POST['gglcptch_private_key'] ) { |
| 523 | $gglcptch_keys['private']['error_msg'] = __( 'Enter secret key', 'google-captcha' ); |
| 524 | $error = __( "WARNING: The captcha will not display while you don't fill key fields.", 'google-captcha' ); |
| 525 | } else |
| 526 | $gglcptch_keys['private']['error_msg'] = ''; |
| 527 | |
| 528 | if ( $_POST['gglcptch_public_key'] != $gglcptch_options['public_key'] || $_POST['gglcptch_private_key'] != $gglcptch_options['private_key'] ) |
| 529 | $gglcptch_options['keys_verified'] = false; |
| 530 | |
| 531 | $gglcptch_options['whitelist_message'] = stripslashes( esc_html( $_POST['gglcptch_whitelist_message'] ) ); |
| 532 | $gglcptch_options['public_key'] = trim( stripslashes( esc_html( $_POST['gglcptch_public_key'] ) ) ); |
| 533 | $gglcptch_options['private_key'] = trim( stripslashes( esc_html( $_POST['gglcptch_private_key'] ) ) ); |
| 534 | $gglcptch_options['login_form'] = isset( $_POST['gglcptch_login_form'] ) ? 1 : 0; |
| 535 | $gglcptch_options['registration_form'] = isset( $_POST['gglcptch_registration_form'] ) ? 1 : 0; |
| 536 | $gglcptch_options['reset_pwd_form'] = isset( $_POST['gglcptch_reset_pwd_form'] ) ? 1 : 0; |
| 537 | $gglcptch_options['comments_form'] = isset( $_POST['gglcptch_comments_form'] ) ? 1 : 0; |
| 538 | $gglcptch_options['contact_form'] = isset( $_POST['gglcptch_contact_form'] ) ? 1 : 0; |
| 539 | $gglcptch_options['recaptcha_version'] = 'v1' == $_POST['gglcptch_recaptcha_version'] ? 'v1' : 'v2'; |
| 540 | $gglcptch_options['theme'] = stripslashes( esc_html( $_POST['gglcptch_theme'] ) ); |
| 541 | $gglcptch_options['theme_v2'] = stripslashes( esc_html( $_POST['gglcptch_theme_v2'] ) ); |
| 542 | |
| 543 | if ( function_exists( 'get_editable_roles' ) ) { |
| 544 | foreach ( get_editable_roles() as $role => $fields ) { |
| 545 | $gglcptch_options[ $role ] = isset( $_POST[ 'gglcptch_' . $role ] ) ? 1 : 0; |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | update_option( 'gglcptch_options', $gglcptch_options ); |
| 550 | $message = __( 'Settings saved', 'google-captcha' ); |
| 551 | } |
| 552 | |
| 553 | if ( isset( $_REQUEST['bws_restore_confirm'] ) && check_admin_referer( $plugin_basename, 'bws_settings_nonce_name' ) ) { |
| 554 | $gglcptch_options = gglcptch_get_default_options(); |
| 555 | update_option( 'gglcptch_options', $gglcptch_options ); |
| 556 | $message = __( 'All plugin settings were restored', 'google-captcha' ); |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | $bws_hide_premium_options_check = bws_hide_premium_options_check( $gglcptch_options ); |
| 561 | |
| 562 | /* GO PRO */ |
| 563 | if ( isset( $_GET['action'] ) && 'go_pro' == $_GET['action'] ) { |
| 564 | $go_pro_result = bws_go_pro_tab_check( $plugin_basename, 'gglcptch_options' ); |
| 565 | if ( ! empty( $go_pro_result['error'] ) ) |
| 566 | $error = $go_pro_result['error']; |
| 567 | elseif ( ! empty( $go_pro_result['message'] ) ) |
| 568 | $message = $go_pro_result['message']; |
| 569 | } ?> |
| 570 | <div class="wrap gglcptch_settings_page"> |
| 571 | <h1 style="line-height: normal;"><?php _e( 'Google Captcha Settings', 'google-captcha' ); ?></h1> |
| 572 | <h2 class="nav-tab-wrapper"> |
| 573 | <a class="nav-tab<?php if ( ! isset( $_GET['action'] ) ) echo ' nav-tab-active'; ?>" href="admin.php?page=google-captcha.php"><?php _e( 'Settings', 'google-captcha' ); ?></a> |
| 574 | <a class="nav-tab<?php if ( isset( $_GET['action'] ) && 'whitelist' == $_GET['action'] ) echo ' nav-tab-active'; ?>" href="admin.php?page=google-captcha.php&action=whitelist"><?php _e( 'Whitelist', 'google-captcha' ); ?></a> |
| 575 | <a class="nav-tab <?php if ( isset( $_GET['action'] ) && 'custom_code' == $_GET['action'] ) echo ' nav-tab-active'; ?>" href="admin.php?page=google-captcha.php&action=custom_code"><?php _e( 'Custom code', 'google-captcha' ); ?></a> |
| 576 | <a class="nav-tab<?php if ( isset( $_GET['action'] ) && 'go_pro' == $_GET['action'] ) echo ' nav-tab-active'; ?> bws_go_pro_tab" href="admin.php?page=google-captcha.php&action=go_pro"><?php _e( 'Go PRO', 'google-captcha' ); ?></a> |
| 577 | </h2> |
| 578 | <?php if ( ! isset( $_GET['action'] ) && ! isset( $_REQUEST['bws_restore_default'] ) ) { |
| 579 | if ( $gglcptch_options['recaptcha_version'] == 'v1' ) { |
| 580 | printf( '<div id="gglcptch_v1_notice" class="updated inline"><p><strong>%s</strong></p></div>', |
| 581 | __( "Only one reCAPTCHA can be displayed on the page, it's related to reCAPTCHA version 1 features.", 'google-captcha' ) |
| 582 | ); |
| 583 | } |
| 584 | } |
| 585 | bws_show_settings_notice(); ?> |
| 586 | <div class="updated fade inline" <?php if ( "" == $message ) echo 'style="display:none"'; ?>><p><strong><?php echo $message; ?></strong></p></div> |
| 587 | <div class="error inline" <?php if ( "" == $error ) echo 'style="display:none"'; ?>><p><strong><?php echo $error; ?></strong></p></div> |
| 588 | <?php if ( ! empty( $hide_result['message'] ) ) { ?> |
| 589 | <div class="updated fade inline"><p><strong><?php echo $hide_result['message']; ?></strong></p></div> |
| 590 | <?php } |
| 591 | if ( ! isset( $_GET['action'] ) ) { |
| 592 | if ( isset( $_REQUEST['bws_restore_default'] ) && check_admin_referer( $plugin_basename, 'bws_settings_nonce_name' ) ) { |
| 593 | bws_form_restore_default_confirm( $plugin_basename ); |
| 594 | } else { ?> |
| 595 | <div style="margin: 20px 0;"> |
| 596 | <?php printf( __( "If you would like to add a Google Captcha (reCAPTCHA) to your page or post, please use %s button", 'google-captcha' ), |
| 597 | '<span class="bwsicons bwsicons-shortcode"></span>' |
| 598 | ); |
| 599 | echo bws_add_help_box( sprintf( |
| 600 | __( "You can add the Google Captcha (reCAPTCHA) to your page or post by clicking on %s button in the content edit block using the Visual mode. If the button isn't displayed or you would like to add the Google Captcha (reCAPTCHA) to your own form , please use the shortcode %s", 'google-captcha' ), |
| 601 | '<span class="bwsicons bwsicons-shortcode"></span>', |
| 602 | sprintf( '<span class="bws_code">[bws_google_captcha]</span><br/>' ) |
| 603 | ) ); ?> |
| 604 | </div> |
| 605 | <form id="gglcptch_admin_settings_page" class="bws_form" method="post" action="admin.php?page=google-captcha.php"> |
| 606 | <h3><?php _e( 'Authentication', 'google-captcha' ); ?></h3> |
| 607 | <p><?php printf( __( 'Before you are able to do something, you must to register %shere%s', 'google-captcha' ), '<a target="_blank" href="https://www.google.com/recaptcha/admin#list">','</a>.' ); ?></p> |
| 608 | <p><?php _e( 'Enter site key and secret key, that you get after registration', 'google-captcha' ); ?></p> |
| 609 | <table id="gglcptch-keys" class="form-table"> |
| 610 | <?php foreach ( $gglcptch_keys as $key => $fields ) { ?> |
| 611 | <tr valign="top"> |
| 612 | <th scope="row"><?php echo $fields['display_name']; ?></th> |
| 613 | <td> |
| 614 | <input type="text" name="<?php echo $fields['form_name']; ?>" value="<?php echo $gglcptch_options[ $key . '_key' ] ?>" maxlength="200" /> |
| 615 | <label class="gglcptch_error_msg error"><?php echo $fields['error_msg']; ?></label> |
| 616 | <span class="dashicons dashicons-yes gglcptch_verified <?php if ( ! isset( $gglcptch_options['keys_verified'] ) || true !== $gglcptch_options['keys_verified'] ) echo 'hidden'; ?>"></span> |
| 617 | </td> |
| 618 | </tr> |
| 619 | <?php } ?> |
| 620 | </table> |
| 621 | <?php if ( ! empty( $gglcptch_options['public_key'] ) && ! empty( $gglcptch_options['private_key'] ) ) { ?> |
| 622 | <p id="gglcptch-test-keys" class="submit hide-if-no-js"> |
| 623 | <a class="button button-secondary" href="<?php echo add_query_arg( array( '_wpnonce' => wp_create_nonce( 'gglcptch-test-keys' ) , 'action' => 'gglcptch-test-keys' ), admin_url( 'admin-ajax.php' ) ); ?>"><?php _e( 'Test Keys' , 'google-captcha' ); ?></a> |
| 624 | </p> |
| 625 | <?php } ?> |
| 626 | <h3><?php _e( 'Options', 'google-captcha' ); ?></h3> |
| 627 | <table class="form-table"> |
| 628 | <tr valign="top"> |
| 629 | <th scope="row"><?php _e( 'Enable reCAPTCHA for', 'google-captcha' ); ?></th> |
| 630 | <td> |
| 631 | <fieldset> |
| 632 | <p> |
| 633 | <i><?php _e( 'WordPress default', 'google-captcha' ); ?></i> |
| 634 | </p> |
| 635 | <?php foreach ( $gglcptch_forms as $form ) { |
| 636 | $gglcptch_form_type = $form[0]; |
| 637 | $gglcptch_form_name = $form[1]; |
| 638 | $gglcptch_form_attr = ( '1' == $gglcptch_options[ $gglcptch_form_type ] ) ? 'checked="checked"' : ''; |
| 639 | $gglcptch_form_notice = ''; |
| 640 | |
| 641 | if ( ( $gglcptch_form_type == 'registration_form' || $gglcptch_form_type == 'reset_pwd_form' ) && ! $is_main_site ) { |
| 642 | $gglcptch_form_notice .= sprintf( '<span class="bws_info">%s</span>', __( 'This option is available only for network or for main blog', 'google-captcha' ) ); |
| 643 | $gglcptch_form_attr = 'disabled="disabled" readonly="readonly"'; |
| 644 | } ?> |
| 645 | <label><input type="checkbox" name="<?php echo 'gglcptch_' . $gglcptch_form_type; ?>" value="<?php echo $gglcptch_form_type; ?>" <?php echo $gglcptch_form_attr; ?> /> <?php echo $gglcptch_form_name; ?></label> |
| 646 | <?php echo bws_add_help_box( '<img src="' . plugins_url( 'google-captcha/images/') . $gglcptch_form_type . '.jpg">', 'bws-auto-width' ); ?> |
| 647 | <span class="bws_info"><?php echo $gglcptch_form_notice; ?></span><br /> |
| 648 | <?php } ?> |
| 649 | <br /> |
| 650 | <p> |
| 651 | <i><?php _e( 'Plugins', 'google-captcha' ); ?></i> |
| 652 | </p> |
| 653 | <?php /* Check Contact Form by BestWebSoft */ |
| 654 | $gglcptch_plugin = $bws_contact_form; |
| 655 | $gglcptch_plugin_name = 'Contact Form by BestWebSoft'; |
| 656 | $gglcptch_attrs = $gglcptch_plugin_notice = ''; |
| 657 | if ( 'deactivated' == $gglcptch_plugin['status'] ) { |
| 658 | $gglcptch_attrs = 'disabled="disabled"'; |
| 659 | $gglcptch_plugin_notice = sprintf( __( 'You should %s to use this functionality', 'google-captcha' ), |
| 660 | sprintf( '<a href="%splugins.php">%s%s %s</a>', $admin_url, __( 'activate', 'google-captcha' ), ( is_network_admin() ? ' ' . __( 'for network', 'google-captcha' ) : '' ), $gglcptch_plugin_name ) |
| 661 | ); |
| 662 | } elseif ( 'not_installed' == $gglcptch_plugin['status'] ) { |
| 663 | $gglcptch_attrs = 'disabled="disabled"'; |
| 664 | $gglcptch_plugin_notice = sprintf( __( 'You should %s to use this functionality', 'google-captcha' ), |
| 665 | sprintf( '<a href="https://bestwebsoft.com/products/wordpress/plugins/contact-form/?k=0a750deb99a8e5296a5432f4c9cb9b55&pn=75&v=%s&wp_v=%s">%s %s</a>', $gglcptch_plugin_info["Version"], $wp_version, __( 'download', 'google-captcha' ), $gglcptch_plugin_name ) |
| 666 | ); |
| 667 | } |
| 668 | if ( $gglcptch_attrs == '' && ( is_plugin_active( 'contact-form-multi-pro/contact-form-multi-pro.php' ) || is_plugin_active( 'contact-form-multi/contact-form-multi.php' ) ) ) |
| 669 | $gglcptch_plugin_notice = ' (' . __( 'Check off for adding captcha to forms on their settings pages', 'google-captcha' ) . ')'; |
| 670 | |
| 671 | if ( '1' == $gglcptch_options['contact_form'] && $gglcptch_attrs == '' ) { |
| 672 | $gglcptch_attrs .= ' checked="checked"'; |
| 673 | } ?> |
| 674 | <label><input type="checkbox" <?php echo $gglcptch_attrs; ?> name="gglcptch_contact_form" value="contact_form" /> <?php echo $gglcptch_plugin_name; ?></label> |
| 675 | <?php echo bws_add_help_box( '<img src="' . plugins_url( 'google-captcha/images/contact_form.jpg') . '">', 'bws-auto-width' ); ?> |
| 676 | <span class="bws_info"><?php echo $gglcptch_plugin_notice; ?></span><br /> |
| 677 | <?php gglcptch_pro_block( 'gglcptch_supported_plugins_banner' ); ?> |
| 678 | <span class="bws_info"><?php printf( __( 'If you would like to add Google Captcha (reCAPTCHA) to a custom form see %s', 'google-captcha' ), sprintf( '<a href="http://bestwebsoft.com/products/wordpress/plugins/google-captcha/faq/" target="_blank">%s</a>', __( 'FAQ', 'google-captcha' ) ) ); ?></span> |
| 679 | </fieldset> |
| 680 | </td> |
| 681 | </tr> |
| 682 | <tr valign="top"> |
| 683 | <th scope="row"><?php _e( 'Hide reCAPTCHA in Comments form for', 'google-captcha' ); ?></th> |
| 684 | <td> |
| 685 | <fieldset> |
| 686 | <?php if ( function_exists( 'get_editable_roles' ) ) { |
| 687 | foreach ( get_editable_roles() as $role => $fields) : ?> |
| 688 | <label><input type="checkbox" name="<?php echo 'gglcptch_' . $role; ?>" value=<?php echo $role; if ( isset( $gglcptch_options[ $role ] ) && '1' == $gglcptch_options[ $role ] ) echo ' checked'; ?>> <?php echo $fields['name']; ?></label><br/> |
| 689 | <?php endforeach; |
| 690 | } ?> |
| 691 | </fieldset> |
| 692 | </td> |
| 693 | </tr> |
| 694 | <tr valign="top"> |
| 695 | <th scope="row"><?php _e( 'Whitelist notification', 'google-captcha' ); ?></th> |
| 696 | <td> |
| 697 | <label> |
| 698 | <input type="text" id="gglcptch_whitelist_message" name="gglcptch_whitelist_message" value="<?php echo $gglcptch_options['whitelist_message']; ?>"> |
| 699 | <?php echo bws_add_help_box( __( 'This message will be displayed instead of the reCAPTCHA If the user IP is added to the whitelist', 'google-captcha' ) ); ?> |
| 700 | <div class="clear"></div> |
| 701 | </label> |
| 702 | </td> |
| 703 | </tr> |
| 704 | <tr valign="top"> |
| 705 | <th scope="row"><?php _e( 'reCAPTCHA version', 'google-captcha' ); ?></th> |
| 706 | <td> |
| 707 | <fieldset> |
| 708 | <label><input type="radio" name="gglcptch_recaptcha_version" value="v1"<?php if ( 'v1' == $gglcptch_options['recaptcha_version'] ) echo ' checked="checked"'; ?>> <?php _e( 'version', 'google-captcha' ); ?> 1</label> |
| 709 | <?php echo bws_add_help_box( '<img src="' . plugins_url( 'google-captcha/images/recaptcha_v1.png' ) . '">', 'bws-auto-width' ); ?><br/> |
| 710 | <label><input type="radio" name="gglcptch_recaptcha_version" value="v2"<?php if ( 'v2' == $gglcptch_options['recaptcha_version'] ) echo ' checked="checked"'; ?>> <?php _e( 'version', 'google-captcha' ); ?> 2</label> |
| 711 | <?php echo bws_add_help_box( '<img src="' . plugins_url( 'google-captcha/images/recaptcha_v2.png' ) . '">', 'bws-auto-width' ); ?><br/> |
| 712 | </fieldset> |
| 713 | </td> |
| 714 | </tr> |
| 715 | <tr class="gglcptch_theme_v1" valign="top"> |
| 716 | <th scope="row"> |
| 717 | <?php _e( 'reCAPTCHA theme', 'google-captcha' ); ?> |
| 718 | <br/><span class="bws_info">(<?php _e( 'for version', 'google-captcha' ); ?> 1)</span> |
| 719 | </th> |
| 720 | <td> |
| 721 | <select name="gglcptch_theme"> |
| 722 | <?php foreach ( $gglcptch_themes as $theme ) : ?> |
| 723 | <option value=<?php echo $theme[0]; if ( $theme[0] == $gglcptch_options['theme'] ) echo ' selected'; ?>> <?php echo $theme[1]; ?></option> |
| 724 | <?php endforeach; ?> |
| 725 | </select> |
| 726 | </td> |
| 727 | </tr> |
| 728 | <tr class="gglcptch_theme_v2" valign="top"> |
| 729 | <th scope="row"> |
| 730 | <?php _e( 'reCAPTCHA theme', 'google-captcha' ); ?> |
| 731 | <br/><span class="bws_info">(<?php _e( 'for version', 'google-captcha' ); ?> 2)</span> |
| 732 | </th> |
| 733 | <td> |
| 734 | <select name="gglcptch_theme_v2"> |
| 735 | <option value="light" <?php if ( 'light' == $gglcptch_options['theme_v2'] ) echo ' selected'; ?>>light</option> |
| 736 | <option value="dark" <?php if ( 'dark' == $gglcptch_options['theme_v2'] ) echo ' selected'; ?>>dark</option> |
| 737 | </select> |
| 738 | </td> |
| 739 | </tr> |
| 740 | </table> |
| 741 | <?php gglcptch_pro_block( 'gglcptch_additional_settings_banner' ); ?> |
| 742 | <p class="submit"> |
| 743 | <input id="bws-submit-button" type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'google-captcha' ); ?>" name="gglcptch_save_changes" /> |
| 744 | <input type="hidden" name="gglcptch_form_submit" value="submit" /> |
| 745 | <?php wp_nonce_field( $plugin_basename, 'gglcptch_nonce_name' ); ?> |
| 746 | </p> |
| 747 | </form> |
| 748 | <?php bws_form_restore_default_settings( $plugin_basename ); |
| 749 | } |
| 750 | } elseif ( 'whitelist' == $_GET['action'] ) { |
| 751 | require_once( dirname( __FILE__ ) . '/includes/whitelist.php' ); |
| 752 | $page = new Gglcptch_Whitelist( $plugin_basename ); |
| 753 | if ( is_object( $page ) ) |
| 754 | $page->display_content(); |
| 755 | } elseif ( 'custom_code' == $_GET['action'] ) { |
| 756 | bws_custom_code_tab(); |
| 757 | } elseif ( 'go_pro' == $_GET['action'] ) { |
| 758 | bws_go_pro_tab_show( $bws_hide_premium_options_check, $gglcptch_plugin_info, $plugin_basename, 'google-captcha.php', 'google-captcha-pro.php', 'google-captcha-pro/google-captcha-pro.php', 'google-captcha', 'b850d949ccc1239cab0da315c3c822ab', '109', isset( $go_pro_result['pro_plugin_is_activated'] ) ); |
| 759 | } |
| 760 | bws_plugin_reviews_block( $gglcptch_plugin_info['Name'], 'google-captcha' ); ?> |
| 761 | </div> |
| 762 | <?php } |
| 763 | } |
| 764 | |
| 765 | /* Checking current user role */ |
| 766 | if ( ! function_exists( 'gglcptch_check_role' ) ) { |
| 767 | function gglcptch_check_role() { |
| 768 | global $current_user, $gglcptch_options; |
| 769 | |
| 770 | if ( ! is_user_logged_in() ) |
| 771 | return false; |
| 772 | |
| 773 | if ( ! empty( $current_user->roles[0] ) ) { |
| 774 | $role = $current_user->roles[0]; |
| 775 | if ( empty( $gglcptch_options ) ) |
| 776 | register_gglcptch_settings(); |
| 777 | return isset( $gglcptch_options[ $role ] ) && '1' == $gglcptch_options[ $role ] ? true : false; |
| 778 | } else |
| 779 | return false; |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | /* Display google captcha via shortcode */ |
| 784 | if ( ! function_exists( 'gglcptch_display' ) ) { |
| 785 | function gglcptch_display( $content = false ) { |
| 786 | global $gglcptch_options, $gglcptch_count, $gglcptch_ip_in_whitelist, $gglcptch_plugin_info; |
| 787 | |
| 788 | if ( empty( $gglcptch_options ) ) |
| 789 | register_gglcptch_settings(); |
| 790 | |
| 791 | if ( empty( $gglcptch_ip_in_whitelist ) ) |
| 792 | $gglcptch_ip_in_whitelist = gglcptch_whitelisted_ip(); |
| 793 | |
| 794 | if ( ! $gglcptch_ip_in_whitelist ) { |
| 795 | |
| 796 | if ( ! $gglcptch_count ) |
| 797 | $gglcptch_count = 1; |
| 798 | |
| 799 | $publickey = $gglcptch_options['public_key']; |
| 800 | $privatekey = $gglcptch_options['private_key']; |
| 801 | |
| 802 | $content .= '<div class="gglcptch gglcptch_' . $gglcptch_options['recaptcha_version'] . '">'; |
| 803 | if ( ! $privatekey || ! $publickey ) { |
| 804 | if ( current_user_can( 'manage_options' ) ) { |
| 805 | $content .= sprintf( |
| 806 | '<strong>%s <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s <a target="_blank" href="%s">%s</a>.</strong>', |
| 807 | __( 'To use Google Captcha you must get the keys from', 'google-captcha' ), |
| 808 | __( 'here', 'google-captcha' ), |
| 809 | __( 'and enter them on the', 'google-captcha' ), |
| 810 | admin_url( '/admin.php?page=google-captcha.php' ), |
| 811 | __( 'plugin setting page', 'google-captcha' ) |
| 812 | ); |
| 813 | } |
| 814 | $content .= '</div>'; |
| 815 | $gglcptch_count++; |
| 816 | return $content; |
| 817 | } |
| 818 | |
| 819 | /* generating random id value in case of getting content with pagination plugin for not getting duplicate id values */ |
| 820 | $id = mt_rand(); |
| 821 | if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) { |
| 822 | $content .= '<div id="gglcptch_recaptcha_' . $id . '" class="gglcptch_recaptcha"></div> |
| 823 | <noscript> |
| 824 | <div style="width: 302px;"> |
| 825 | <div style="width: 302px; height: 422px; position: relative;"> |
| 826 | <div style="width: 302px; height: 422px; position: absolute;"> |
| 827 | <iframe src="https://www.google.com/recaptcha/api/fallback?k=' . $publickey . '" frameborder="0" scrolling="no" style="width: 302px; height:422px; border-style: none;"></iframe> |
| 828 | </div> |
| 829 | </div> |
| 830 | <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;"> |
| 831 | <textarea 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;"></textarea> |
| 832 | </div> |
| 833 | </div> |
| 834 | </noscript>'; |
| 835 | $api_url = "https://www.google.com/recaptcha/api.js"; |
| 836 | } else { |
| 837 | require_once( 'lib/recaptchalib.php' ); |
| 838 | $content .= '<div id="gglcptch_recaptcha_' . $id . '" class="gglcptch_recaptcha"></div>'; |
| 839 | $content .= gglcptch_recaptcha_get_html( $publickey, null, is_ssl() ); |
| 840 | $api_url = "https://www.google.com/recaptcha/api/js/recaptcha_ajax.js"; |
| 841 | } |
| 842 | $content .= '</div>'; |
| 843 | $gglcptch_count++; |
| 844 | |
| 845 | /* register reCAPTCHA script */ |
| 846 | if ( ! wp_script_is( 'gglcptch_api', 'registered' ) ) { |
| 847 | wp_register_script( 'gglcptch_api', $api_url, false, $gglcptch_plugin_info['Version'], true ); |
| 848 | add_action( 'wp_footer', 'gglcptch_add_scripts' ); |
| 849 | if ( |
| 850 | '1' == $gglcptch_options['login_form'] || |
| 851 | '1' == $gglcptch_options['reset_pwd_form'] || |
| 852 | '1' == $gglcptch_options['registration_form'] |
| 853 | ) |
| 854 | add_action( 'login_footer', 'gglcptch_add_scripts' ); |
| 855 | } |
| 856 | } else { |
| 857 | if ( ! empty( $gglcptch_options['whitelist_message'] ) ) |
| 858 | $content .= '<label class="gglcptch_whitelist_message">' . $gglcptch_options['whitelist_message'] . '</label>'; |
| 859 | } |
| 860 | |
| 861 | return $content; |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | if ( ! function_exists( 'gglcptch_get_response' ) ) { |
| 866 | function gglcptch_get_response( $privatekey, $remote_ip ) { |
| 867 | $args = array( |
| 868 | 'body' => array( |
| 869 | 'secret' => $privatekey, |
| 870 | 'response' => stripslashes( esc_html( $_POST["g-recaptcha-response"] ) ), |
| 871 | 'remoteip' => $remote_ip, |
| 872 | ), |
| 873 | 'sslverify' => false |
| 874 | ); |
| 875 | $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $args ); |
| 876 | return json_decode( wp_remote_retrieve_body( $resp ), true ); |
| 877 | } |
| 878 | } |
| 879 | |
| 880 | /* Check google captcha */ |
| 881 | if ( ! function_exists( 'gglcptch_check' ) ) { |
| 882 | function gglcptch_check( $debug = false ) { |
| 883 | global $gglcptch_options; |
| 884 | |
| 885 | if ( empty( $gglcptch_options ) ) |
| 886 | register_gglcptch_settings(); |
| 887 | |
| 888 | $publickey = $gglcptch_options['public_key']; |
| 889 | $privatekey = $gglcptch_options['private_key']; |
| 890 | |
| 891 | if ( ! $privatekey || ! $publickey ) { |
| 892 | return array( |
| 893 | 'response' => false, |
| 894 | 'reason' => 'ERROR_NO_KEYS' |
| 895 | ); |
| 896 | } |
| 897 | |
| 898 | $gglcptch_remote_addr = filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP ); |
| 899 | |
| 900 | if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) { |
| 901 | |
| 902 | if ( ! isset( $_POST["g-recaptcha-response"] ) ) { |
| 903 | return array( |
| 904 | 'response' => false, |
| 905 | 'reason' => 'RECAPTCHA_NO_RESPONSE' |
| 906 | ); |
| 907 | } elseif ( empty( $_POST["g-recaptcha-response"] ) ) { |
| 908 | return array( |
| 909 | 'response' => false, |
| 910 | 'reason' => 'RECAPTCHA_EMPTY_RESPONSE' |
| 911 | ); |
| 912 | } |
| 913 | |
| 914 | $response = gglcptch_get_response( $privatekey, $gglcptch_remote_addr ); |
| 915 | |
| 916 | if ( isset( $response['success'] ) && !! $response['success'] ) { |
| 917 | return array( |
| 918 | 'response' => true, |
| 919 | 'reason' => '' |
| 920 | ); |
| 921 | } else { |
| 922 | return array( |
| 923 | 'response' => false, |
| 924 | 'reason' => $debug ? $response['error-codes'] : 'VERIFICATION_FAILED' |
| 925 | ); |
| 926 | } |
| 927 | } else { |
| 928 | $gglcptch_recaptcha_challenge_field = $gglcptch_recaptcha_response_field = ''; |
| 929 | |
| 930 | if ( ! isset( $_POST['recaptcha_challenge_field'] ) && ! isset( $_POST['recaptcha_response_field'] ) ) { |
| 931 | return array( |
| 932 | 'response' => false, |
| 933 | 'reason' => 'RECAPTCHA_NO_RESPONSE' |
| 934 | ); |
| 935 | } elseif ( ! empty( $_POST['recaptcha_challenge_field'] ) && empty( $_POST['recaptcha_response_field'] ) ) { |
| 936 | return array( |
| 937 | 'response' => false, |
| 938 | 'reason' => 'RECAPTCHA_EMPTY_RESPONSE' |
| 939 | ); |
| 940 | } else { |
| 941 | $gglcptch_recaptcha_challenge_field = stripslashes( esc_html( $_POST['recaptcha_challenge_field'] ) ); |
| 942 | $gglcptch_recaptcha_response_field = stripslashes( esc_html( $_POST['recaptcha_response_field'] ) ); |
| 943 | } |
| 944 | |
| 945 | require_once( 'lib/recaptchalib.php' ); |
| 946 | $response = gglcptch_recaptcha_check_answer( $privatekey, $gglcptch_remote_addr, $gglcptch_recaptcha_challenge_field, $gglcptch_recaptcha_response_field ); |
| 947 | |
| 948 | if ( ! $response->is_valid ) { |
| 949 | return array( |
| 950 | 'response' => false, |
| 951 | 'reason' => $debug ? $response->error : 'VERIFICATION_FAILED' |
| 952 | ); |
| 953 | } else { |
| 954 | return array( |
| 955 | 'response' => true, |
| 956 | 'reason' => '' |
| 957 | ); |
| 958 | } |
| 959 | } |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | /* Add google captcha to the login form */ |
| 964 | if ( ! function_exists( 'gglcptch_login_display' ) ) { |
| 965 | function gglcptch_login_display() { |
| 966 | global $gglcptch_options; |
| 967 | if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) { |
| 968 | $from_width = 302; |
| 969 | } else { |
| 970 | $from_width = 320; |
| 971 | if ( 'clean' == $gglcptch_options['theme'] ) |
| 972 | $from_width = 450; |
| 973 | } ?> |
| 974 | <style type="text/css" media="screen"> |
| 975 | .login-action-login #loginform, |
| 976 | .login-action-lostpassword #lostpasswordform, |
| 977 | .login-action-register #registerform { |
| 978 | width: <?php echo $from_width; ?>px !important; |
| 979 | } |
| 980 | #login_error, |
| 981 | .message { |
| 982 | width: <?php echo $from_width + 20; ?>px !important; |
| 983 | } |
| 984 | .login-action-login #loginform .gglcptch, |
| 985 | .login-action-lostpassword #lostpasswordform .gglcptch, |
| 986 | .login-action-register #registerform .gglcptch { |
| 987 | margin-bottom: 10px; |
| 988 | } |
| 989 | </style> |
| 990 | <?php echo gglcptch_display(); |
| 991 | return true; |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | /* Check google captcha in login form */ |
| 996 | if ( ! function_exists( 'gglcptch_login_check' ) ) { |
| 997 | function gglcptch_login_check( $user ) { |
| 998 | |
| 999 | $result = gglcptch_check(); |
| 1000 | |
| 1001 | if ( ! $result['response'] ) { |
| 1002 | if ( $result['reason'] == 'ERROR_NO_KEYS' ) { |
| 1003 | return $user; |
| 1004 | } |
| 1005 | |
| 1006 | $error_message = sprintf( '<strong>%s</strong>: %s', __( 'Error', 'google-captcha' ), __( 'You have entered an incorrect reCAPTCHA value', 'google-captcha' ) ); |
| 1007 | |
| 1008 | if ( $result['reason'] == 'VERIFICATION_FAILED' ) { |
| 1009 | wp_clear_auth_cookie(); |
| 1010 | return new WP_Error( 'gglcptch_error', $error_message ); |
| 1011 | } |
| 1012 | |
| 1013 | if ( isset( $_REQUEST['log'] ) && isset( $_REQUEST['pwd'] ) ) { |
| 1014 | return new WP_Error( 'gglcptch_error', $error_message ); |
| 1015 | } else { |
| 1016 | return $user; |
| 1017 | } |
| 1018 | } else { |
| 1019 | return $user; |
| 1020 | } |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | /* Check google captcha in BWS Contact Form */ |
| 1025 | if ( ! function_exists( 'gglcptch_recaptcha_check' ) ) { |
| 1026 | function gglcptch_recaptcha_check( $allow = true ) { |
| 1027 | /** |
| 1028 | * this condition is necessary for compatibility |
| 1029 | * with Contact Form ( Free and Pro ) by BestWebsoft plugins versions |
| 1030 | * that use $_POST as parameter for hook ( old versions ) |
| 1031 | * apply_filters( 'cntctfrmpr_check_form', $_POST ); |
| 1032 | * @deprecated since 1.22 |
| 1033 | * @todo remove after 25.02.2017 |
| 1034 | */ |
| 1035 | if ( is_array( $allow ) ) { |
| 1036 | $allow = false; |
| 1037 | $old_cf_version = true; |
| 1038 | } else /* end @todo */ if ( ! $allow || is_string( $allow ) || is_wp_error( $allow ) ) { |
| 1039 | return $allow; |
| 1040 | } |
| 1041 | |
| 1042 | $result = gglcptch_check(); |
| 1043 | |
| 1044 | if ( $result['response'] || $result['reason'] == 'ERROR_NO_KEYS' ) |
| 1045 | return true; |
| 1046 | |
| 1047 | /** |
| 1048 | * @deprecated since 1.22 |
| 1049 | * @todo remove after 25.02.2017 |
| 1050 | */ |
| 1051 | if ( isset( $old_cf_version ) ) { |
| 1052 | return false; |
| 1053 | } else /* end @todo */ { |
| 1054 | $error_message = '<strong>' . __( 'Error', 'google-captcha' ) . '</strong>: ' . __( 'You have entered an incorrect reCAPTCHA value', 'google-captcha' ); |
| 1055 | /** |
| 1056 | * Function 'cntctfrm_handle_captcha_filters' was added in Contact Form 4.0.2 (Free and Pro) |
| 1057 | * remove this condition. WP_Error is correct object for return. |
| 1058 | * @deprecated since 1.26 |
| 1059 | * @todo remove after 01.08.2017 |
| 1060 | */ |
| 1061 | if ( function_exists( 'cntctfrm_handle_captcha_filters' ) ) { |
| 1062 | $allow = new WP_Error(); |
| 1063 | $allow->add( 'gglcptch_error', $error_message ); |
| 1064 | } else { |
| 1065 | $allow = $error_message; |
| 1066 | } |
| 1067 | } |
| 1068 | return $allow; |
| 1069 | } |
| 1070 | } |
| 1071 | |
| 1072 | /* Check google captcha in lostpassword form */ |
| 1073 | if ( ! function_exists( 'gglcptch_lostpassword_check' ) ) { |
| 1074 | function gglcptch_lostpassword_check( $allow ) { |
| 1075 | |
| 1076 | $result = gglcptch_check(); |
| 1077 | |
| 1078 | if ( $result['response'] || $result['reason'] == 'ERROR_NO_KEYS' ) |
| 1079 | return $allow; |
| 1080 | |
| 1081 | if ( ! is_wp_error( $allow ) ) |
| 1082 | $allow = new WP_Error(); |
| 1083 | |
| 1084 | $allow->add( 'gglcptch_error', '<strong>' . __( 'ERROR', 'google-captcha' ) . '</strong>: ' . __( 'You have entered an incorrect reCAPTCHA value', 'google-captcha' ) . '.' ); |
| 1085 | return $allow; |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | /* Add google captcha to the multisite login form */ |
| 1090 | if ( ! function_exists( 'gglcptch_signup_display' ) ) { |
| 1091 | function gglcptch_signup_display( $errors ) { |
| 1092 | if ( $error_message = $errors->get_error_message( 'gglcptch_error' ) ) { |
| 1093 | printf( '<p class="error gglcptch_error">%s</p>', $error_message ); |
| 1094 | } |
| 1095 | echo gglcptch_display(); |
| 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | /* Check google captcha in multisite login form */ |
| 1100 | if ( ! function_exists( 'gglcptch_signup_check' ) ) { |
| 1101 | function gglcptch_signup_check( $result ) { |
| 1102 | global $current_user; |
| 1103 | |
| 1104 | if ( is_admin() && ! defined( 'DOING_AJAX' ) && ! empty( $current_user->data->ID ) ) |
| 1105 | return $result; |
| 1106 | |
| 1107 | $check_result = gglcptch_check(); |
| 1108 | |
| 1109 | if ( $check_result['response'] || $check_result['reason'] == 'ERROR_NO_KEYS' ) |
| 1110 | return $result; |
| 1111 | |
| 1112 | $error = $result['errors']; |
| 1113 | $error->add( 'gglcptch_error', '<strong>' . __( 'ERROR', 'google-captcha' ) . '</strong>: ' . __( 'You have entered an incorrect reCAPTCHA value', 'google-captcha' ) . '.' ); |
| 1114 | return $result; |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | /* Add google captcha to the comment form */ |
| 1119 | if ( ! function_exists( 'gglcptch_commentform_display' ) ) { |
| 1120 | function gglcptch_commentform_display() { |
| 1121 | if ( gglcptch_check_role() ) |
| 1122 | return; |
| 1123 | echo gglcptch_display(); |
| 1124 | return true; |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | /* Check JS enabled for comment form */ |
| 1129 | if ( ! function_exists( 'gglcptch_commentform_check' ) ) { |
| 1130 | function gglcptch_commentform_check() { |
| 1131 | if ( gglcptch_check_role() ) |
| 1132 | return; |
| 1133 | |
| 1134 | $result = gglcptch_check(); |
| 1135 | |
| 1136 | if ( $result['response'] || $result['reason'] == 'ERROR_NO_KEYS' ) |
| 1137 | return; |
| 1138 | |
| 1139 | wp_die( '<strong>' . __( 'ERROR', 'google-captcha' ) . '</strong>: ' . __( 'You have entered an incorrect reCAPTCHA value. Click the BACK button on your browser, and try again.', 'google-captcha' ) ); |
| 1140 | } |
| 1141 | } |
| 1142 | |
| 1143 | /* display google captcha in Contact form */ |
| 1144 | if ( ! function_exists( 'gglcptch_cf_display' ) ) { |
| 1145 | function gglcptch_cf_display( $content, $form_slug = "" ) { |
| 1146 | /** |
| 1147 | * this are necessary for compatibility |
| 1148 | * with old Contact Form Free and Pro by BestWebsoft versions. |
| 1149 | * correct return - $content = $content . gglcptch_display(); |
| 1150 | * @since 1.26 |
| 1151 | * @todo remove after 1.03.2017 |
| 1152 | */ |
| 1153 | if ( is_string( $content ) ) |
| 1154 | $content = $content . gglcptch_display(); |
| 1155 | elseif ( is_array( $content ) ) |
| 1156 | $content = gglcptch_display(); |
| 1157 | else |
| 1158 | $content = $form_slug . gglcptch_display(); |
| 1159 | |
| 1160 | return $content; |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | /* Check Google Captcha in shortcode and contact form */ |
| 1165 | if ( ! function_exists( 'gglcptch_captcha_check' ) ) { |
| 1166 | function gglcptch_captcha_check() { |
| 1167 | $result = gglcptch_check(); |
| 1168 | echo $result['response'] ? "success" : "error"; |
| 1169 | die(); |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | if ( ! function_exists( 'gglcptch_test_keys' ) ) { |
| 1174 | function gglcptch_test_keys() { |
| 1175 | if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'] , $_REQUEST['action'] ) ) { |
| 1176 | header( 'Content-Type: text/html' ); ?> |
| 1177 | <p><?php _e( 'Please, complete the captcha and submit "Test verification"', 'google-captcha' ); ?></p> |
| 1178 | <?php echo gglcptch_display(); ?> |
| 1179 | <p> |
| 1180 | <input type="hidden" name="gglcptch_test_keys_verification-nonce" value="<?php echo wp_create_nonce( 'gglcptch_test_keys_verification' ); ?>" /> |
| 1181 | <button id="gglcptch_test_keys_verification" name="action" class="button-primary" value="gglcptch_test_keys_verification"><?php _e( 'Test verification', 'google-captcha' ); ?></button> |
| 1182 | </p> |
| 1183 | <?php } |
| 1184 | die(); |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | if ( ! function_exists( 'gglcptch_test_keys_verification' ) ) { |
| 1189 | function gglcptch_test_keys_verification() { |
| 1190 | if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'] , $_REQUEST['action'] ) ) { |
| 1191 | $result = gglcptch_check( true ); |
| 1192 | |
| 1193 | if ( ! $result['response'] ) { |
| 1194 | $errors = array( |
| 1195 | /* custom error */ |
| 1196 | 'RECAPTCHA_EMPTY_RESPONSE' => __( 'The user response was missing', 'google-captcha' ), |
| 1197 | /* v2 error */ |
| 1198 | 'missing-input-secret' => __( 'The Secret Key is missing', 'google-captcha' ), |
| 1199 | 'invalid-input-secret' => sprintf( |
| 1200 | '<strong>%s</strong>. <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s.', |
| 1201 | __( 'The Secret Key is invalid', 'google-captcha' ), |
| 1202 | __( 'Check your domain configuration', 'google-captcha' ), |
| 1203 | __( 'and enter it again', 'google-captcha' ) |
| 1204 | ), |
| 1205 | 'missing-input-response' => __( 'The user response was missing', 'google-captcha' ), |
| 1206 | 'invalid-input-response' => __( 'The user response is invalid', 'google-captcha' ), |
| 1207 | /* v1 error */ |
| 1208 | 'invalid-site-private-key' => sprintf( |
| 1209 | '<strong>%s</strong>. <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s.', |
| 1210 | __( 'The Secret Key is invalid', 'google-captcha' ), |
| 1211 | __( 'Check your domain configuration', 'google-captcha' ), |
| 1212 | __( 'and enter it again', 'google-captcha' ) |
| 1213 | ), |
| 1214 | 'incorrect-captcha-sol' => __( 'The user response is invalid', 'google-captcha' ), |
| 1215 | ); |
| 1216 | |
| 1217 | if ( isset( $result['reason'] ) ) { |
| 1218 | foreach ( (array)$result['reason'] as $error ) { ?> |
| 1219 | <div class="error gglcptch-test-results"><p><?php echo $error; ?></p></div> |
| 1220 | <?php } |
| 1221 | } |
| 1222 | } else { ?> |
| 1223 | <div class="updated gglcptch-test-results"><p><?php _e( 'The verification is successfully completed','google-captcha' ); ?></p></div> |
| 1224 | <?php $gglcptch_options = get_option( 'gglcptch_options' ); |
| 1225 | $gglcptch_options['keys_verified'] = true; |
| 1226 | update_option( 'gglcptch_options', $gglcptch_options ); |
| 1227 | } |
| 1228 | } |
| 1229 | die(); |
| 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | if ( ! function_exists( 'gglcptch_action_links' ) ) { |
| 1234 | function gglcptch_action_links( $links, $file ) { |
| 1235 | if ( ! is_network_admin() ) { |
| 1236 | static $this_plugin; |
| 1237 | if ( ! $this_plugin ) |
| 1238 | $this_plugin = plugin_basename(__FILE__); |
| 1239 | |
| 1240 | if ( $file == $this_plugin ) { |
| 1241 | $settings_link = '<a href="admin.php?page=google-captcha.php">' . __( 'Settings', 'google-captcha' ) . '</a>'; |
| 1242 | array_unshift( $links, $settings_link ); |
| 1243 | } |
| 1244 | } |
| 1245 | return $links; |
| 1246 | } |
| 1247 | } |
| 1248 | |
| 1249 | if ( ! function_exists( 'gglcptch_shortcode_button_content' ) ) { |
| 1250 | function gglcptch_shortcode_button_content( $content ) { ?> |
| 1251 | <div id="gglcptch" style="display:none;"> |
| 1252 | <input class="bws_default_shortcode" type="hidden" name="default" value="[bws_google_captcha]" /> |
| 1253 | </div> |
| 1254 | <?php } |
| 1255 | } |
| 1256 | |
| 1257 | if ( ! function_exists( 'gglcptch_links' ) ) { |
| 1258 | function gglcptch_links( $links, $file ) { |
| 1259 | $base = plugin_basename( __FILE__ ); |
| 1260 | if ( $file == $base ) { |
| 1261 | if ( ! is_network_admin() ) |
| 1262 | $links[] = '<a href="admin.php?page=google-captcha.php">' . __( 'Settings', 'google-captcha' ) . '</a>'; |
| 1263 | $links[] = '<a href="https://support.bestwebsoft.com/hc/en-us/sections/200538719" target="_blank">' . __( 'FAQ', 'google-captcha' ) . '</a>'; |
| 1264 | $links[] = '<a href="https://support.bestwebsoft.com">' . __( 'Support', 'google-captcha' ) . '</a>'; |
| 1265 | } |
| 1266 | return $links; |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | if ( ! function_exists ( 'gglcptch_plugin_banner' ) ) { |
| 1271 | function gglcptch_plugin_banner() { |
| 1272 | global $hook_suffix, $gglcptch_plugin_info, $gglcptch_options; |
| 1273 | if ( 'plugins.php' == $hook_suffix ) { |
| 1274 | if ( empty( $gglcptch_options ) ) |
| 1275 | register_gglcptch_settings(); |
| 1276 | |
| 1277 | if ( empty( $gglcptch_options['public_key'] ) || empty( $gglcptch_options['private_key'] ) ) { ?> |
| 1278 | <div class="error"> |
| 1279 | <p> |
| 1280 | <?php printf( |
| 1281 | '<strong>%s <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s <a target="_blank" href="%s">%s</a>.</strong>', |
| 1282 | __( 'To use Google Captcha you must get the keys from', 'google-captcha' ), |
| 1283 | __ ( 'here', 'google-captcha' ), |
| 1284 | __ ( 'and enter them on the', 'google-captcha' ), |
| 1285 | admin_url( '/admin.php?page=google-captcha.php' ), |
| 1286 | __( 'plugin setting page', 'google-captcha' ) |
| 1287 | ); ?> |
| 1288 | </p> |
| 1289 | </div> |
| 1290 | <?php } |
| 1291 | if ( isset( $gglcptch_options['first_install'] ) && strtotime( '-1 week' ) > $gglcptch_options['first_install'] ) |
| 1292 | bws_plugin_banner( $gglcptch_plugin_info, 'gglcptch', 'google-captcha', '676d9558f9786ab41d7de35335cf5c4d', '109', '//ps.w.org/google-captcha/assets/icon-128x128.png' ); |
| 1293 | |
| 1294 | bws_plugin_banner_to_settings( $gglcptch_plugin_info, 'gglcptch_options', 'google-captcha', 'admin.php?page=google-captcha.php' ); |
| 1295 | } |
| 1296 | |
| 1297 | if ( isset( $_GET['page'] ) && 'google-captcha.php' == $_GET['page'] ) { |
| 1298 | bws_plugin_suggest_feature_banner( $gglcptch_plugin_info, 'gglcptch_options', 'google-captcha' ); |
| 1299 | } |
| 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | /* add help tab */ |
| 1304 | if ( ! function_exists( 'gglcptch_add_tabs' ) ) { |
| 1305 | function gglcptch_add_tabs() { |
| 1306 | $screen = get_current_screen(); |
| 1307 | $args = array( |
| 1308 | 'id' => 'gglcptch', |
| 1309 | 'section' => '200538719' |
| 1310 | ); |
| 1311 | bws_help_tab( $screen, $args ); |
| 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | if ( ! function_exists( 'gglcptch_delete_options' ) ) { |
| 1316 | function gglcptch_delete_options() { |
| 1317 | if ( ! function_exists( 'get_plugins' ) ) |
| 1318 | require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 1319 | $all_plugins = get_plugins(); |
| 1320 | |
| 1321 | if ( ! array_key_exists( 'google-captcha-pro/google-captcha-pro.php', $all_plugins ) ) { |
| 1322 | global $wpdb; |
| 1323 | if ( function_exists( 'is_multisite' ) && is_multisite() ) { |
| 1324 | $old_blog = $wpdb->blogid; |
| 1325 | /* Get all blog ids */ |
| 1326 | $blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" ); |
| 1327 | foreach ( $blogids as $blog_id ) { |
| 1328 | switch_to_blog( $blog_id ); |
| 1329 | $wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}gglcptch_whitelist`;" ); |
| 1330 | delete_option( 'gglcptch_options' ); |
| 1331 | } |
| 1332 | switch_to_blog( $old_blog ); |
| 1333 | delete_site_option( 'gglcptch_options' ); |
| 1334 | } else { |
| 1335 | $wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}gglcptch_whitelist`;" ); |
| 1336 | delete_option( 'gglcptch_options' ); |
| 1337 | } |
| 1338 | } |
| 1339 | |
| 1340 | require_once( dirname( __FILE__ ) . '/bws_menu/bws_include.php' ); |
| 1341 | bws_include_init( plugin_basename( __FILE__ ) ); |
| 1342 | bws_delete_plugin( plugin_basename( __FILE__ ) ); |
| 1343 | } |
| 1344 | } |
| 1345 | |
| 1346 | register_activation_hook( __FILE__, 'gglcptch_plugin_activate' ); |
| 1347 | |
| 1348 | add_action( 'admin_menu', 'gglcptch_admin_menu' ); |
| 1349 | |
| 1350 | add_action( 'init', 'gglcptch_init' ); |
| 1351 | add_action( 'admin_init', 'gglcptch_admin_init' ); |
| 1352 | |
| 1353 | add_action( 'plugins_loaded', 'gglcptch_plugins_loaded' ); |
| 1354 | |
| 1355 | add_action( 'admin_enqueue_scripts', 'gglcptch_add_admin_script_styles' ); |
| 1356 | add_action( 'wp_enqueue_scripts', 'gglcptch_add_styles' ); |
| 1357 | add_filter( 'script_loader_tag', 'gglcptch_add_async_attribute', 10, 2 ); |
| 1358 | add_action( 'admin_footer', 'gglcptch_admin_footer' ); |
| 1359 | add_filter( 'pgntn_callback', 'gglcptch_pagination_callback' ); |
| 1360 | |
| 1361 | /* custom filter for bws button in tinyMCE */ |
| 1362 | add_filter( 'bws_shortcode_button_content', 'gglcptch_shortcode_button_content' ); |
| 1363 | add_shortcode( 'bws_google_captcha', 'gglcptch_display' ); |
| 1364 | add_filter( 'widget_text', 'do_shortcode' ); |
| 1365 | |
| 1366 | add_filter( 'plugin_action_links', 'gglcptch_action_links', 10, 2 ); |
| 1367 | add_filter( 'plugin_row_meta', 'gglcptch_links', 10, 2 ); |
| 1368 | |
| 1369 | add_action( 'admin_notices', 'gglcptch_plugin_banner' ); |
| 1370 | |
| 1371 | add_action( 'wp_ajax_gglcptch_captcha_check', 'gglcptch_captcha_check' ); |
| 1372 | add_action( 'wp_ajax_nopriv_gglcptch_captcha_check', 'gglcptch_captcha_check' ); |
| 1373 | add_action( 'wp_ajax_gglcptch-test-keys', 'gglcptch_test_keys' ); |
| 1374 | add_action( 'wp_ajax_gglcptch_test_keys_verification', 'gglcptch_test_keys_verification' ); |