/** * Output the reCAPTCHA HTML, use theme if specified * * @param $errors @since 1.1.0 * @return void */ public function add_recaptcha($errors = false) { if ($this->user_can_bypass()) { return ''; } $this->load_captcha_library(); if (!defined('BWP_CAPT_ADDED')) { // make sure we add only one recaptcha instance define('BWP_CAPT_ADDED', true); // captcha error can comes from $_GET variable or passed via // hooks' parameters. $captcha_error = ''; $extra_class = ''; if (!empty($_GET['cerror']) && 'incorrect-captcha-sol' == $_GET['cerror']) { $captcha_error = $_GET['cerror']; } else { if (is_wp_error($errors)) { // right now only registration errors are passed this way $captcha_error = $errors->get_error_message('reg-recaptcha-error'); $extra_class = ' error'; } } if ($this->_is_comment_spam()) { ?> <p class="bwp-capt-spam-identified"> <?php _e('Your comment was identified as spam, ' . 'please complete the CAPTCHA below:', $this->domain); ?> </p> <?php } do_action('bwp_capt_before_add_captcha'); ?> <style type="text/css"> /* this is to prevent the iframe from showing up in Chrome */ iframe[src="about:blank"] { display: none; } </style> <?php if ($this->options['select_theme'] != 'custom') { if (!empty($captcha_error)) { ?> <p class="recaptcha_only_if_incorrect_sol<?php echo $extra_class; ?> "> <?php echo $this->options['input_error']; ?> </p> <?php } ?> <script type="text/javascript"> var RecaptchaOptions = (typeof CustomRecaptchaOptions === 'undefined') ? { theme: '<?php echo $this->options['select_theme']; ?> ', lang: '<?php echo $this->options['select_lang']; ?> ', <?php if (!empty($this->options['input_tab'])) { ?> tabindex: <?php echo (int) $this->options['input_tab']; echo "\n"; } ?> } : CustomRecaptchaOptions; </script> <?php } else { bwp_capt_custom_theme_widget(); } if ('redirect' == $this->options['select_response'] && !is_admin()) { ?> <input type="hidden" name="error_redirect_to" value="<?php esc_attr_e($this->get_current_comment_page_link()); ?> " /> <?php } $use_ssl = is_ssl() ? true : false; if (!empty($this->options['input_pubkey'])) { echo recaptcha_get_html($this->options['input_pubkey'], $captcha_error, $use_ssl, $this->options['select_lang']); } else { if (current_user_can('manage_options')) { // if user is an admin show the actual error printf(__('To use reCAPTCHA you must get an API key from ' . '<a href="%1$s">%1$s</a>', $this->domain), 'https://www.google.com/recaptcha/admin/create'); } else { echo ''; } } } }
/** * Output the reCAPTCHA HTML, use theme if specified * @param $errors @since 1.1.0 */ function add_recaptcha($errors = false) { $this->load_captcha_library(); if (!defined('BWP_CAPT_ADDED')) { // make sure we add only one recaptcha instance define('BWP_CAPT_ADDED', true); // captcha error can comes from $_GET variable or passed via // hooks' parameters. $captcha_error = ''; $extra_class = ''; if (!empty($_GET['cerror']) && 'incorrect-captcha-sol' == $_GET['cerror']) { $captcha_error = $_GET['cerror']; } else { if (is_wp_error($errors)) { // right now only registration errors are passed this way $captcha_error = $errors->get_error_message('reg-recaptcha-error'); $extra_class = ' error'; } } if (!empty($_SESSION['bwp_capt_akismet_needed']) && 'yes' == $_SESSION['bwp_capt_akismet_needed']) { ?> <p class="bwp-capt-spam-identified"><?php _e('Your comment was identified as spam, please complete the CAPTCHA below:', 'bwp-recaptcha'); ?> </p> <?php } else { if (!empty($captcha_error)) { ?> <p class="recaptcha_only_if_incorrect_sol<?php echo $extra_class; ?> "><?php echo $this->options['input_error']; ?> </p> <?php } } do_action('bwp_capt_before_add_captcha'); if ($this->options['select_theme'] != 'custom') { ?> <script type="text/javascript"> var RecaptchaOptions = (typeof CustomRecaptchaOptions === 'undefined') ? { theme: '<?php echo $this->options['select_theme']; ?> ', lang: '<?php echo $this->options['select_lang']; ?> ', <?php if (!empty($this->options['input_tab'])) { ?> tabindex: <?php echo (int) $this->options['input_tab']; echo "\n"; } ?> } : CustomRecaptchaOptions; </script> <?php } else { bwp_capt_custom_theme_widget(); } if ('redirect' == $this->options['select_response'] && !is_admin()) { ?> <input type="hidden" name="error_redirect_to" value="<?php esc_attr_e($this->get_current_comment_page_link()); ?> " /> <?php } $use_ssl = isset($_SERVER['HTTPS']) && 'on' == $_SERVER['HTTPS'] ? true : false; if (!empty($this->options['input_pubkey'])) { echo recaptcha_get_html($this->options['input_pubkey'], $captcha_error, $use_ssl, $this->options['select_lang']); } else { if (current_user_can('manage_options')) { _e("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>", 'bwp-recaptcha'); } else { echo ''; } } } }