/** * Check the Captcha after Awesome Support tried to log the user in * * If the user login failed we simply return the existing error. * * @param WP_Error|WP_User $signon The result of the login attempt * * @return WP_Error|WP_User */ function recaptcha_check($signon) { if (is_wp_error($signon)) { return $signon; } if (!WP_reCaptcha::instance()->recaptcha_check()) { return new WP_Error('recaptcha_failed', __('The Captcha didn't verify', 'wp-recaptcha-integration')); } return $signon; }
/** * WooCommerce recaptcha Check * hooks into actions `woocommerce_process_login_errors` and `woocommerce_registration_errors` */ function login_errors($validation_error) { if (!WP_reCaptcha::instance()->recaptcha_check()) { $validation_error->add('captcha_error', __("<strong>Error:</strong> the Captcha didn’t verify.", 'wp-recaptcha-integration')); } return $validation_error; }
/** * Rendering the options page */ public function render_options_page() { $option_flavor = WP_reCaptcha::instance()->get_option('recaptcha_flavor'); ?> <div class="wrap flavor-<?php echo $option_flavor; ?> "><?php ?> <h2><?php /*icon*/ _e('Settings'); echo ' › '; _e('ReCaptcha', 'wp-recaptcha-integration'); ?> </h2><?php /* ?><p><?php _e( '...' , 'googlefont' ); ?></p><?php */ ?> <form action="options.php" method="post"><?php settings_fields('recaptcha_options'); do_settings_sections('recaptcha'); submit_button(null, 'primary', null, null, array('autocomplete' => 'off')); ?> </form><?php ?> </div><?php }
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /** * Autoload WPAA Classes * * @param string $classname */ function wp_recaptcha_integration_autoload($classname) { $class_path = dirname(__FILE__) . sprintf('/inc/class-%s.php', strtolower($classname)); if (file_exists($class_path)) { require_once $class_path; } } spl_autoload_register('wp_recaptcha_integration_autoload'); // disable 2.0.0 updates on php < 5.4 function wp_recaptcha_disable_updates($value) { if (version_compare(PHP_VERSION, '5.4', '<')) { $plugin_basename = plugin_basename(__FILE__); if (isset($value->response[$plugin_basename]) && version_compare($value->response[$plugin_basename]['new_version'], '2.0.0', '>=')) { unset($value->response[plugin_basename(__FILE__)]); } } return $value; } add_filter('site_transient_update_plugins', 'wp_recaptcha_disable_updates'); WP_reCaptcha::instance(); if (is_admin()) { WP_reCaptcha_Options::instance(); }
/** * @inheritdoc */ public function check() { $private_key = WP_reCaptcha::instance()->get_option('recaptcha_privatekey'); $user_response = isset($_REQUEST['g-recaptcha-response']) ? $_REQUEST['g-recaptcha-response'] : false; if ($user_response !== false) { if (!$this->_last_result) { $remote_ip = $_SERVER['REMOTE_ADDR']; $url = "https://www.google.com/recaptcha/api/siteverify?secret={$private_key}&response={$user_response}&remoteip={$remote_ip}"; $response = wp_remote_get($url); if (!is_wp_error($response)) { $response_data = wp_remote_retrieve_body($response); $this->_last_result = json_decode($response_data); } else { $this->_last_result = (object) array('success' => false, 'wp_error' => $response); } } do_action('wp_recaptcha_checked', $this->_last_result->success); return $this->_last_result->success; } return false; }
function recaptcha_validation_filter($result, $tag) { if (!WP_reCaptcha::instance()->is_required()) { return $result; } $tag = new WPCF7_Shortcode($tag); $name = $tag->name; if (!WP_reCaptcha::instance()->recaptcha_check()) { $message = wpcf7_get_message('wp_recaptcha_invalid'); if (!$message) { $message = __("The Captcha didn’t verify.", 'wp-recaptcha-integration'); } if (method_exists($result, 'invalidate')) { // since CF7 4.1 $result->invalidate($tag, $message); } else { $result['valid'] = false; $result['reason'][$name] = $message; } // var_dump(WP_reCaptcha::instance()->captcha_instance()->get_last_result()); } return $result; }
/** * @inheritdoc */ public function check() { if (!$this->_last_result) { $private_key = WP_reCaptcha::instance()->get_option('recaptcha_privatekey'); $this->_last_result = recaptcha_check_answer($private_key, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$this->_last_result->is_valid) { $this->last_error = $this->_last_result->error; } } do_action('wp_recaptcha_checked', $this->_last_result->is_valid); return $this->_last_result->is_valid; }
/** * Get plugin option by name. * * @return bool true if plugin is activated on network */ static function is_network_activated() { if (is_null(self::$_is_network_activated)) { if (!is_multisite()) { return false; } if (!function_exists('is_plugin_active_for_network')) { require_once ABSPATH . '/wp-admin/includes/plugin.php'; } self::$_is_network_activated = is_plugin_active_for_network(basename(dirname(__FILE__)) . '/' . basename(__FILE__)); } return self::$_is_network_activated; }
function field_recaptcha_pre_process($field_id, $user_value) { global $ninja_forms_processing; $plugin_settings = nf_get_settings(); $recaptcha_error = __("The Captcha didn’t verify.", 'wp-recaptcha-integration'); if (isset($plugin_settings['wp_recaptcha_invalid'])) { $recaptcha_error = $plugin_settings['wp_recaptcha_invalid']; } $field_row = ninja_forms_get_field_by_id($field_id); $field_data = $field_row['data']; $form_row = ninja_forms_get_form_by_field_id($field_id); $form_id = $form_row['id']; $require_recaptcha = WP_reCaptcha::instance()->is_required(); if ($ninja_forms_processing->get_action() != 'save' && $ninja_forms_processing->get_action() != 'mp_save' && $require_recaptcha && !WP_reCaptcha::instance()->recaptcha_check()) { $ninja_forms_processing->add_error('recaptcha-general', $recaptcha_error, 'general'); $ninja_forms_processing->add_error('recaptcha-' . $field_id, $recaptcha_error, $field_id); } }
/** * bbP recaptcha Check * * @return void */ function recaptcha_check() { if (!WP_reCaptcha::instance()->recaptcha_check()) { bbp_add_error('bbp-recaptcha-error', __('<strong>Error:</strong> the Captcha didn’t verify.', 'wp-recaptcha-integration'), 'error'); } }