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