google-captcha
Last commit date
bws_menu
8 years ago
css
8 years ago
includes
8 years ago
js
8 years ago
languages
8 years ago
lib
8 years ago
google-captcha.php
8 years ago
readme.txt
8 years ago
screenshot-1.png
8 years ago
screenshot-2.png
8 years ago
screenshot-3.png
8 years ago
screenshot-4.png
8 years ago
screenshot-5.png
8 years ago
screenshot-6.png
8 years ago
screenshot-7.png
8 years ago
screenshot-8.png
8 years ago
screenshot-9.png
8 years ago
google-captcha.php
1135 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.31 |
| 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 | global $submenu, $wp_version, $gglcptch_plugin_info; |
| 34 | |
| 35 | $settings_page = add_menu_page( __( 'Google Captcha Settings', 'google-captcha' ), 'Google Captcha', 'manage_options', 'google-captcha.php', 'gglcptch_add_settings_page', 'none' ); |
| 36 | |
| 37 | add_submenu_page( 'google-captcha.php', __( 'Google Captcha Settings', 'google-captcha' ), __( 'Settings', 'google-captcha' ), 'manage_options', 'google-captcha.php', 'gglcptch_add_settings_page' ); |
| 38 | |
| 39 | $whitelist_page = add_submenu_page( 'google-captcha.php', __( 'Google Captcha Whitelist', 'google-captcha' ), __( 'Whitelist', 'google-captcha' ), 'manage_options', 'google-captcha-whitelist.php', 'gglcptch_add_settings_page' ); |
| 40 | |
| 41 | add_submenu_page( 'google-captcha.php', 'BWS Panel', 'BWS Panel', 'manage_options', 'gglcptch-bws-panel', 'bws_add_menu_render' ); |
| 42 | |
| 43 | if ( isset( $submenu['google-captcha.php'] ) ) |
| 44 | $submenu['google-captcha.php'][] = array( |
| 45 | '<span style="color:#d86463"> ' . __( 'Upgrade to Pro', 'google-captcha' ) . '</span>', |
| 46 | 'manage_options', |
| 47 | 'https://bestwebsoft.com/products/wordpress/plugins/google-captcha/?k=b850d949ccc1239cab0da315c3c822ab&pn=109&v=' . $gglcptch_plugin_info["Version"] . '&wp_v=' . $wp_version ); |
| 48 | |
| 49 | add_action( "load-{$settings_page}", 'gglcptch_add_tabs' ); |
| 50 | add_action( "load-{$whitelist_page}", 'gglcptch_add_tabs' ); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | if ( ! function_exists( 'gglcptch_plugins_loaded' ) ) { |
| 55 | function gglcptch_plugins_loaded() { |
| 56 | /* Internationalization, first(!) */ |
| 57 | load_plugin_textdomain( 'google-captcha', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | if ( ! function_exists( 'gglcptch_init' ) ) { |
| 62 | function gglcptch_init() { |
| 63 | global $gglcptch_plugin_info, $gglcptch_options, $gglcptch_ip_in_whitelist;; |
| 64 | |
| 65 | require_once( dirname( __FILE__ ) . '/bws_menu/bws_include.php' ); |
| 66 | bws_include_init( plugin_basename( __FILE__ ) ); |
| 67 | |
| 68 | if ( empty( $gglcptch_plugin_info ) ) { |
| 69 | if ( ! function_exists( 'get_plugin_data' ) ) |
| 70 | require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 71 | $gglcptch_plugin_info = get_plugin_data( __FILE__ ); |
| 72 | } |
| 73 | |
| 74 | /* Function check if plugin is compatible with current WP version */ |
| 75 | bws_wp_min_version_check( plugin_basename( __FILE__ ), $gglcptch_plugin_info, '3.9' ); |
| 76 | |
| 77 | $is_admin = is_admin() && ! defined( 'DOING_AJAX' ); |
| 78 | /* Call register settings function */ |
| 79 | if ( ! $is_admin || ( isset( $_GET['page'] ) && 'google-captcha.php' == $_GET['page'] ) ) |
| 80 | register_gglcptch_settings(); |
| 81 | |
| 82 | if ( ! isset( $gglcptch_ip_in_whitelist ) ) |
| 83 | $gglcptch_ip_in_whitelist = gglcptch_whitelisted_ip(); |
| 84 | |
| 85 | /* Add hooks */ |
| 86 | if ( ! $is_admin && ! empty( $gglcptch_options['public_key'] ) && ! empty( $gglcptch_options['private_key'] ) ) { |
| 87 | /* Add hooks */ |
| 88 | if ( '1' == $gglcptch_options['login_form'] || '1' == $gglcptch_options['reset_pwd_form'] || '1' == $gglcptch_options['registration_form'] ) { |
| 89 | add_action( 'login_enqueue_scripts', 'gglcptch_add_styles' ); |
| 90 | |
| 91 | if ( '1' == $gglcptch_options['login_form'] ) { |
| 92 | add_action( 'login_form', 'gglcptch_login_display' ); |
| 93 | if ( ! $gglcptch_ip_in_whitelist ) |
| 94 | add_action( 'authenticate', 'gglcptch_login_check', 21, 1 ); |
| 95 | } |
| 96 | |
| 97 | if ( '1' == $gglcptch_options['reset_pwd_form'] ) { |
| 98 | add_action( 'lostpassword_form', 'gglcptch_login_display' ); |
| 99 | if ( ! $gglcptch_ip_in_whitelist ) |
| 100 | add_action( 'allow_password_reset', 'gglcptch_lostpassword_check' ); |
| 101 | } |
| 102 | |
| 103 | if ( '1' == $gglcptch_options['registration_form'] ) { |
| 104 | if ( ! is_multisite() ) { |
| 105 | add_action( 'register_form', 'gglcptch_login_display', 99 ); |
| 106 | if ( ! $gglcptch_ip_in_whitelist ) |
| 107 | add_action( 'registration_errors', 'gglcptch_lostpassword_check' ); |
| 108 | } else { |
| 109 | add_action( 'signup_extra_fields', 'gglcptch_signup_display' ); |
| 110 | add_action( 'signup_blogform', 'gglcptch_signup_display' ); |
| 111 | if ( ! $gglcptch_ip_in_whitelist ) |
| 112 | add_filter( 'wpmu_validate_user_signup', 'gglcptch_signup_check' ); |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | if ( '1' == $gglcptch_options['comments_form'] ) { |
| 118 | add_action( 'comment_form_after_fields', 'gglcptch_commentform_display' ); |
| 119 | add_action( 'comment_form_logged_in_after', 'gglcptch_commentform_display' ); |
| 120 | if ( ! $gglcptch_ip_in_whitelist ) |
| 121 | add_action( 'pre_comment_on_post', 'gglcptch_commentform_check' ); |
| 122 | } |
| 123 | |
| 124 | if ( '1' == $gglcptch_options['contact_form'] ) { |
| 125 | add_filter( 'cntctfrm_display_captcha', 'gglcptch_cf_display', 10, 2 ); |
| 126 | if ( ! $gglcptch_ip_in_whitelist ) |
| 127 | add_filter( 'cntctfrm_check_form', 'gglcptch_recaptcha_check' ); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Activation plugin function |
| 135 | */ |
| 136 | if ( ! function_exists( 'gglcptch_plugin_activate' ) ) { |
| 137 | function gglcptch_plugin_activate( $networkwide ) { |
| 138 | global $wpdb; |
| 139 | /* Activation function for network, check if it is a network activation - if so, run the activation function for each blog id */ |
| 140 | if ( is_multisite() ) { |
| 141 | switch_to_blog( 1 ); |
| 142 | register_uninstall_hook( __FILE__, 'gglcptch_delete_options' ); |
| 143 | restore_current_blog(); |
| 144 | } else { |
| 145 | register_uninstall_hook( __FILE__, 'gglcptch_delete_options' ); |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | if ( ! function_exists( 'gglcptch_admin_init' ) ) { |
| 151 | function gglcptch_admin_init() { |
| 152 | global $bws_plugin_info, $gglcptch_plugin_info, $bws_shortcode_list; |
| 153 | |
| 154 | if ( empty( $bws_plugin_info ) ) |
| 155 | $bws_plugin_info = array( 'id' => '109', 'version' => $gglcptch_plugin_info["Version"] ); |
| 156 | |
| 157 | /* add google captcha to global $bws_shortcode_list */ |
| 158 | $bws_shortcode_list['gglcptch'] = array( 'name' => 'Google Captcha (reCAPTCHA)' ); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /* Add google captcha styles */ |
| 163 | if ( ! function_exists( 'gglcptch_add_admin_script_styles' ) ) { |
| 164 | function gglcptch_add_admin_script_styles() { |
| 165 | global $gglcptch_plugin_info; |
| 166 | |
| 167 | /* css for displaing an icon */ |
| 168 | wp_enqueue_style( 'gglcptch_admin_page_stylesheet', plugins_url( 'css/admin_page.css', __FILE__ ) ); |
| 169 | |
| 170 | if ( isset( $_REQUEST['page'] ) && ( 'google-captcha.php' == $_REQUEST['page'] || 'google-captcha-whitelist.php' == $_REQUEST['page'] ) ) { |
| 171 | wp_enqueue_style( 'gglcptch_stylesheet', plugins_url( 'css/style.css', __FILE__ ), array(), $gglcptch_plugin_info['Version'] ); |
| 172 | wp_enqueue_script( 'gglcptch_admin_script', plugins_url( 'js/admin_script.js', __FILE__ ), array( 'jquery' ), $gglcptch_plugin_info['Version'] ); |
| 173 | |
| 174 | bws_enqueue_settings_scripts(); |
| 175 | bws_plugins_include_codemirror(); |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | /* Add google captcha admin styles for test key */ |
| 181 | if ( ! function_exists( 'gglcptch_admin_footer' ) ) { |
| 182 | function gglcptch_admin_footer() { |
| 183 | global $gglcptch_plugin_info, $gglcptch_options; |
| 184 | if ( isset( $_REQUEST['page'] ) && 'google-captcha.php' == $_REQUEST['page'] ) { |
| 185 | |
| 186 | /* update $gglcptch_options */ |
| 187 | register_gglcptch_settings(); |
| 188 | |
| 189 | /* for gglcptch test key */ |
| 190 | if ( isset( $gglcptch_options['recaptcha_version'] ) && in_array( $gglcptch_options['recaptcha_version'], array( 'v2', 'invisible' ) ) ) { |
| 191 | $api_url = "https://www.google.com/recaptcha/api.js"; |
| 192 | $deps = array( 'gglcptch_pre_api' ); |
| 193 | } else { |
| 194 | $api_url = "https://www.google.com/recaptcha/api/js/recaptcha_ajax.js"; |
| 195 | $deps = array(); |
| 196 | } |
| 197 | wp_register_script( 'gglcptch_api', $api_url, $deps, $gglcptch_plugin_info['Version'], true ); |
| 198 | gglcptch_add_scripts(); |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Remove dublicate scripts |
| 205 | */ |
| 206 | if ( ! function_exists( 'gglcptch_remove_dublicate_scripts' ) ) { |
| 207 | function gglcptch_remove_dublicate_scripts() { |
| 208 | global $wp_scripts; |
| 209 | |
| 210 | if ( ! is_object( $wp_scripts ) || empty( $wp_scripts ) ) |
| 211 | return false; |
| 212 | |
| 213 | foreach ( $wp_scripts->registered as $script_name => $args ) { |
| 214 | if ( preg_match( "|google\.com/recaptcha/api\.js|", $args->src ) && 'gglcptch_api' != $script_name ) |
| 215 | /* remove a previously enqueued script */ |
| 216 | wp_dequeue_script( $script_name ); |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Add google captcha styles |
| 223 | */ |
| 224 | if ( ! function_exists( 'gglcptch_add_styles' ) ) { |
| 225 | function gglcptch_add_styles() { |
| 226 | global $gglcptch_plugin_info, $gglcptch_options; |
| 227 | wp_enqueue_style( 'gglcptch', plugins_url( 'css/gglcptch.css', __FILE__ ), array(), $gglcptch_plugin_info["Version"] ); |
| 228 | |
| 229 | if ( defined( 'BWS_ENQUEUE_ALL_SCRIPTS' ) && BWS_ENQUEUE_ALL_SCRIPTS ) { |
| 230 | if ( ! wp_script_is( 'gglcptch_api', 'registered' ) ) { |
| 231 | if ( isset( $gglcptch_options['recaptcha_version'] ) && in_array( $gglcptch_options['recaptcha_version'], array( 'v2', 'invisible' ) ) ) { |
| 232 | $api_url = "https://www.google.com/recaptcha/api.js?onload=gglcptch_onload_callback&render=explicit"; |
| 233 | $deps = array( 'gglcptch_pre_api' ); |
| 234 | } else { |
| 235 | $api_url = "https://www.google.com/recaptcha/api/js/recaptcha_ajax.js"; |
| 236 | $deps = array(); |
| 237 | } |
| 238 | |
| 239 | wp_register_script( 'gglcptch_api', $api_url, $deps, $gglcptch_plugin_info["Version"], true ); |
| 240 | add_action( 'wp_footer', 'gglcptch_add_scripts' ); |
| 241 | if ( |
| 242 | '1' == $gglcptch_options['login_form'] || |
| 243 | '1' == $gglcptch_options['reset_pwd_form'] || |
| 244 | '1' == $gglcptch_options['registration_form'] |
| 245 | ) |
| 246 | add_action( 'login_footer', 'gglcptch_add_scripts' ); |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * Add google captcha js scripts |
| 254 | */ |
| 255 | if ( ! function_exists( 'gglcptch_add_scripts' ) ) { |
| 256 | function gglcptch_add_scripts() { |
| 257 | global $gglcptch_options, $gglcptch_plugin_info; |
| 258 | |
| 259 | if ( empty( $gglcptch_options ) ) |
| 260 | register_gglcptch_settings(); |
| 261 | |
| 262 | if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v1' != $gglcptch_options['recaptcha_version'] ) { |
| 263 | gglcptch_remove_dublicate_scripts(); |
| 264 | wp_enqueue_script( 'gglcptch_pre_api', plugins_url( 'js/pre-api-script.js', __FILE__ ), array( 'jquery'), $gglcptch_plugin_info['Version'], true ); |
| 265 | wp_localize_script( 'gglcptch_pre_api', 'gglcptch_pre', array( |
| 266 | 'messages' => array( |
| 267 | 'in_progress' => __( 'Please wait until Google reCAPTCHA is loaded.', 'google-captcha' ), |
| 268 | 'timeout' => __( 'Failed to load Google reCAPTCHA. Please check your internet connection and reload this page.', 'google-captcha' ) |
| 269 | ) |
| 270 | ) ); |
| 271 | } |
| 272 | |
| 273 | wp_enqueue_script( 'gglcptch_script', plugins_url( 'js/script.js', __FILE__ ), array( 'jquery', 'gglcptch_api' ), $gglcptch_plugin_info["Version"], true ); |
| 274 | |
| 275 | $version = $gglcptch_options['recaptcha_version'] == 'v2' ? '_v2' : ''; |
| 276 | |
| 277 | /* forms to exclude from ajax check */ |
| 278 | $excluded_forms = apply_filters( 'gglcptch_exclude_forms', '' ); |
| 279 | if ( ! empty( $excluded_forms ) && is_array( $excluded_forms ) ) { |
| 280 | $excluded_forms = implode( ', ', $excluded_forms ); |
| 281 | } |
| 282 | |
| 283 | wp_localize_script( 'gglcptch_script', 'gglcptch', array( |
| 284 | 'options' => array( |
| 285 | 'version' => $gglcptch_options['recaptcha_version'], |
| 286 | 'sitekey' => $gglcptch_options['public_key'], |
| 287 | 'theme' => $gglcptch_options[ 'theme' . $version ], |
| 288 | 'error' => sprintf( '<strong>%s</strong>: %s', __( 'Warning', 'google-captcha' ), gglcptch_get_message( 'multiple_blocks' ) ) |
| 289 | ), |
| 290 | 'vars' => array( |
| 291 | 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 292 | 'error_msg' => sprintf( '%s: %s', __( 'Error', 'google-captcha' ), gglcptch_get_message() ), |
| 293 | 'nonce' => wp_create_nonce( 'gglcptch_recaptcha_nonce' ), |
| 294 | 'visibility' => ( 'login_footer' == current_filter() ) ? true : false, |
| 295 | 'excluded_forms' => ! empty( $excluded_forms ) ? ', ' . $excluded_forms : '' |
| 296 | ) |
| 297 | ) ); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | if ( ! function_exists( 'gglcptch_pagination_callback' ) ) { |
| 302 | function gglcptch_pagination_callback( $content ) { |
| 303 | $content .= "if ( typeof Recaptcha != 'undefined' || typeof grecaptcha != 'undefined' ) { gglcptch.prepare(); }"; |
| 304 | return $content; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * Add the "async" attribute to our registered script. |
| 310 | */ |
| 311 | if ( ! function_exists( 'gglcptch_add_async_attribute' ) ) { |
| 312 | function gglcptch_add_async_attribute( $tag, $handle ) { |
| 313 | if ( 'gglcptch_api' == $handle ) |
| 314 | $tag = str_replace( ' src', ' data-cfasync="false" async="async" defer="defer" src', $tag ); |
| 315 | return $tag; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | if ( ! function_exists( 'gglcptch_create_table' ) ) { |
| 320 | function gglcptch_create_table() { |
| 321 | global $wpdb; |
| 322 | require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 323 | $whitelist_exist = $wpdb->query( "SHOW TABLES LIKE '{$wpdb->prefix}gglcptch_whitelist';" ); |
| 324 | if ( ! $whitelist_exist ) { |
| 325 | $sql = "CREATE TABLE `{$wpdb->prefix}gglcptch_whitelist` ( |
| 326 | `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, |
| 327 | `ip` CHAR(31) NOT NULL, |
| 328 | `ip_from_int` BIGINT, |
| 329 | `ip_to_int` BIGINT, |
| 330 | `add_time` DATETIME, |
| 331 | PRIMARY KEY (`id`) |
| 332 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; |
| 333 | dbDelta( $sql ); |
| 334 | |
| 335 | /* add unique key */ |
| 336 | if ( 0 == $wpdb->query( "SHOW KEYS FROM `{$wpdb->prefix}gglcptch_whitelist` WHERE Key_name='ip'" ) ) |
| 337 | $wpdb->query( "ALTER TABLE `{$wpdb->prefix}gglcptch_whitelist` ADD UNIQUE(`ip`);" ); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | /* Google catpcha settings */ |
| 343 | if ( ! function_exists( 'register_gglcptch_settings' ) ) { |
| 344 | function register_gglcptch_settings() { |
| 345 | global $gglcptch_options, $bws_plugin_info, $gglcptch_plugin_info; |
| 346 | |
| 347 | $plugin_db_version = '0.1'; |
| 348 | |
| 349 | /* Install the option defaults */ |
| 350 | if ( ! get_option( 'gglcptch_options' ) ) |
| 351 | add_option( 'gglcptch_options', gglcptch_get_default_options() ); |
| 352 | /* Get options from the database */ |
| 353 | $gglcptch_options = get_option( 'gglcptch_options' ); |
| 354 | |
| 355 | /* Array merge incase this version has added new options */ |
| 356 | if ( ! isset( $gglcptch_options['plugin_option_version'] ) || $gglcptch_options['plugin_option_version'] != $gglcptch_plugin_info["Version"] ) { |
| 357 | $gglcptch_options = array_merge( gglcptch_get_default_options(), $gglcptch_options ); |
| 358 | $gglcptch_options['plugin_option_version'] = $gglcptch_plugin_info["Version"]; |
| 359 | /* show pro features */ |
| 360 | $gglcptch_options['hide_premium_options'] = array(); |
| 361 | |
| 362 | if ( is_multisite() ) { |
| 363 | switch_to_blog( 1 ); |
| 364 | register_uninstall_hook( __FILE__, 'gglcptch_delete_options' ); |
| 365 | restore_current_blog(); |
| 366 | } else { |
| 367 | register_uninstall_hook( __FILE__, 'gglcptch_delete_options' ); |
| 368 | } |
| 369 | update_option( 'gglcptch_options', $gglcptch_options ); |
| 370 | } |
| 371 | /* Update tables when update plugin and tables changes*/ |
| 372 | if ( |
| 373 | ! isset( $gglcptch_options['plugin_db_version'] ) || |
| 374 | ( isset( $gglcptch_options['plugin_db_version'] ) && $gglcptch_options['plugin_db_version'] != $plugin_db_version ) |
| 375 | ) { |
| 376 | if ( ! isset( $gglcptch_options['plugin_db_version'] ) ) { |
| 377 | gglcptch_create_table(); |
| 378 | } |
| 379 | $gglcptch_options['plugin_db_version'] = $plugin_db_version; |
| 380 | update_option( 'gglcptch_options', $gglcptch_options ); |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | if ( ! function_exists( 'gglcptch_get_default_options' ) ) { |
| 386 | function gglcptch_get_default_options() { |
| 387 | global $gglcptch_plugin_info; |
| 388 | |
| 389 | $default_options = array( |
| 390 | 'whitelist_message' => __( 'You are in the whitelist', 'google-captcha' ), |
| 391 | 'public_key' => '', |
| 392 | 'private_key' => '', |
| 393 | 'login_form' => '1', |
| 394 | 'registration_form' => '1', |
| 395 | 'reset_pwd_form' => '1', |
| 396 | 'comments_form' => '1', |
| 397 | 'contact_form' => '0', |
| 398 | 'theme' => 'red', |
| 399 | 'theme_v2' => 'light', |
| 400 | 'recaptcha_version' => 'v2', |
| 401 | 'plugin_option_version' => $gglcptch_plugin_info["Version"], |
| 402 | 'first_install' => strtotime( "now" ), |
| 403 | 'display_settings_notice' => 1, |
| 404 | 'suggest_feature_banner' => 1, |
| 405 | ); |
| 406 | |
| 407 | if ( function_exists( 'get_editable_roles' ) ) { |
| 408 | foreach ( get_editable_roles() as $role => $fields ) { |
| 409 | $default_options[ $role ] = '0'; |
| 410 | } |
| 411 | } |
| 412 | return $default_options; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | if ( ! function_exists( 'gglcptch_plugin_status' ) ) { |
| 417 | function gglcptch_plugin_status( $plugins, $all_plugins, $is_network ) { |
| 418 | $result = array( |
| 419 | 'status' => '', |
| 420 | 'plugin' => '', |
| 421 | 'plugin_info' => array(), |
| 422 | ); |
| 423 | foreach ( (array)$plugins as $plugin ) { |
| 424 | if ( array_key_exists( $plugin, $all_plugins ) ) { |
| 425 | if ( |
| 426 | ( $is_network && is_plugin_active_for_network( $plugin ) ) || |
| 427 | ( ! $is_network && is_plugin_active( $plugin ) ) |
| 428 | ) { |
| 429 | $result['status'] = 'actived'; |
| 430 | $result['plugin'] = $plugin; |
| 431 | $result['plugin_info'] = $all_plugins[$plugin]; |
| 432 | break; |
| 433 | } else { |
| 434 | $result['status'] = 'deactivated'; |
| 435 | $result['plugin'] = $plugin; |
| 436 | $result['plugin_info'] = $all_plugins[$plugin]; |
| 437 | } |
| 438 | |
| 439 | } |
| 440 | } |
| 441 | if ( empty( $result['status'] ) ) |
| 442 | $result['status'] = 'not_installed'; |
| 443 | return $result; |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | if ( ! function_exists( 'gglcptch_whitelisted_ip' ) ) { |
| 448 | function gglcptch_whitelisted_ip() { |
| 449 | global $wpdb, $gglcptch_options; |
| 450 | $checked = false; |
| 451 | if ( empty( $gglcptch_options ) ) |
| 452 | $gglcptch_options = get_option( 'gglcptch_options' ); |
| 453 | $whitelist_exist = $wpdb->query( "SHOW TABLES LIKE '{$wpdb->prefix}gglcptch_whitelist'" ); |
| 454 | if ( 1 === $whitelist_exist ) { |
| 455 | $ip = ''; |
| 456 | if ( isset( $_SERVER ) ) { |
| 457 | $server_vars = array( 'HTTP_X_REAL_IP', 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'REMOTE_ADDR' ); |
| 458 | foreach( $server_vars as $var ) { |
| 459 | if ( isset( $_SERVER[ $var ] ) && ! empty( $_SERVER[ $var ] ) ) { |
| 460 | if ( filter_var( $_SERVER[ $var ], FILTER_VALIDATE_IP ) ) { |
| 461 | $ip = $_SERVER[ $var ]; |
| 462 | break; |
| 463 | } else { /* if proxy */ |
| 464 | $ip_array = explode( ',', $_SERVER[ $var ] ); |
| 465 | if ( is_array( $ip_array ) && ! empty( $ip_array ) && filter_var( $ip_array[0], FILTER_VALIDATE_IP ) ) { |
| 466 | $ip = $ip_array[0]; |
| 467 | break; |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | if ( ! empty( $ip ) ) { |
| 475 | $ip_int = sprintf( '%u', ip2long( $ip ) ); |
| 476 | $result = $wpdb->get_var( |
| 477 | "SELECT `id` |
| 478 | FROM `{$wpdb->prefix}gglcptch_whitelist` |
| 479 | WHERE ( `ip_from_int` <= {$ip_int} AND `ip_to_int` >= {$ip_int} ) OR `ip` LIKE '{$ip}' LIMIT 1;" |
| 480 | ); |
| 481 | $checked = is_null( $result ) || ! $result ? false : true; |
| 482 | } else { |
| 483 | $checked = false; |
| 484 | } |
| 485 | } |
| 486 | return $checked; |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | /* Display settings page */ |
| 491 | if ( ! function_exists( 'gglcptch_add_settings_page' ) ) { |
| 492 | function gglcptch_add_settings_page() { |
| 493 | global $gglcptch_plugin_info; |
| 494 | require_once( dirname( __FILE__ ) . '/includes/pro_banners.php' ); ?> |
| 495 | <div class="wrap"> |
| 496 | <?php if ( 'google-captcha.php' == $_GET['page'] ) { |
| 497 | require_once( dirname( __FILE__ ) . '/includes/class-gglcptch-settings-tabs.php' ); |
| 498 | $page = new Gglcptch_Settings_Tabs( plugin_basename( __FILE__ ) ); ?> |
| 499 | <h1><?php _e( 'Google Captcha Settings', 'google-captcha' ); ?></h1> |
| 500 | <?php $page->display_content(); |
| 501 | } else { |
| 502 | require_once( dirname( __FILE__ ) . '/includes/whitelist.php' ); |
| 503 | $page = new Gglcptch_Whitelist( plugin_basename( __FILE__ ) ); |
| 504 | if ( is_object( $page ) ) |
| 505 | $page->display_content(); |
| 506 | |
| 507 | bws_plugin_reviews_block( $gglcptch_plugin_info['Name'], 'google-captcha' ); |
| 508 | } ?> |
| 509 | </div> |
| 510 | <?php } |
| 511 | } |
| 512 | |
| 513 | /* Checking current user role */ |
| 514 | if ( ! function_exists( 'gglcptch_check_role' ) ) { |
| 515 | function gglcptch_check_role() { |
| 516 | global $current_user, $gglcptch_options; |
| 517 | |
| 518 | if ( ! is_user_logged_in() ) |
| 519 | return false; |
| 520 | |
| 521 | if ( ! empty( $current_user->roles[0] ) ) { |
| 522 | $role = $current_user->roles[0]; |
| 523 | if ( empty( $gglcptch_options ) ) |
| 524 | register_gglcptch_settings(); |
| 525 | return isset( $gglcptch_options[ $role ] ) && '1' == $gglcptch_options[ $role ] ? true : false; |
| 526 | } else |
| 527 | return false; |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | /* Display google captcha via shortcode */ |
| 532 | if ( ! function_exists( 'gglcptch_display' ) ) { |
| 533 | function gglcptch_display( $content = false ) { |
| 534 | global $gglcptch_options, $gglcptch_count, $gglcptch_ip_in_whitelist, $gglcptch_plugin_info; |
| 535 | |
| 536 | if ( empty( $gglcptch_options ) ) |
| 537 | register_gglcptch_settings(); |
| 538 | |
| 539 | if ( ! isset( $gglcptch_ip_in_whitelist ) ) |
| 540 | $gglcptch_ip_in_whitelist = gglcptch_whitelisted_ip(); |
| 541 | |
| 542 | if ( ! $gglcptch_ip_in_whitelist ) { |
| 543 | |
| 544 | if ( ! $gglcptch_count ) |
| 545 | $gglcptch_count = 1; |
| 546 | |
| 547 | $publickey = $gglcptch_options['public_key']; |
| 548 | $privatekey = $gglcptch_options['private_key']; |
| 549 | |
| 550 | $content .= '<div class="gglcptch gglcptch_' . $gglcptch_options['recaptcha_version'] . '">'; |
| 551 | if ( ! $privatekey || ! $publickey ) { |
| 552 | if ( current_user_can( 'manage_options' ) ) { |
| 553 | $content .= sprintf( |
| 554 | '<strong>%s <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s <a target="_blank" href="%s">%s</a>.</strong>', |
| 555 | __( 'To use Google Captcha you must get the keys from', 'google-captcha' ), |
| 556 | __( 'here', 'google-captcha' ), |
| 557 | __( 'and enter them on the', 'google-captcha' ), |
| 558 | admin_url( '/admin.php?page=google-captcha.php' ), |
| 559 | __( 'plugin setting page', 'google-captcha' ) |
| 560 | ); |
| 561 | } |
| 562 | $content .= '</div>'; |
| 563 | $gglcptch_count++; |
| 564 | return $content; |
| 565 | } |
| 566 | |
| 567 | /* generating random id value in case of getting content with pagination plugin for not getting duplicate id values */ |
| 568 | $id = mt_rand(); |
| 569 | if ( isset( $gglcptch_options['recaptcha_version'] ) && in_array( $gglcptch_options['recaptcha_version'], array( 'v2', 'invisible' ) ) ) { |
| 570 | $content .= '<div id="gglcptch_recaptcha_' . $id . '" class="gglcptch_recaptcha"></div> |
| 571 | <noscript> |
| 572 | <div style="width: 302px;"> |
| 573 | <div style="width: 302px; height: 422px; position: relative;"> |
| 574 | <div style="width: 302px; height: 422px; position: absolute;"> |
| 575 | <iframe src="https://www.google.com/recaptcha/api/fallback?k=' . $publickey . '" frameborder="0" scrolling="no" style="width: 302px; height:422px; border-style: none;"></iframe> |
| 576 | </div> |
| 577 | </div> |
| 578 | <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;"> |
| 579 | <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> |
| 580 | </div> |
| 581 | </div> |
| 582 | </noscript>'; |
| 583 | $api_url = "https://www.google.com/recaptcha/api.js?onload=gglcptch_onload_callback&render=explicit"; |
| 584 | $deps = array( 'gglcptch_pre_api' ); |
| 585 | } else { |
| 586 | require_once( 'lib/recaptchalib.php' ); |
| 587 | $content .= '<div id="gglcptch_recaptcha_' . $id . '" class="gglcptch_recaptcha"></div>'; |
| 588 | $content .= gglcptch_recaptcha_get_html( $publickey, null, is_ssl() ); |
| 589 | $api_url = "https://www.google.com/recaptcha/api/js/recaptcha_ajax.js"; |
| 590 | $deps = array(); |
| 591 | } |
| 592 | $content .= '</div>'; |
| 593 | $gglcptch_count++; |
| 594 | |
| 595 | /* register reCAPTCHA script */ |
| 596 | if ( ! wp_script_is( 'gglcptch_api', 'registered' ) ) { |
| 597 | wp_register_script( 'gglcptch_api', $api_url, $deps, $gglcptch_plugin_info['Version'], true ); |
| 598 | add_action( 'wp_footer', 'gglcptch_add_scripts' ); |
| 599 | if ( |
| 600 | '1' == $gglcptch_options['login_form'] || |
| 601 | '1' == $gglcptch_options['reset_pwd_form'] || |
| 602 | '1' == $gglcptch_options['registration_form'] |
| 603 | ) |
| 604 | add_action( 'login_footer', 'gglcptch_add_scripts' ); |
| 605 | } |
| 606 | } else { |
| 607 | if ( ! empty( $gglcptch_options['whitelist_message'] ) ) |
| 608 | $content .= '<label class="gglcptch_whitelist_message">' . $gglcptch_options['whitelist_message'] . '</label>'; |
| 609 | } |
| 610 | |
| 611 | return $content; |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | if ( ! function_exists( 'gglcptch_get_response' ) ) { |
| 616 | function gglcptch_get_response( $privatekey, $remote_ip ) { |
| 617 | $args = array( |
| 618 | 'body' => array( |
| 619 | 'secret' => $privatekey, |
| 620 | 'response' => stripslashes( esc_html( $_POST["g-recaptcha-response"] ) ), |
| 621 | 'remoteip' => $remote_ip, |
| 622 | ), |
| 623 | 'sslverify' => false |
| 624 | ); |
| 625 | $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $args ); |
| 626 | return json_decode( wp_remote_retrieve_body( $resp ), true ); |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | /* Check google captcha */ |
| 631 | if ( ! function_exists( 'gglcptch_check' ) ) { |
| 632 | function gglcptch_check( $debug = false ) { |
| 633 | global $gglcptch_options; |
| 634 | |
| 635 | if ( empty( $gglcptch_options ) ) |
| 636 | register_gglcptch_settings(); |
| 637 | |
| 638 | $publickey = $gglcptch_options['public_key']; |
| 639 | $privatekey = $gglcptch_options['private_key']; |
| 640 | |
| 641 | if ( ! $privatekey || ! $publickey ) { |
| 642 | return array( |
| 643 | 'response' => false, |
| 644 | 'reason' => 'ERROR_NO_KEYS' |
| 645 | ); |
| 646 | } |
| 647 | |
| 648 | $gglcptch_remote_addr = filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP ); |
| 649 | |
| 650 | if ( |
| 651 | isset( $gglcptch_options['recaptcha_version'] ) && |
| 652 | in_array( $gglcptch_options['recaptcha_version'], array( 'v2', 'invisible' ) ) |
| 653 | ) { |
| 654 | if ( ! isset( $_POST["g-recaptcha-response"] ) ) { |
| 655 | return array( |
| 656 | 'response' => false, |
| 657 | 'reason' => 'RECAPTCHA_NO_RESPONSE' |
| 658 | ); |
| 659 | } elseif ( empty( $_POST["g-recaptcha-response"] ) ) { |
| 660 | return array( |
| 661 | 'response' => false, |
| 662 | 'reason' => 'RECAPTCHA_EMPTY_RESPONSE' |
| 663 | ); |
| 664 | } |
| 665 | |
| 666 | $response = gglcptch_get_response( $privatekey, $gglcptch_remote_addr ); |
| 667 | |
| 668 | if ( isset( $response['success'] ) && !! $response['success'] ) { |
| 669 | return array( |
| 670 | 'response' => true, |
| 671 | 'reason' => '' |
| 672 | ); |
| 673 | } else { |
| 674 | return array( |
| 675 | 'response' => false, |
| 676 | 'reason' => $debug ? $response['error-codes'] : 'VERIFICATION_FAILED' |
| 677 | ); |
| 678 | } |
| 679 | } else { |
| 680 | $gglcptch_recaptcha_challenge_field = $gglcptch_recaptcha_response_field = ''; |
| 681 | |
| 682 | if ( ! isset( $_POST['recaptcha_challenge_field'] ) && ! isset( $_POST['recaptcha_response_field'] ) ) { |
| 683 | return array( |
| 684 | 'response' => false, |
| 685 | 'reason' => 'RECAPTCHA_NO_RESPONSE' |
| 686 | ); |
| 687 | } elseif ( ! empty( $_POST['recaptcha_challenge_field'] ) && empty( $_POST['recaptcha_response_field'] ) ) { |
| 688 | return array( |
| 689 | 'response' => false, |
| 690 | 'reason' => 'RECAPTCHA_EMPTY_RESPONSE' |
| 691 | ); |
| 692 | } else { |
| 693 | $gglcptch_recaptcha_challenge_field = stripslashes( esc_html( $_POST['recaptcha_challenge_field'] ) ); |
| 694 | $gglcptch_recaptcha_response_field = stripslashes( esc_html( $_POST['recaptcha_response_field'] ) ); |
| 695 | } |
| 696 | |
| 697 | require_once( 'lib/recaptchalib.php' ); |
| 698 | $response = gglcptch_recaptcha_check_answer( $privatekey, $gglcptch_remote_addr, $gglcptch_recaptcha_challenge_field, $gglcptch_recaptcha_response_field ); |
| 699 | |
| 700 | if ( ! $response->is_valid ) { |
| 701 | return array( |
| 702 | 'response' => false, |
| 703 | 'reason' => $debug ? $response->error : 'VERIFICATION_FAILED' |
| 704 | ); |
| 705 | } else { |
| 706 | return array( |
| 707 | 'response' => true, |
| 708 | 'reason' => '' |
| 709 | ); |
| 710 | } |
| 711 | } |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | /* Add google captcha to the login form */ |
| 716 | if ( ! function_exists( 'gglcptch_login_display' ) ) { |
| 717 | function gglcptch_login_display() { |
| 718 | global $gglcptch_options; |
| 719 | if ( isset( $gglcptch_options['recaptcha_version'] ) && in_array( $gglcptch_options['recaptcha_version'], array( 'v1', 'v2' ) ) ) { |
| 720 | if ( 'v2' == $gglcptch_options['recaptcha_version'] ) { |
| 721 | $from_width = 302; |
| 722 | } else { |
| 723 | $from_width = 320; |
| 724 | if ( 'clean' == $gglcptch_options['theme'] ) |
| 725 | $from_width = 450; |
| 726 | } ?> |
| 727 | <style type="text/css" media="screen"> |
| 728 | .login-action-login #loginform, |
| 729 | .login-action-lostpassword #lostpasswordform, |
| 730 | .login-action-register #registerform { |
| 731 | width: <?php echo $from_width; ?>px !important; |
| 732 | } |
| 733 | #login_error, |
| 734 | .message { |
| 735 | width: <?php echo $from_width + 20; ?>px !important; |
| 736 | } |
| 737 | .login-action-login #loginform .gglcptch, |
| 738 | .login-action-lostpassword #lostpasswordform .gglcptch, |
| 739 | .login-action-register #registerform .gglcptch { |
| 740 | margin-bottom: 10px; |
| 741 | } |
| 742 | </style> |
| 743 | <?php } |
| 744 | echo gglcptch_display(); |
| 745 | return true; |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | /** |
| 750 | * Retrieve the message that corresponds to its message code |
| 751 | * @since 1.29 |
| 752 | * @param string $message_code used to switch the corresponding message |
| 753 | * @param boolean $echo 'false' is default. If 'false' - returns a message, if 'true' - first, echo a message and then return it. |
| 754 | * @return string $message Returned message. |
| 755 | */ |
| 756 | if ( ! function_exists( 'gglcptch_get_message' ) ) { |
| 757 | function gglcptch_get_message( $message_code = 'incorrect', $echo = false ) { |
| 758 | $message = ''; |
| 759 | |
| 760 | $messages = array( |
| 761 | /* custom error */ |
| 762 | 'RECAPTCHA_EMPTY_RESPONSE' => __( 'User response is missing.', 'google-captcha' ), |
| 763 | /* v1 error */ |
| 764 | 'invalid-site-private-key' => sprintf( |
| 765 | '<strong>%s</strong> <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s.', |
| 766 | __( 'Secret Key is invalid.', 'google-captcha' ), |
| 767 | __( 'Check your domain configurations', 'google-captcha' ), |
| 768 | __( 'and enter it again', 'google-captcha' ) |
| 769 | ), |
| 770 | /* v2 error */ |
| 771 | 'missing-input-secret' => __( 'Secret Key is missing.', 'google-captcha' ), |
| 772 | 'invalid-input-secret' => sprintf( |
| 773 | '<strong>%s</strong> <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s.', |
| 774 | __( 'Secret Key is invalid.', 'google-captcha' ), |
| 775 | __( 'Check your domain configurations', 'google-captcha' ), |
| 776 | __( 'and enter it again', 'google-captcha' ) |
| 777 | ), |
| 778 | 'incorrect-captcha-sol' => __( 'User response is invalid', 'google-captcha' ), |
| 779 | 'incorrect' => __( 'You have entered an incorrect reCAPTCHA value.', 'google-captcha' ), |
| 780 | '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' ) |
| 781 | ); |
| 782 | |
| 783 | if ( isset( $messages[ $message_code ] ) ) { |
| 784 | $message = $messages[ $message_code ]; |
| 785 | } else { |
| 786 | $message = $messages['incorrect']; |
| 787 | } |
| 788 | |
| 789 | if ( $echo ) |
| 790 | echo $message; |
| 791 | |
| 792 | return $message; |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | /* Check google captcha in login form */ |
| 797 | if ( ! function_exists( 'gglcptch_login_check' ) ) { |
| 798 | function gglcptch_login_check( $user ) { |
| 799 | |
| 800 | $result = gglcptch_check(); |
| 801 | |
| 802 | if ( ! $result['response'] ) { |
| 803 | if ( $result['reason'] == 'ERROR_NO_KEYS' ) { |
| 804 | return $user; |
| 805 | } |
| 806 | |
| 807 | $error_message = sprintf( '<strong>%s</strong>: %s', __( 'Error', 'google-captcha' ), gglcptch_get_message() ); |
| 808 | |
| 809 | if ( $result['reason'] == 'VERIFICATION_FAILED' ) { |
| 810 | wp_clear_auth_cookie(); |
| 811 | return new WP_Error( 'gglcptch_error', $error_message ); |
| 812 | } |
| 813 | |
| 814 | if ( isset( $_REQUEST['log'] ) && isset( $_REQUEST['pwd'] ) ) { |
| 815 | return new WP_Error( 'gglcptch_error', $error_message ); |
| 816 | } else { |
| 817 | return $user; |
| 818 | } |
| 819 | } else { |
| 820 | return $user; |
| 821 | } |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | /* Check google captcha in BWS Contact Form */ |
| 826 | if ( ! function_exists( 'gglcptch_recaptcha_check' ) ) { |
| 827 | function gglcptch_recaptcha_check( $allow = true ) { |
| 828 | |
| 829 | if ( ! $allow || is_string( $allow ) || is_wp_error( $allow ) ) { |
| 830 | return $allow; |
| 831 | } |
| 832 | |
| 833 | $result = gglcptch_check(); |
| 834 | |
| 835 | if ( $result['response'] || $result['reason'] == 'ERROR_NO_KEYS' ) |
| 836 | return true; |
| 837 | |
| 838 | $error_message = sprintf( '<strong>%s</strong>: %s', __( 'Error', 'google-captcha' ), gglcptch_get_message() ); |
| 839 | /** |
| 840 | * Function 'cntctfrm_handle_captcha_filters' was added in Contact Form 4.0.2 (Free and Pro) |
| 841 | * remove this condition. WP_Error is correct object for return. |
| 842 | * @deprecated since 1.26 |
| 843 | * @todo remove after 01.08.2017 |
| 844 | */ |
| 845 | if ( function_exists( 'cntctfrm_handle_captcha_filters' ) ) { |
| 846 | $allow = new WP_Error(); |
| 847 | $allow->add( 'gglcptch_error', $error_message ); |
| 848 | } else { |
| 849 | $allow = $error_message; |
| 850 | } |
| 851 | return $allow; |
| 852 | } |
| 853 | } |
| 854 | |
| 855 | /* Check google captcha in lostpassword form */ |
| 856 | if ( ! function_exists( 'gglcptch_lostpassword_check' ) ) { |
| 857 | function gglcptch_lostpassword_check( $allow ) { |
| 858 | |
| 859 | $result = gglcptch_check(); |
| 860 | |
| 861 | if ( $result['response'] || $result['reason'] == 'ERROR_NO_KEYS' ) |
| 862 | return $allow; |
| 863 | |
| 864 | if ( ! is_wp_error( $allow ) ) |
| 865 | $allow = new WP_Error(); |
| 866 | |
| 867 | $error_message = sprintf( '<strong>%s</strong>: %s', __( 'Error', 'google-captcha' ), gglcptch_get_message() ); |
| 868 | |
| 869 | $allow->add( 'gglcptch_error', $error_message ); |
| 870 | return $allow; |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | /* Add google captcha to the multisite login form */ |
| 875 | if ( ! function_exists( 'gglcptch_signup_display' ) ) { |
| 876 | function gglcptch_signup_display( $errors ) { |
| 877 | if ( $error_message = $errors->get_error_message( 'gglcptch_error' ) ) { |
| 878 | printf( '<p class="error gglcptch_error">%s</p>', $error_message ); |
| 879 | } |
| 880 | echo gglcptch_display(); |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | /* Check google captcha in multisite login form */ |
| 885 | if ( ! function_exists( 'gglcptch_signup_check' ) ) { |
| 886 | function gglcptch_signup_check( $result ) { |
| 887 | global $current_user; |
| 888 | |
| 889 | if ( is_admin() && ! defined( 'DOING_AJAX' ) && ! empty( $current_user->data->ID ) ) |
| 890 | return $result; |
| 891 | |
| 892 | $check_result = gglcptch_check(); |
| 893 | |
| 894 | if ( $check_result['response'] || $check_result['reason'] == 'ERROR_NO_KEYS' ) |
| 895 | return $result; |
| 896 | |
| 897 | $error_message = sprintf( '<strong>%s</strong>: %s', __( 'Error', 'google-captcha' ), gglcptch_get_message() ); |
| 898 | |
| 899 | $error = $result['errors']; |
| 900 | $error->add( 'gglcptch_error', $error_message ); |
| 901 | return $result; |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | /* Add google captcha to the comment form */ |
| 906 | if ( ! function_exists( 'gglcptch_commentform_display' ) ) { |
| 907 | function gglcptch_commentform_display() { |
| 908 | if ( gglcptch_check_role() ) |
| 909 | return; |
| 910 | echo gglcptch_display(); |
| 911 | return true; |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | /* Check JS enabled for comment form */ |
| 916 | if ( ! function_exists( 'gglcptch_commentform_check' ) ) { |
| 917 | function gglcptch_commentform_check() { |
| 918 | if ( gglcptch_check_role() ) |
| 919 | return; |
| 920 | |
| 921 | $result = gglcptch_check(); |
| 922 | |
| 923 | if ( $result['response'] || $result['reason'] == 'ERROR_NO_KEYS' ) |
| 924 | return; |
| 925 | |
| 926 | wp_die( sprintf( '<strong>%s</strong>: %s %s', __( 'Error', 'google-captcha' ), gglcptch_get_message(), __( 'Click the BACK button on your browser and try again.', 'google-captcha' ) ) ); |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | /* display google captcha in Contact form */ |
| 931 | if ( ! function_exists( 'gglcptch_cf_display' ) ) { |
| 932 | function gglcptch_cf_display( $content, $form_slug = "" ) { |
| 933 | return $content . gglcptch_display(); |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | /* Check Google Captcha in shortcode and contact form */ |
| 938 | if ( ! function_exists( 'gglcptch_captcha_check' ) ) { |
| 939 | function gglcptch_captcha_check() { |
| 940 | $result = gglcptch_check(); |
| 941 | echo $result['response'] ? "success" : "error"; |
| 942 | die(); |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | if ( ! function_exists( 'gglcptch_test_keys' ) ) { |
| 947 | function gglcptch_test_keys() { |
| 948 | global $gglcptch_ip_in_whitelist, $gglcptch_options; |
| 949 | if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'] , $_REQUEST['action'] ) ) { |
| 950 | header( 'Content-Type: text/html' ); |
| 951 | register_gglcptch_settings(); ?> |
| 952 | <p> |
| 953 | <?php if ( 'invisible' == $gglcptch_options['recaptcha_version'] ) |
| 954 | _e( 'Please submit "Test verification"', 'google-captcha' ); |
| 955 | else |
| 956 | _e( 'Please complete the captcha and submit "Test verification"', 'google-captcha' ); ?> |
| 957 | </p> |
| 958 | <?php $gglcptch_ip_in_whitelist = false; |
| 959 | echo gglcptch_display(); ?> |
| 960 | <p> |
| 961 | <input type="hidden" name="gglcptch_test_keys_verification-nonce" value="<?php echo wp_create_nonce( 'gglcptch_test_keys_verification' ); ?>" /> |
| 962 | <button id="gglcptch_test_keys_verification" name="action" class="button-primary" value="gglcptch_test_keys_verification"><?php _e( 'Test verification', 'google-captcha' ); ?></button> |
| 963 | </p> |
| 964 | <?php } |
| 965 | die(); |
| 966 | } |
| 967 | } |
| 968 | |
| 969 | if ( ! function_exists( 'gglcptch_test_keys_verification' ) ) { |
| 970 | function gglcptch_test_keys_verification() { |
| 971 | if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'] , $_REQUEST['action'] ) ) { |
| 972 | $result = gglcptch_check( true ); |
| 973 | |
| 974 | if ( ! $result['response'] ) { |
| 975 | if ( isset( $result['reason'] ) ) { |
| 976 | foreach ( (array)$result['reason'] as $error ) { ?> |
| 977 | <div class="error gglcptch-test-results"><p> |
| 978 | <?php gglcptch_get_message( $error, true ); ?> |
| 979 | </p></div> |
| 980 | <?php } |
| 981 | } |
| 982 | } else { ?> |
| 983 | <div class="updated gglcptch-test-results"><p><?php _e( 'The verification is successfully completed.','google-captcha' ); ?></p></div> |
| 984 | <?php $gglcptch_options = get_option( 'gglcptch_options' ); |
| 985 | $gglcptch_options['keys_verified'] = true; |
| 986 | unset( $gglcptch_options['need_keys_verified_check'] ); |
| 987 | update_option( 'gglcptch_options', $gglcptch_options ); |
| 988 | } |
| 989 | } |
| 990 | die(); |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | if ( ! function_exists( 'gglcptch_action_links' ) ) { |
| 995 | function gglcptch_action_links( $links, $file ) { |
| 996 | if ( ! is_network_admin() ) { |
| 997 | static $this_plugin; |
| 998 | if ( ! $this_plugin ) |
| 999 | $this_plugin = plugin_basename(__FILE__); |
| 1000 | |
| 1001 | if ( $file == $this_plugin ) { |
| 1002 | $settings_link = '<a href="admin.php?page=google-captcha.php">' . __( 'Settings', 'google-captcha' ) . '</a>'; |
| 1003 | array_unshift( $links, $settings_link ); |
| 1004 | } |
| 1005 | } |
| 1006 | return $links; |
| 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | if ( ! function_exists( 'gglcptch_shortcode_button_content' ) ) { |
| 1011 | function gglcptch_shortcode_button_content( $content ) { ?> |
| 1012 | <div id="gglcptch" style="display:none;"> |
| 1013 | <input class="bws_default_shortcode" type="hidden" name="default" value="[bws_google_captcha]" /> |
| 1014 | </div> |
| 1015 | <?php } |
| 1016 | } |
| 1017 | |
| 1018 | if ( ! function_exists( 'gglcptch_links' ) ) { |
| 1019 | function gglcptch_links( $links, $file ) { |
| 1020 | $base = plugin_basename( __FILE__ ); |
| 1021 | if ( $file == $base ) { |
| 1022 | if ( ! is_network_admin() ) |
| 1023 | $links[] = '<a href="admin.php?page=google-captcha.php">' . __( 'Settings', 'google-captcha' ) . '</a>'; |
| 1024 | $links[] = '<a href="https://support.bestwebsoft.com/hc/en-us/sections/200538719" target="_blank">' . __( 'FAQ', 'google-captcha' ) . '</a>'; |
| 1025 | $links[] = '<a href="https://support.bestwebsoft.com">' . __( 'Support', 'google-captcha' ) . '</a>'; |
| 1026 | } |
| 1027 | return $links; |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | if ( ! function_exists ( 'gglcptch_plugin_banner' ) ) { |
| 1032 | function gglcptch_plugin_banner() { |
| 1033 | global $hook_suffix, $gglcptch_plugin_info, $gglcptch_options; |
| 1034 | if ( 'plugins.php' == $hook_suffix ) { |
| 1035 | if ( empty( $gglcptch_options ) ) |
| 1036 | register_gglcptch_settings(); |
| 1037 | |
| 1038 | if ( empty( $gglcptch_options['public_key'] ) || empty( $gglcptch_options['private_key'] ) ) { ?> |
| 1039 | <div class="error"> |
| 1040 | <p> |
| 1041 | <?php printf( |
| 1042 | '<strong>%s <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s <a target="_blank" href="%s">%s</a>.</strong>', |
| 1043 | __( 'To use Google Captcha you must get the keys from', 'google-captcha' ), |
| 1044 | __ ( 'here', 'google-captcha' ), |
| 1045 | __ ( 'and enter them on the', 'google-captcha' ), |
| 1046 | admin_url( '/admin.php?page=google-captcha.php' ), |
| 1047 | __( 'plugin setting page', 'google-captcha' ) |
| 1048 | ); ?> |
| 1049 | </p> |
| 1050 | </div> |
| 1051 | <?php } |
| 1052 | if ( isset( $gglcptch_options['first_install'] ) && strtotime( '-1 week' ) > $gglcptch_options['first_install'] ) |
| 1053 | bws_plugin_banner( $gglcptch_plugin_info, 'gglcptch', 'google-captcha', '676d9558f9786ab41d7de35335cf5c4d', '109', '//ps.w.org/google-captcha/assets/icon-128x128.png' ); |
| 1054 | |
| 1055 | bws_plugin_banner_to_settings( $gglcptch_plugin_info, 'gglcptch_options', 'google-captcha', 'admin.php?page=google-captcha.php' ); |
| 1056 | } |
| 1057 | |
| 1058 | if ( isset( $_GET['page'] ) && 'google-captcha.php' == $_GET['page'] ) { |
| 1059 | bws_plugin_suggest_feature_banner( $gglcptch_plugin_info, 'gglcptch_options', 'google-captcha' ); |
| 1060 | } |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | /* add help tab */ |
| 1065 | if ( ! function_exists( 'gglcptch_add_tabs' ) ) { |
| 1066 | function gglcptch_add_tabs() { |
| 1067 | $screen = get_current_screen(); |
| 1068 | $args = array( |
| 1069 | 'id' => 'gglcptch', |
| 1070 | 'section' => '200538719' |
| 1071 | ); |
| 1072 | bws_help_tab( $screen, $args ); |
| 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | if ( ! function_exists( 'gglcptch_delete_options' ) ) { |
| 1077 | function gglcptch_delete_options() { |
| 1078 | if ( ! function_exists( 'get_plugins' ) ) |
| 1079 | require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 1080 | $all_plugins = get_plugins(); |
| 1081 | |
| 1082 | if ( ! array_key_exists( 'google-captcha-pro/google-captcha-pro.php', $all_plugins ) ) { |
| 1083 | global $wpdb; |
| 1084 | if ( function_exists( 'is_multisite' ) && is_multisite() ) { |
| 1085 | $old_blog = $wpdb->blogid; |
| 1086 | /* Get all blog ids */ |
| 1087 | $blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" ); |
| 1088 | foreach ( $blogids as $blog_id ) { |
| 1089 | switch_to_blog( $blog_id ); |
| 1090 | $wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}gglcptch_whitelist`;" ); |
| 1091 | delete_option( 'gglcptch_options' ); |
| 1092 | } |
| 1093 | switch_to_blog( $old_blog ); |
| 1094 | delete_site_option( 'gglcptch_options' ); |
| 1095 | } else { |
| 1096 | $wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}gglcptch_whitelist`;" ); |
| 1097 | delete_option( 'gglcptch_options' ); |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | require_once( dirname( __FILE__ ) . '/bws_menu/bws_include.php' ); |
| 1102 | bws_include_init( plugin_basename( __FILE__ ) ); |
| 1103 | bws_delete_plugin( plugin_basename( __FILE__ ) ); |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | register_activation_hook( __FILE__, 'gglcptch_plugin_activate' ); |
| 1108 | |
| 1109 | add_action( 'admin_menu', 'gglcptch_admin_menu' ); |
| 1110 | |
| 1111 | add_action( 'init', 'gglcptch_init' ); |
| 1112 | add_action( 'admin_init', 'gglcptch_admin_init' ); |
| 1113 | |
| 1114 | add_action( 'plugins_loaded', 'gglcptch_plugins_loaded' ); |
| 1115 | |
| 1116 | add_action( 'admin_enqueue_scripts', 'gglcptch_add_admin_script_styles' ); |
| 1117 | add_action( 'wp_enqueue_scripts', 'gglcptch_add_styles' ); |
| 1118 | add_filter( 'script_loader_tag', 'gglcptch_add_async_attribute', 10, 2 ); |
| 1119 | add_action( 'admin_footer', 'gglcptch_admin_footer' ); |
| 1120 | add_filter( 'pgntn_callback', 'gglcptch_pagination_callback' ); |
| 1121 | |
| 1122 | /* custom filter for bws button in tinyMCE */ |
| 1123 | add_filter( 'bws_shortcode_button_content', 'gglcptch_shortcode_button_content' ); |
| 1124 | add_shortcode( 'bws_google_captcha', 'gglcptch_display' ); |
| 1125 | add_filter( 'widget_text', 'do_shortcode' ); |
| 1126 | |
| 1127 | add_filter( 'plugin_action_links', 'gglcptch_action_links', 10, 2 ); |
| 1128 | add_filter( 'plugin_row_meta', 'gglcptch_links', 10, 2 ); |
| 1129 | |
| 1130 | add_action( 'admin_notices', 'gglcptch_plugin_banner' ); |
| 1131 | |
| 1132 | add_action( 'wp_ajax_gglcptch_captcha_check', 'gglcptch_captcha_check' ); |
| 1133 | add_action( 'wp_ajax_nopriv_gglcptch_captcha_check', 'gglcptch_captcha_check' ); |
| 1134 | add_action( 'wp_ajax_gglcptch-test-keys', 'gglcptch_test_keys' ); |
| 1135 | add_action( 'wp_ajax_gglcptch_test_keys_verification', 'gglcptch_test_keys_verification' ); |