Version Description
- Code: separate classes for recaptcha / nocaptcha
- Code: Class autoloader
- Fix: avoid double verification
- Fix: CF7 4.1 validation
Download this release
Release Info
Developer | podpirate |
Plugin | WordPress ReCaptcha Integration |
Version | 1.0.6 |
Comparing to | |
See all releases |
Code changes from version 1.0.5 to 1.0.6
- inc/class-wp_recaptcha_captcha.php +39 -0
- inc/class-wp_recaptcha_nocaptcha.php +180 -0
- inc/{class-wp-recaptcha-options.php → class-wp_recaptcha_options.php} +0 -2
- inc/class-wp_recaptcha_recaptcha.php +158 -0
- inc/{class-wp-recaptcha-woocommerce.php → class-wp_recaptcha_woocommerce.php} +1 -1
- inc/contact_form_7_recaptcha.php +7 -2
- recaptchalib.php → inc/recaptchalib.php +0 -0
- readme.txt +7 -1
- wp-recaptcha-integration.php +180 -429
inc/class-wp_recaptcha_captcha.php
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Class to manage the recaptcha options.
|
7 |
+
*/
|
8 |
+
abstract class WP_reCaptcha_Captcha {
|
9 |
+
|
10 |
+
protected $_last_result = false;
|
11 |
+
|
12 |
+
abstract function print_head();
|
13 |
+
abstract function print_foot();
|
14 |
+
abstract function get_html();
|
15 |
+
abstract function check();
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Get languages supported by current recaptcha flavor.
|
19 |
+
*
|
20 |
+
* @return array languages supported by recaptcha.
|
21 |
+
*/
|
22 |
+
public function get_supported_languages() {
|
23 |
+
return $this->supported_languages;
|
24 |
+
}
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Get last result of recaptcha check
|
28 |
+
* @return string recaptcha html
|
29 |
+
*/
|
30 |
+
function get_last_result() {
|
31 |
+
return $this->_last_result;
|
32 |
+
}
|
33 |
+
|
34 |
+
|
35 |
+
}
|
36 |
+
|
37 |
+
|
38 |
+
WP_reCaptcha_Options::instance();
|
39 |
+
|
inc/class-wp_recaptcha_nocaptcha.php
ADDED
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Class to manage the recaptcha options.
|
7 |
+
*/
|
8 |
+
class WP_reCaptcha_NoCaptcha extends WP_reCaptcha_Captcha {
|
9 |
+
|
10 |
+
private $supported_languages = array(
|
11 |
+
'ar' => 'Arabic',
|
12 |
+
'bg' => 'Bulgarian',
|
13 |
+
'ca' => 'Catalan',
|
14 |
+
'zh-CN' => 'Chinese (Simplified)',
|
15 |
+
'zh-TW' => 'Chinese (Traditional)',
|
16 |
+
'hr' => 'Croatian',
|
17 |
+
'cs' => 'Czech',
|
18 |
+
'da' => 'Danish',
|
19 |
+
'nl' => 'Dutch',
|
20 |
+
'en-GB' => 'English (UK)',
|
21 |
+
'en' => 'English (US)',
|
22 |
+
'fil' => 'Filipino',
|
23 |
+
'fi' => 'Finnish',
|
24 |
+
'fr' => 'French',
|
25 |
+
'fr-CA' => 'French (Canadian)',
|
26 |
+
'de' => 'German',
|
27 |
+
'de-AT' => 'German (Austria)',
|
28 |
+
'de-CH' => 'German (Switzerland)',
|
29 |
+
'el' => 'Greek',
|
30 |
+
'iw' => 'Hebrew',
|
31 |
+
'hi' => 'Hindi',
|
32 |
+
'hu' => 'Hungarain',
|
33 |
+
'id' => 'Indonesian',
|
34 |
+
'it' => 'Italian',
|
35 |
+
'ja' => 'Japanese',
|
36 |
+
'ko' => 'Korean',
|
37 |
+
'lv' => 'Latvian',
|
38 |
+
'lt' => 'Lithuanian',
|
39 |
+
'no' => 'Norwegian',
|
40 |
+
'fa' => 'Persian',
|
41 |
+
'pl' => 'Polish',
|
42 |
+
'pt' => 'Portuguese',
|
43 |
+
'pt-BR' => 'Portuguese (Brazil)',
|
44 |
+
'pt-PT' => 'Portuguese (Portugal)',
|
45 |
+
'ro' => 'Romanian',
|
46 |
+
'ru' => 'Russian',
|
47 |
+
'sr' => 'Serbian',
|
48 |
+
'sk' => 'Slovak',
|
49 |
+
'sl' => 'Slovenian',
|
50 |
+
'es' => 'Spanish',
|
51 |
+
'es-419' => 'Spanish (Latin America)',
|
52 |
+
'sv' => 'Swedish',
|
53 |
+
'th' => 'Thai',
|
54 |
+
'tr' => 'Turkish',
|
55 |
+
'uk' => 'Ukrainian',
|
56 |
+
'vi' => 'Vietnamese',
|
57 |
+
);
|
58 |
+
|
59 |
+
private $_counter = 0;
|
60 |
+
/**
|
61 |
+
* Holding the singleton instance
|
62 |
+
*/
|
63 |
+
private static $_instance = null;
|
64 |
+
|
65 |
+
/**
|
66 |
+
* @return WP_reCaptcha_Options The options manager instance
|
67 |
+
*/
|
68 |
+
public static function instance(){
|
69 |
+
if ( is_null( self::$_instance ) )
|
70 |
+
self::$_instance = new self();
|
71 |
+
return self::$_instance;
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Prevent from creating more than one instance
|
76 |
+
*/
|
77 |
+
private function __clone() {
|
78 |
+
}
|
79 |
+
/**
|
80 |
+
* Prevent from creating more than one instance
|
81 |
+
*/
|
82 |
+
private function __construct() {
|
83 |
+
|
84 |
+
}
|
85 |
+
|
86 |
+
public function print_head() {
|
87 |
+
?><style type="text/css">
|
88 |
+
#login {
|
89 |
+
width:350px !important;
|
90 |
+
}
|
91 |
+
</style><?php
|
92 |
+
}
|
93 |
+
|
94 |
+
|
95 |
+
public function print_foot() {
|
96 |
+
$language_param = '';
|
97 |
+
if ( $language_code = apply_filters( 'wp_recaptcha_language' , WP_reCaptcha::instance()->get_option( 'recaptcha_language' ) ) )
|
98 |
+
$language_param = "&hl=$language_code";
|
99 |
+
|
100 |
+
?><!-- BEGIN recaptcha, injected by plugin wp-recaptcha-integration -->
|
101 |
+
<script type="text/javascript">
|
102 |
+
var recaptcha_widgets={};
|
103 |
+
function recaptchaLoadCallback(){
|
104 |
+
try {
|
105 |
+
grecaptcha;
|
106 |
+
} catch(err){
|
107 |
+
return;
|
108 |
+
}
|
109 |
+
var e=document.getElementsByClassName('g-recaptcha'),form_submits;
|
110 |
+
|
111 |
+
for (var i=0;i<e.length;i++) {
|
112 |
+
(function(el){
|
113 |
+
<?php if ( WP_reCaptcha::instance()->get_option( 'recaptcha_disable_submit' ) ) { ?>
|
114 |
+
var form_submits = get_form_submits(el).setEnabled(false),wid;
|
115 |
+
<?php } ?>
|
116 |
+
// check if captcha element is unrendered
|
117 |
+
if ( ! el.childNodes.length) {
|
118 |
+
wid = grecaptcha.render(el,{
|
119 |
+
'sitekey':'<?php echo WP_reCaptcha::instance()->get_option('recaptcha_publickey'); ?>',
|
120 |
+
'theme':'<?php echo WP_reCaptcha::instance()->get_option('recaptcha_theme'); ?>'
|
121 |
+
<?php if ( WP_reCaptcha::instance()->get_option( 'recaptcha_disable_submit' ) ) { ?>
|
122 |
+
,
|
123 |
+
'callback' : function(r){ get_form_submits(el).setEnabled(true); /* enable submit buttons */ }
|
124 |
+
<?php } ?>
|
125 |
+
});
|
126 |
+
el.setAttribute('data-widget-id',wid);
|
127 |
+
} else {
|
128 |
+
wid = el.getAttribute('data-widget-id');
|
129 |
+
grecaptcha.reset(wid);
|
130 |
+
}
|
131 |
+
})(e[i]);
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
// if jquery present re-render jquery/ajax loaded captcha elements
|
136 |
+
if ( !!jQuery )
|
137 |
+
jQuery(document).ajaxComplete( recaptchaLoadCallback );
|
138 |
+
|
139 |
+
</script><?php
|
140 |
+
?><script src="https://www.google.com/recaptcha/api.js?onload=recaptchaLoadCallback&render=explicit<?php echo $language_param ?>" async defer></script>
|
141 |
+
?><!-- END recaptcha -->
|
142 |
+
<?php
|
143 |
+
}
|
144 |
+
|
145 |
+
|
146 |
+
|
147 |
+
public function get_html() {
|
148 |
+
$public_key = WP_reCaptcha::instance()->get_option( 'recaptcha_publickey' );
|
149 |
+
$theme = WP_reCaptcha::instance()->get_option('recaptcha_theme');
|
150 |
+
$return = sprintf( '<div id="g-recaptcha-%d" class="g-recaptcha" data-sitekey="%s" data-theme="%s"></div>' , $this->_counter++ , $public_key , $theme );
|
151 |
+
$return .= '<noscript>'.__('Please enable JavaScript to submit this form.','wp-recaptcha-integration').'</noscript>';
|
152 |
+
return $return;
|
153 |
+
}
|
154 |
+
public function check() {
|
155 |
+
$private_key = WP_reCaptcha::instance()->get_option( 'recaptcha_privatekey' );
|
156 |
+
$user_response = isset( $_REQUEST['g-recaptcha-response'] ) ? $_REQUEST['g-recaptcha-response'] : false;
|
157 |
+
if ( $user_response ) {
|
158 |
+
if ( ! $this->_last_result->success ) {
|
159 |
+
$remote_ip = $_SERVER['REMOTE_ADDR'];
|
160 |
+
$url = "https://www.google.com/recaptcha/api/siteverify?secret=$private_key&response=$user_response&remoteip=$remote_ip";
|
161 |
+
$response = wp_remote_get( $url );
|
162 |
+
if ( ! is_wp_error($response) ) {
|
163 |
+
$response_data = wp_remote_retrieve_body( $response );
|
164 |
+
$this->_last_result = json_decode($response_data);
|
165 |
+
} else {
|
166 |
+
$this->_last_result = (object) array( 'success' => false );
|
167 |
+
}
|
168 |
+
}
|
169 |
+
do_action( 'wp_recaptcha_checked' , $this->_last_result->success );
|
170 |
+
return $this->_last_result->success;
|
171 |
+
}
|
172 |
+
return false;
|
173 |
+
}
|
174 |
+
|
175 |
+
|
176 |
+
}
|
177 |
+
|
178 |
+
|
179 |
+
WP_reCaptcha_Options::instance();
|
180 |
+
|
inc/{class-wp-recaptcha-options.php → class-wp_recaptcha_options.php}
RENAMED
@@ -599,5 +599,3 @@ class WP_reCaptcha_Options {
|
|
599 |
}
|
600 |
|
601 |
|
602 |
-
WP_reCaptcha_Options::instance();
|
603 |
-
|
599 |
}
|
600 |
|
601 |
|
|
|
|
inc/class-wp_recaptcha_recaptcha.php
ADDED
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Class to manage the recaptcha options.
|
7 |
+
*/
|
8 |
+
class WP_reCaptcha_ReCaptcha extends WP_reCaptcha_Captcha {
|
9 |
+
|
10 |
+
private $supported_languages = array(
|
11 |
+
'en' => 'English',
|
12 |
+
'nl' => 'Dutch',
|
13 |
+
'fr' => 'French',
|
14 |
+
'de' => 'German',
|
15 |
+
'pt' => 'Portuguese',
|
16 |
+
'ru' => 'Russian',
|
17 |
+
'es' => 'Spanish',
|
18 |
+
'tr' => 'Turkish',
|
19 |
+
);
|
20 |
+
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Holding the singleton instance
|
24 |
+
*/
|
25 |
+
private static $_instance = null;
|
26 |
+
|
27 |
+
/**
|
28 |
+
* @return WP_reCaptcha_Options The options manager instance
|
29 |
+
*/
|
30 |
+
public static function instance(){
|
31 |
+
if ( is_null( self::$_instance ) )
|
32 |
+
self::$_instance = new self();
|
33 |
+
return self::$_instance;
|
34 |
+
}
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Prevent from creating more than one instance
|
38 |
+
*/
|
39 |
+
private function __clone() {
|
40 |
+
}
|
41 |
+
/**
|
42 |
+
* Prevent from creating more than one instance
|
43 |
+
*/
|
44 |
+
private function __construct() {
|
45 |
+
if ( ! defined( 'RECAPTCHA_API_SERVER' ) || ! function_exists( 'recaptcha_get_html' ) )
|
46 |
+
require_once dirname(__FILE__).'/recaptchalib.php';
|
47 |
+
}
|
48 |
+
|
49 |
+
public function print_head() {
|
50 |
+
$recaptcha_theme = WP_reCaptcha::instance()->get_option('recaptcha_theme');
|
51 |
+
if ( $recaptcha_theme == 'custom' ) {
|
52 |
+
?><script type="text/javascript">
|
53 |
+
var RecaptchaOptions = {
|
54 |
+
theme : '<?php echo $recaptcha_theme ?>',
|
55 |
+
custom_theme_widget: 'recaptcha_widget'
|
56 |
+
};
|
57 |
+
</script><?php
|
58 |
+
} else {
|
59 |
+
?><script type="text/javascript">
|
60 |
+
var RecaptchaOptions = {
|
61 |
+
<?php
|
62 |
+
$language_code = apply_filters( 'wp_recaptcha_language' , WP_reCaptcha::instance()->get_option( 'recaptcha_language' ) );
|
63 |
+
if ( $language_code ) { ?>
|
64 |
+
lang : '<?php echo $language_code ?>',
|
65 |
+
<?php } ?>
|
66 |
+
theme : '<?php echo $recaptcha_theme ?>'
|
67 |
+
|
68 |
+
};
|
69 |
+
</script><?php
|
70 |
+
}
|
71 |
+
}
|
72 |
+
public function print_foot() {
|
73 |
+
if ( WP_reCaptcha::instance()->get_option( 'recaptcha_disable_submit' ) ) {
|
74 |
+
?><script type="text/javascript">
|
75 |
+
document.addEventListener('keyup',function(e){
|
76 |
+
if (e.target && typeof e.target.getAttribute=='function' && e.target.getAttribute('ID')=='recaptcha_response_field') {
|
77 |
+
get_form_submits(e.target).setEnabled(!!e.target.value);
|
78 |
+
}
|
79 |
+
});
|
80 |
+
document.addEventListener('DOMContentLoaded',function(e){
|
81 |
+
try {
|
82 |
+
get_form_submits(document.getElementById('wp-recaptcha-integration-marker')).setEnabled(false);
|
83 |
+
} catch(e){};
|
84 |
+
});
|
85 |
+
</script><?php
|
86 |
+
}
|
87 |
+
break;
|
88 |
+
}
|
89 |
+
public function get_html() {
|
90 |
+
$public_key = WP_reCaptcha::instance()->get_option( 'recaptcha_publickey' );
|
91 |
+
$recaptcha_theme = WP_reCaptcha::instance()->get_option('recaptcha_theme');
|
92 |
+
|
93 |
+
if ($recaptcha_theme == 'custom')
|
94 |
+
$return = $this->get_custom_html( $public_key );
|
95 |
+
else
|
96 |
+
$return = recaptcha_get_html( $public_key, $this->last_error );
|
97 |
+
if ( WP_reCaptcha::instance()->get_option( 'recaptcha_disable_submit' ) ) {
|
98 |
+
$return .= '<span id="wp-recaptcha-integration-marker"></span>';
|
99 |
+
}
|
100 |
+
return $return;
|
101 |
+
}
|
102 |
+
public function check() {
|
103 |
+
if ( ! $this->_last_result ) {
|
104 |
+
$private_key = $this->get_option( 'recaptcha_privatekey' );
|
105 |
+
$this->_last_result = recaptcha_check_answer( $private_key,
|
106 |
+
$_SERVER["REMOTE_ADDR"],
|
107 |
+
$_POST["recaptcha_challenge_field"],
|
108 |
+
$_POST["recaptcha_response_field"]);
|
109 |
+
|
110 |
+
if ( ! $this->_last_result->is_valid )
|
111 |
+
$this->last_error = $this->_last_result->error;
|
112 |
+
}
|
113 |
+
do_action( 'wp_recaptcha_checked' , $this->_last_result->is_valid );
|
114 |
+
return $this->_last_result->is_valid;
|
115 |
+
}
|
116 |
+
|
117 |
+
|
118 |
+
/**
|
119 |
+
* Get un-themed old style recaptcha HTML.
|
120 |
+
* @return string recaptcha html
|
121 |
+
*/
|
122 |
+
private function get_custom_html( $public_key ) {
|
123 |
+
|
124 |
+
$return = '<div id="recaptcha_widget" style="display:none">';
|
125 |
+
|
126 |
+
$return .= '<div id="recaptcha_image"></div>';
|
127 |
+
$return .= sprintf('<div class="recaptcha_only_if_incorrect_sol" style="color:red">%s</div>',__('Incorrect please try again','wp-recaptcha-integration'));
|
128 |
+
|
129 |
+
$return .= sprintf('<span class="recaptcha_only_if_image">%s</span>',__('Enter the words above:','wp-recaptcha-integration'));
|
130 |
+
$return .= sprintf('<span class="recaptcha_only_if_audio">%s</span>',__('Enter the numbers you hear:','wp-recaptcha-integration'));
|
131 |
+
|
132 |
+
$return .= '<input type="text" id="recaptcha_response_field" name="recaptcha_response_field" />';
|
133 |
+
|
134 |
+
$return .= sprintf('<div><a href="javascript:Recaptcha.reload()"></a></div>',__('Get another CAPTCHA','wp-recaptcha-integration'));
|
135 |
+
$return .= sprintf('<div class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type(\'audio\')">%s</a></div>',__('Get an audio CAPTCHA','wp-recaptcha-integration'));
|
136 |
+
$return .= sprintf('<div class="recaptcha_only_if_audio"><a href="javascript:Recaptcha.switch_type(\'image\')">%s</a></div>',__('Get an image CAPTCHA','wp-recaptcha-integration'));
|
137 |
+
|
138 |
+
$return .= '<div><a href="javascript:Recaptcha.showhelp()">Help</a></div>';
|
139 |
+
$return .= '</div>';
|
140 |
+
|
141 |
+
$return .= sprintf('<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=%s"></script>',$public_key);
|
142 |
+
$return .= '<noscript>';
|
143 |
+
$return .= sprintf('<iframe src="http://www.google.com/recaptcha/api/noscript?k=%s" height="300" width="500" frameborder="0"></iframe><br>',$public_key);
|
144 |
+
$return .= '<textarea name="recaptcha_challenge_field" rows="3" cols="40">';
|
145 |
+
$return .= '</textarea>';
|
146 |
+
$return .= '<input type="hidden" name="recaptcha_response_field" value="manual_challenge">';
|
147 |
+
$return .= '</noscript>';
|
148 |
+
|
149 |
+
return $return;
|
150 |
+
}
|
151 |
+
|
152 |
+
|
153 |
+
|
154 |
+
}
|
155 |
+
|
156 |
+
|
157 |
+
WP_reCaptcha_Options::instance();
|
158 |
+
|
inc/{class-wp-recaptcha-woocommerce.php → class-wp_recaptcha_woocommerce.php}
RENAMED
@@ -82,4 +82,4 @@ class WP_reCaptcha_WooCommerce {
|
|
82 |
}
|
83 |
}
|
84 |
|
85 |
-
|
82 |
}
|
83 |
}
|
84 |
|
85 |
+
|
inc/contact_form_7_recaptcha.php
CHANGED
@@ -69,8 +69,13 @@ function wpcf7_recaptcha_validation_filter( $result, $tag ) {
|
|
69 |
$name = $tag->name;
|
70 |
|
71 |
if ( ! WP_reCaptcha::instance()->recaptcha_check() ) {
|
72 |
-
$
|
73 |
-
$result
|
|
|
|
|
|
|
|
|
|
|
74 |
}
|
75 |
return $result;
|
76 |
}
|
69 |
$name = $tag->name;
|
70 |
|
71 |
if ( ! WP_reCaptcha::instance()->recaptcha_check() ) {
|
72 |
+
$message = __("The Captcha didn’t verify.",'wp-recaptcha-integration');
|
73 |
+
if ( method_exists($result, 'invalidate' ) ) {
|
74 |
+
$result->invalidate( $tag , $message );
|
75 |
+
} else {
|
76 |
+
$result['valid'] = false;
|
77 |
+
$result['reason'][$name] = $message;
|
78 |
+
}
|
79 |
}
|
80 |
return $result;
|
81 |
}
|
recaptchalib.php → inc/recaptchalib.php
RENAMED
File without changes
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
|
|
4 |
Tags: security, captcha, recaptcha, no captcha, login, signup, contact form 7, ninja forms
|
5 |
Requires at least: 3.8
|
6 |
Tested up to: 4.1
|
7 |
-
Stable tag: 1.0.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -144,6 +144,12 @@ I will migrate all the translation stuff there.
|
|
144 |
|
145 |
== Changelog ==
|
146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
= 1.0.5 =
|
148 |
- Add Language option
|
149 |
- Brasilian Portuguese localization
|
4 |
Tags: security, captcha, recaptcha, no captcha, login, signup, contact form 7, ninja forms
|
5 |
Requires at least: 3.8
|
6 |
Tested up to: 4.1
|
7 |
+
Stable tag: 1.0.6
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
144 |
|
145 |
== Changelog ==
|
146 |
|
147 |
+
= 1.0.6 =
|
148 |
+
- Code: separate classes for recaptcha / nocaptcha
|
149 |
+
- Code: Class autoloader
|
150 |
+
- Fix: avoid double verification
|
151 |
+
- Fix: CF7 4.1 validation
|
152 |
+
|
153 |
= 1.0.5 =
|
154 |
- Add Language option
|
155 |
- Brasilian Portuguese localization
|
wp-recaptcha-integration.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: WP reCaptcha Integration
|
4 |
Plugin URI: https://wordpress.org/plugins/wp-recaptcha-integration/
|
5 |
Description: Integrate reCaptcha in your blog. Supports no Captcha (new style recaptcha) as well as the old style reCaptcha. Provides of the box integration for signup, login, comment forms, lost password, Ninja Forms and contact form 7.
|
6 |
-
Version: 1.0.
|
7 |
Author: Jörn Lund
|
8 |
Author URI: https://github.com/mcguffin/
|
9 |
*/
|
@@ -39,65 +39,9 @@ class WP_reCaptcha {
|
|
39 |
private $_last_result;
|
40 |
|
41 |
private $_counter = 0;
|
|
|
|
|
42 |
|
43 |
-
private $grecaptcha_languages = array(
|
44 |
-
'ar' => 'Arabic',
|
45 |
-
'bg' => 'Bulgarian',
|
46 |
-
'ca' => 'Catalan',
|
47 |
-
'zh-CN' => 'Chinese (Simplified)',
|
48 |
-
'zh-TW' => 'Chinese (Traditional)',
|
49 |
-
'hr' => 'Croatian',
|
50 |
-
'cs' => 'Czech',
|
51 |
-
'da' => 'Danish',
|
52 |
-
'nl' => 'Dutch',
|
53 |
-
'en-GB' => 'English (UK)',
|
54 |
-
'en' => 'English (US)',
|
55 |
-
'fil' => 'Filipino',
|
56 |
-
'fi' => 'Finnish',
|
57 |
-
'fr' => 'French',
|
58 |
-
'fr-CA' => 'French (Canadian)',
|
59 |
-
'de' => 'German',
|
60 |
-
'de-AT' => 'German (Austria)',
|
61 |
-
'de-CH' => 'German (Switzerland)',
|
62 |
-
'el' => 'Greek',
|
63 |
-
'iw' => 'Hebrew',
|
64 |
-
'hi' => 'Hindi',
|
65 |
-
'hu' => 'Hungarain',
|
66 |
-
'id' => 'Indonesian',
|
67 |
-
'it' => 'Italian',
|
68 |
-
'ja' => 'Japanese',
|
69 |
-
'ko' => 'Korean',
|
70 |
-
'lv' => 'Latvian',
|
71 |
-
'lt' => 'Lithuanian',
|
72 |
-
'no' => 'Norwegian',
|
73 |
-
'fa' => 'Persian',
|
74 |
-
'pl' => 'Polish',
|
75 |
-
'pt' => 'Portuguese',
|
76 |
-
'pt-BR' => 'Portuguese (Brazil)',
|
77 |
-
'pt-PT' => 'Portuguese (Portugal)',
|
78 |
-
'ro' => 'Romanian',
|
79 |
-
'ru' => 'Russian',
|
80 |
-
'sr' => 'Serbian',
|
81 |
-
'sk' => 'Slovak',
|
82 |
-
'sl' => 'Slovenian',
|
83 |
-
'es' => 'Spanish',
|
84 |
-
'es-419' => 'Spanish (Latin America)',
|
85 |
-
'sv' => 'Swedish',
|
86 |
-
'th' => 'Thai',
|
87 |
-
'tr' => 'Turkish',
|
88 |
-
'uk' => 'Ukrainian',
|
89 |
-
'vi' => 'Vietnamese',
|
90 |
-
);
|
91 |
-
private $recaptcha_languages = array(
|
92 |
-
'en' => 'English',
|
93 |
-
'nl' => 'Dutch',
|
94 |
-
'fr' => 'French',
|
95 |
-
'de' => 'German',
|
96 |
-
'pt' => 'Portuguese',
|
97 |
-
'ru' => 'Russian',
|
98 |
-
'es' => 'Spanish',
|
99 |
-
'tr' => 'Turkish',
|
100 |
-
);
|
101 |
/**
|
102 |
* Holding the singleton instance
|
103 |
*/
|
@@ -159,13 +103,6 @@ class WP_reCaptcha {
|
|
159 |
register_uninstall_hook( __FILE__ , array( __CLASS__ , 'uninstall' ) );
|
160 |
|
161 |
}
|
162 |
-
|
163 |
-
/**
|
164 |
-
* @return bool return if google api is configured
|
165 |
-
*/
|
166 |
-
function has_api_key() {
|
167 |
-
return $this->_has_api_key;
|
168 |
-
}
|
169 |
|
170 |
/**
|
171 |
* Load ninja/cf7 php files if necessary
|
@@ -184,9 +121,9 @@ class WP_reCaptcha {
|
|
184 |
include_once dirname(__FILE__).'/inc/contact_form_7_recaptcha.php';
|
185 |
|
186 |
// WooCommerce support
|
187 |
-
// check if
|
188 |
if ( function_exists('WC') || class_exists('WooCommerce') )
|
189 |
-
|
190 |
|
191 |
}
|
192 |
}
|
@@ -246,16 +183,21 @@ class WP_reCaptcha {
|
|
246 |
}
|
247 |
}
|
248 |
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
|
|
|
|
|
|
|
|
258 |
}
|
|
|
259 |
/**
|
260 |
* returns if recaptcha is required.
|
261 |
*
|
@@ -268,127 +210,18 @@ class WP_reCaptcha {
|
|
268 |
|
269 |
|
270 |
|
271 |
-
/**
|
272 |
-
* check recaptcha on login
|
273 |
-
* filter function for `wp_authenticate_user`
|
274 |
-
*
|
275 |
-
* @param $user WP_User
|
276 |
-
* @return object user or wp_error
|
277 |
-
*/
|
278 |
-
function deny_login( $user ) {
|
279 |
-
if ( isset( $_POST["log"]) )
|
280 |
-
$user = $this->wp_error( $user );
|
281 |
-
return $user;
|
282 |
-
}
|
283 |
-
|
284 |
-
/**
|
285 |
-
* check recaptcha on registration
|
286 |
-
* filter function for `registration_errors`
|
287 |
-
*
|
288 |
-
* @param $errors WP_Error
|
289 |
-
* @return WP_Error with captcha error added if test fails.
|
290 |
-
*/
|
291 |
-
function registration_errors( $errors ) {
|
292 |
-
if ( isset( $_POST["user_login"]) )
|
293 |
-
$errors = $this->wp_error_add( $errors );
|
294 |
-
return $errors;
|
295 |
-
}
|
296 |
-
|
297 |
-
/**
|
298 |
-
* check recaptcha WPMU signup
|
299 |
-
* filter function for `wpmu_validate_user_signup`
|
300 |
-
*
|
301 |
-
* @see filter hook `wpmu_validate_user_signup`
|
302 |
-
*/
|
303 |
-
function wpmu_validate_user_signup( $result ) {
|
304 |
-
if ( isset( $_POST['stage'] ) && $_POST['stage'] == 'validate-user-signup' )
|
305 |
-
$result['errors'] = $this->wp_error_add( $result['errors'] , 'generic' );
|
306 |
-
return $result;
|
307 |
-
}
|
308 |
-
|
309 |
-
|
310 |
-
/**
|
311 |
-
* check recaptcha and return WP_Error on failure.
|
312 |
-
* filter function for `allow_password_reset`
|
313 |
-
*
|
314 |
-
* @param $param mixed return value of funtion when captcha validates
|
315 |
-
* @return mixed will return argument $param an success, else WP_Error
|
316 |
-
*/
|
317 |
-
function wp_error( $param , $error_code = 'captcha_error' ) {
|
318 |
-
if ( ! $this->recaptcha_check() ) {
|
319 |
-
return new WP_Error( $error_code , __("<strong>Error:</strong> the Captcha didn’t verify.",'wp-recaptcha-integration') );
|
320 |
-
} else {
|
321 |
-
return $param;
|
322 |
-
}
|
323 |
-
}
|
324 |
-
/**
|
325 |
-
* check recaptcha and return WP_Error on failure.
|
326 |
-
* filter function for `allow_password_reset`
|
327 |
-
*
|
328 |
-
* @param $param mixed return value of funtion when captcha validates
|
329 |
-
* @return mixed will return argument $param an success, else WP_Error
|
330 |
-
*/
|
331 |
-
function wp_error_add( $param , $error_code = 'captcha_error' ) {
|
332 |
-
if ( ! $this->recaptcha_check() ) {
|
333 |
-
return new WP_Error( $error_code , __("<strong>Error:</strong> the Captcha didn’t verify.",'wp-recaptcha-integration') );
|
334 |
-
} else {
|
335 |
-
return $param;
|
336 |
-
}
|
337 |
-
}
|
338 |
-
|
339 |
-
/**
|
340 |
-
* Check recaptcha and wp_die() on fail
|
341 |
-
* hooks into `pre_comment_on_post`, `lostpassword_post`
|
342 |
-
*/
|
343 |
-
function recaptcha_check_or_die( ) {
|
344 |
-
if ( ! $this->recaptcha_check() ) {
|
345 |
-
$err = new WP_Error('comment_err', __("<strong>Error:</strong> the Captcha didn’t verify.",'wp-recaptcha-integration') );
|
346 |
-
wp_die( $err );
|
347 |
-
}
|
348 |
-
}
|
349 |
-
|
350 |
|
|
|
|
|
|
|
351 |
|
352 |
/**
|
353 |
* print recaptcha stylesheets
|
354 |
* hooks into `wp_head`
|
355 |
*/
|
356 |
-
function recaptcha_head(
|
357 |
-
if ( empty( $flavor ) )
|
358 |
-
$flavor = $this->get_option( 'recaptcha_flavor' );
|
359 |
$this->begin_inject( );
|
360 |
-
|
361 |
-
case 'grecaptcha':
|
362 |
-
?><style type="text/css">
|
363 |
-
#login {
|
364 |
-
width:350px !important;
|
365 |
-
}
|
366 |
-
</style><?php
|
367 |
-
break;
|
368 |
-
case 'recaptcha':
|
369 |
-
$recaptcha_theme = $this->get_option('recaptcha_theme');
|
370 |
-
if ( $recaptcha_theme == 'custom' ) {
|
371 |
-
?><script type="text/javascript">
|
372 |
-
var RecaptchaOptions = {
|
373 |
-
theme : '<?php echo $recaptcha_theme ?>',
|
374 |
-
custom_theme_widget: 'recaptcha_widget'
|
375 |
-
};
|
376 |
-
</script><?php
|
377 |
-
} else {
|
378 |
-
?><script type="text/javascript">
|
379 |
-
var RecaptchaOptions = {
|
380 |
-
<?php
|
381 |
-
$language_code = apply_filters( 'wp_recaptcha_language' , $this->get_option( 'recaptcha_language' ) );
|
382 |
-
if ( $language_code ) { ?>
|
383 |
-
lang : '<?php echo $language_code ?>',
|
384 |
-
<?php } ?>
|
385 |
-
theme : '<?php echo $recaptcha_theme ?>'
|
386 |
-
|
387 |
-
};
|
388 |
-
</script><?php
|
389 |
-
}
|
390 |
-
break;
|
391 |
-
}
|
392 |
$this->end_inject( );
|
393 |
}
|
394 |
|
@@ -396,13 +229,10 @@ class WP_reCaptcha {
|
|
396 |
* Print recaptcha scripts
|
397 |
* hooks into `wp_footer`
|
398 |
*
|
399 |
-
* @param $flavor string force recaptcha | greaptcha flavor. falls back to `get_option( 'recaptcha_flavor' )`.
|
400 |
*/
|
401 |
-
function recaptcha_foot(
|
402 |
-
if ( empty( $flavor ) )
|
403 |
-
$flavor = $this->get_option( 'recaptcha_flavor' );
|
404 |
-
|
405 |
$this->begin_inject( );
|
|
|
406 |
// getting submit buttons of an elements form
|
407 |
if ( $this->get_option( 'recaptcha_disable_submit' ) ) {
|
408 |
?><script type="text/javascript">
|
@@ -430,243 +260,170 @@ class WP_reCaptcha {
|
|
430 |
}
|
431 |
</script><?php
|
432 |
}
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
$language_param = '';
|
437 |
-
if ( $language_code = apply_filters( 'wp_recaptcha_language' , $this->get_option( 'recaptcha_language' ) ) )
|
438 |
-
$language_param = "&hl=$language_code";
|
439 |
-
|
440 |
-
?><script type="text/javascript">
|
441 |
-
var recaptcha_widgets={};
|
442 |
-
function recaptchaLoadCallback(){
|
443 |
-
try {
|
444 |
-
grecaptcha;
|
445 |
-
} catch(err){
|
446 |
-
return;
|
447 |
-
}
|
448 |
-
var e=document.getElementsByClassName('g-recaptcha'),form_submits;
|
449 |
-
|
450 |
-
for (var i=0;i<e.length;i++) {
|
451 |
-
(function(el){
|
452 |
-
<?php if ( $this->get_option( 'recaptcha_disable_submit' ) ) { ?>
|
453 |
-
var form_submits = get_form_submits(el).setEnabled(false),wid;
|
454 |
-
<?php } ?>
|
455 |
-
// check if captcha element is unrendered
|
456 |
-
if ( ! el.childNodes.length) {
|
457 |
-
wid = grecaptcha.render(el,{
|
458 |
-
'sitekey':'<?php echo $this->get_option('recaptcha_publickey'); ?>',
|
459 |
-
'theme':'<?php echo $this->get_option('recaptcha_theme'); ?>'
|
460 |
-
<?php if ( $this->get_option( 'recaptcha_disable_submit' ) ) { ?>
|
461 |
-
,
|
462 |
-
'callback' : function(r){ get_form_submits(el).setEnabled(true); /* enable submit buttons */ }
|
463 |
-
<?php } ?>
|
464 |
-
});
|
465 |
-
el.setAttribute('data-widget-id',wid);
|
466 |
-
} else {
|
467 |
-
wid = el.getAttribute('data-widget-id');
|
468 |
-
grecaptcha.reset(wid);
|
469 |
-
}
|
470 |
-
})(e[i]);
|
471 |
-
}
|
472 |
-
}
|
473 |
-
|
474 |
-
// if jquery present re-render jquery/ajax loaded captcha elements
|
475 |
-
if ( !!jQuery )
|
476 |
-
jQuery(document).ajaxComplete( recaptchaLoadCallback );
|
477 |
-
|
478 |
-
</script><?php
|
479 |
-
?><script src="https://www.google.com/recaptcha/api.js?onload=recaptchaLoadCallback&render=explicit<?php echo $language_param ?>" async defer></script><?php
|
480 |
-
break;
|
481 |
-
case 'recaptcha':
|
482 |
-
if ( $this->get_option( 'recaptcha_disable_submit' ) ) {
|
483 |
-
?><script type="text/javascript">
|
484 |
-
document.addEventListener('keyup',function(e){
|
485 |
-
if (e.target && typeof e.target.getAttribute=='function' && e.target.getAttribute('ID')=='recaptcha_response_field') {
|
486 |
-
get_form_submits(e.target).setEnabled(!!e.target.value);
|
487 |
-
}
|
488 |
-
});
|
489 |
-
document.addEventListener('DOMContentLoaded',function(e){
|
490 |
-
try {
|
491 |
-
get_form_submits(document.getElementById('wp-recaptcha-integration-marker')).setEnabled(false);
|
492 |
-
} catch(e){};
|
493 |
-
});
|
494 |
-
</script><?php
|
495 |
-
}
|
496 |
-
break;
|
497 |
-
}
|
498 |
$this->end_inject( );
|
499 |
}
|
|
|
500 |
/**
|
501 |
* Print recaptcha HTML. Use inside a form.
|
502 |
*
|
503 |
-
* @param $flavor string force recaptcha | greaptcha flavor. falls back to `get_option( 'recaptcha_flavor' )`.
|
504 |
*/
|
505 |
-
function print_recaptcha_html(
|
506 |
-
|
|
|
|
|
507 |
}
|
508 |
|
509 |
/**
|
510 |
* Get recaptcha HTML.
|
511 |
*
|
512 |
-
* @param $flavor string force recaptcha | greaptcha flavor. falls back to `get_option( 'recaptcha_flavor' )`.
|
513 |
* @return string recaptcha html
|
514 |
*/
|
515 |
-
function recaptcha_html(
|
516 |
-
|
517 |
-
if ( empty( $flavor ) )
|
518 |
-
$flavor = $this->get_option( 'recaptcha_flavor' );
|
519 |
-
$return = $this->begin_inject( true );
|
520 |
-
|
521 |
-
switch ( $flavor ) {
|
522 |
-
case 'grecaptcha':
|
523 |
-
$return .= $this->grecaptcha_html();
|
524 |
-
break;
|
525 |
-
case 'recaptcha':
|
526 |
-
$return .= $this->old_recaptcha_html();
|
527 |
-
break;
|
528 |
-
}
|
529 |
-
$return .= $this->end_inject( true );
|
530 |
-
return $return;
|
531 |
}
|
532 |
|
533 |
/**
|
534 |
-
*
|
535 |
-
*
|
|
|
|
|
|
|
536 |
*/
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
if ($recaptcha_theme == 'custom')
|
543 |
-
$return = $this->get_custom_html( $public_key );
|
544 |
-
else
|
545 |
-
$return = recaptcha_get_html( $public_key, $this->last_error );
|
546 |
-
if ( $this->get_option( 'recaptcha_disable_submit' ) ) {
|
547 |
-
$return .= '<span id="wp-recaptcha-integration-marker"></span>';
|
548 |
-
}
|
549 |
-
return $return;
|
550 |
-
}
|
551 |
-
|
552 |
/**
|
553 |
-
*
|
554 |
-
*
|
|
|
|
|
555 |
*/
|
556 |
-
function
|
557 |
-
$
|
558 |
-
$
|
559 |
-
|
560 |
-
$return .= '<noscript>'.__('Please enable JavaScript to submit this form.','wp-recaptcha-integration').'</noscript>';
|
561 |
-
return $return;
|
562 |
}
|
563 |
|
564 |
/**
|
565 |
-
*
|
566 |
-
*
|
|
|
|
|
567 |
*/
|
568 |
-
function
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
$return .= '<div id="recaptcha_image"></div>';
|
573 |
-
$return .= sprintf('<div class="recaptcha_only_if_incorrect_sol" style="color:red">%s</div>',__('Incorrect please try again','wp-recaptcha-integration'));
|
574 |
-
|
575 |
-
$return .= sprintf('<span class="recaptcha_only_if_image">%s</span>',__('Enter the words above:','wp-recaptcha-integration'));
|
576 |
-
$return .= sprintf('<span class="recaptcha_only_if_audio">%s</span>',__('Enter the numbers you hear:','wp-recaptcha-integration'));
|
577 |
-
|
578 |
-
$return .= '<input type="text" id="recaptcha_response_field" name="recaptcha_response_field" />';
|
579 |
-
|
580 |
-
$return .= sprintf('<div><a href="javascript:Recaptcha.reload()"></a></div>',__('Get another CAPTCHA','wp-recaptcha-integration'));
|
581 |
-
$return .= sprintf('<div class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type(\'audio\')">%s</a></div>',__('Get an audio CAPTCHA','wp-recaptcha-integration'));
|
582 |
-
$return .= sprintf('<div class="recaptcha_only_if_audio"><a href="javascript:Recaptcha.switch_type(\'image\')">%s</a></div>',__('Get an image CAPTCHA','wp-recaptcha-integration'));
|
583 |
|
584 |
-
|
585 |
-
|
|
|
586 |
|
587 |
-
$return .= sprintf('<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=%s"></script>',$public_key);
|
588 |
-
$return .= '<noscript>';
|
589 |
-
$return .= sprintf('<iframe src="http://www.google.com/recaptcha/api/noscript?k=%s" height="300" width="500" frameborder="0"></iframe><br>',$public_key);
|
590 |
-
$return .= '<textarea name="recaptcha_challenge_field" rows="3" cols="40">';
|
591 |
-
$return .= '</textarea>';
|
592 |
-
$return .= '<input type="hidden" name="recaptcha_response_field" value="manual_challenge">';
|
593 |
-
$return .= '</noscript>';
|
594 |
-
|
595 |
-
return $return;
|
596 |
-
}
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
/**
|
602 |
* Get last result of recaptcha check
|
603 |
* @return string recaptcha html
|
604 |
*/
|
605 |
function get_last_result() {
|
606 |
-
return $this->
|
607 |
}
|
608 |
|
609 |
/**
|
610 |
* Check recaptcha
|
611 |
*
|
612 |
-
* @param $flavor string force recaptcha | greaptcha flavor. falls back to `get_option( 'recaptcha_flavor' )`.
|
613 |
* @return bool false if check does not validate
|
614 |
*/
|
615 |
-
function recaptcha_check(
|
616 |
-
$
|
617 |
-
if ( empty( $flavor ) )
|
618 |
-
$flavor = $this->get_option( 'recaptcha_flavor' );
|
619 |
-
switch ( $flavor ) {
|
620 |
-
case 'grecaptcha':
|
621 |
-
$result = $this->grecaptcha_check();
|
622 |
-
break;
|
623 |
-
case 'recaptcha':
|
624 |
-
$result = $this->old_recaptcha_check();
|
625 |
-
break;
|
626 |
-
}
|
627 |
-
return $result;
|
628 |
}
|
|
|
629 |
/**
|
630 |
-
*
|
631 |
-
*
|
632 |
-
*
|
|
|
|
|
633 |
*/
|
634 |
-
function
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
647 |
}
|
648 |
-
return false;
|
649 |
}
|
650 |
/**
|
651 |
-
*
|
652 |
-
*
|
653 |
-
*
|
|
|
|
|
654 |
*/
|
655 |
-
function
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
$
|
660 |
-
|
661 |
-
$_POST["recaptcha_response_field"]);
|
662 |
-
|
663 |
-
if ( ! $this->_last_result->is_valid )
|
664 |
-
$this->last_error = $this->_last_result->error;
|
665 |
-
|
666 |
-
do_action( 'wp_recaptcha_checked' , $this->_last_result->is_valid );
|
667 |
-
return $this->_last_result->is_valid;
|
668 |
}
|
669 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
670 |
/**
|
671 |
* Get plugin option by name.
|
672 |
*
|
@@ -695,6 +452,18 @@ class WP_reCaptcha {
|
|
695 |
}
|
696 |
}
|
697 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
698 |
/**
|
699 |
* Fired on plugin activation
|
700 |
*/
|
@@ -759,31 +528,14 @@ class WP_reCaptcha {
|
|
759 |
}
|
760 |
return self::$_is_network_activated;
|
761 |
}
|
762 |
-
/**
|
763 |
-
* HTML comment with some notes (beginning)
|
764 |
-
*
|
765 |
-
* @param $return bool Whether to print or to return the comment
|
766 |
-
* @param $moretext string Additional information being included in the comment
|
767 |
-
* @return null|string HTML-Comment
|
768 |
-
*/
|
769 |
-
function begin_inject($return = false,$moretext='') {
|
770 |
-
$html = "\n<!-- BEGIN recaptcha, injected by plugin wp-recaptcha-integration $moretext -->\n";
|
771 |
-
if ( $return ) return $html;
|
772 |
-
echo $html;
|
773 |
-
}
|
774 |
-
/**
|
775 |
-
* HTML comment with some notes (ending)
|
776 |
-
*
|
777 |
-
* @param $return bool Whether to print or to return the comment
|
778 |
-
* @return null|string HTML-Comment
|
779 |
-
*/
|
780 |
-
function end_inject( $return = false ) {
|
781 |
-
$html = "\n<!-- END recaptcha -->\n";
|
782 |
-
if ( $return ) return $html;
|
783 |
-
echo $html;
|
784 |
-
}
|
785 |
|
786 |
|
|
|
|
|
|
|
|
|
|
|
|
|
787 |
/**
|
788 |
* Rewrite WP get_locale() to recaptcha lang param.
|
789 |
*
|
@@ -829,29 +581,28 @@ class WP_reCaptcha {
|
|
829 |
*
|
830 |
* @return array languages supported by recaptcha.
|
831 |
*/
|
832 |
-
function get_supported_languages(
|
833 |
-
|
834 |
-
$flavor = $this->get_option( 'recaptcha_flavor' );
|
835 |
-
switch( $flavor ) {
|
836 |
-
case 'recaptcha':
|
837 |
-
return $this->recaptcha_languages;
|
838 |
-
case 'grecaptcha':
|
839 |
-
return $this->grecaptcha_languages;
|
840 |
-
}
|
841 |
-
return array();
|
842 |
}
|
843 |
|
844 |
-
/**
|
845 |
-
* Load reCaptcha Library (3rd Party) if needed.
|
846 |
-
*
|
847 |
-
*/
|
848 |
-
private function load_recaptchalib() {
|
849 |
-
if ( ! defined( 'RECAPTCHA_API_SERVER' ) || ! function_exists( 'recaptcha_get_html' ) )
|
850 |
-
require_once dirname(__FILE__).'/recaptchalib.php';
|
851 |
-
}
|
852 |
}
|
853 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
854 |
WP_reCaptcha::instance();
|
855 |
|
|
|
856 |
if ( is_admin() )
|
857 |
-
|
3 |
Plugin Name: WP reCaptcha Integration
|
4 |
Plugin URI: https://wordpress.org/plugins/wp-recaptcha-integration/
|
5 |
Description: Integrate reCaptcha in your blog. Supports no Captcha (new style recaptcha) as well as the old style reCaptcha. Provides of the box integration for signup, login, comment forms, lost password, Ninja Forms and contact form 7.
|
6 |
+
Version: 1.0.6
|
7 |
Author: Jörn Lund
|
8 |
Author URI: https://github.com/mcguffin/
|
9 |
*/
|
39 |
private $_last_result;
|
40 |
|
41 |
private $_counter = 0;
|
42 |
+
|
43 |
+
private $_captcha_instance = null;
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
/**
|
46 |
* Holding the singleton instance
|
47 |
*/
|
103 |
register_uninstall_hook( __FILE__ , array( __CLASS__ , 'uninstall' ) );
|
104 |
|
105 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
/**
|
108 |
* Load ninja/cf7 php files if necessary
|
121 |
include_once dirname(__FILE__).'/inc/contact_form_7_recaptcha.php';
|
122 |
|
123 |
// WooCommerce support
|
124 |
+
// check if woocommerce is present
|
125 |
if ( function_exists('WC') || class_exists('WooCommerce') )
|
126 |
+
WP_reCaptcha_WooCommerce::instance();
|
127 |
|
128 |
}
|
129 |
}
|
183 |
}
|
184 |
}
|
185 |
|
186 |
+
|
187 |
+
public function captcha_instance() {
|
188 |
+
if ( is_null( $this->_captcha_instance ) ) {
|
189 |
+
switch ( $this->get_option( 'recaptcha_flavor' ) ) {
|
190 |
+
case 'grecaptcha':
|
191 |
+
$this->_captcha_instance = WP_reCaptcha_NoCaptcha::instance();
|
192 |
+
break;
|
193 |
+
case 'recaptcha':
|
194 |
+
$this->_captcha_instance = WP_reCaptcha_ReCaptcha::instance();
|
195 |
+
break;
|
196 |
+
}
|
197 |
+
}
|
198 |
+
return $this->_captcha_instance;
|
199 |
}
|
200 |
+
|
201 |
/**
|
202 |
* returns if recaptcha is required.
|
203 |
*
|
210 |
|
211 |
|
212 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
|
214 |
+
//////////////////////////////////
|
215 |
+
// Displaying
|
216 |
+
//
|
217 |
|
218 |
/**
|
219 |
* print recaptcha stylesheets
|
220 |
* hooks into `wp_head`
|
221 |
*/
|
222 |
+
function recaptcha_head( ) {
|
|
|
|
|
223 |
$this->begin_inject( );
|
224 |
+
$this->captcha_instance()->print_head();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
$this->end_inject( );
|
226 |
}
|
227 |
|
229 |
* Print recaptcha scripts
|
230 |
* hooks into `wp_footer`
|
231 |
*
|
|
|
232 |
*/
|
233 |
+
function recaptcha_foot( ) {
|
|
|
|
|
|
|
234 |
$this->begin_inject( );
|
235 |
+
|
236 |
// getting submit buttons of an elements form
|
237 |
if ( $this->get_option( 'recaptcha_disable_submit' ) ) {
|
238 |
?><script type="text/javascript">
|
260 |
}
|
261 |
</script><?php
|
262 |
}
|
263 |
+
$this->captcha_instance()->print_foot();
|
264 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
$this->end_inject( );
|
266 |
}
|
267 |
+
|
268 |
/**
|
269 |
* Print recaptcha HTML. Use inside a form.
|
270 |
*
|
|
|
271 |
*/
|
272 |
+
function print_recaptcha_html() {
|
273 |
+
echo $this->begin_inject( );
|
274 |
+
echo $this->recaptcha_html( );
|
275 |
+
echo $this->end_inject( );
|
276 |
}
|
277 |
|
278 |
/**
|
279 |
* Get recaptcha HTML.
|
280 |
*
|
|
|
281 |
* @return string recaptcha html
|
282 |
*/
|
283 |
+
function recaptcha_html( ) {
|
284 |
+
return $this->captcha_instance()->get_html();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
285 |
}
|
286 |
|
287 |
/**
|
288 |
+
* HTML comment with some notes (beginning)
|
289 |
+
*
|
290 |
+
* @param $return bool Whether to print or to return the comment
|
291 |
+
* @param $moretext string Additional information being included in the comment
|
292 |
+
* @return null|string HTML-Comment
|
293 |
*/
|
294 |
+
function begin_inject($return = false,$moretext='') {
|
295 |
+
$html = "\n<!-- BEGIN recaptcha, injected by plugin wp-recaptcha-integration $moretext -->\n";
|
296 |
+
if ( $return ) return $html;
|
297 |
+
echo $html;
|
298 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
299 |
/**
|
300 |
+
* HTML comment with some notes (ending)
|
301 |
+
*
|
302 |
+
* @param $return bool Whether to print or to return the comment
|
303 |
+
* @return null|string HTML-Comment
|
304 |
*/
|
305 |
+
function end_inject( $return = false ) {
|
306 |
+
$html = "\n<!-- END recaptcha -->\n";
|
307 |
+
if ( $return ) return $html;
|
308 |
+
echo $html;
|
|
|
|
|
309 |
}
|
310 |
|
311 |
/**
|
312 |
+
* Display recaptcha on comments form.
|
313 |
+
* filter function for `comment_form_defaults`
|
314 |
+
*
|
315 |
+
* @see filter doc `comment_form_defaults`
|
316 |
*/
|
317 |
+
function comment_form_defaults( $defaults ) {
|
318 |
+
$defaults['comment_notes_after'] .= '<p>' . $this->recaptcha_html() . '</p>';
|
319 |
+
return $defaults;
|
320 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
321 |
|
322 |
+
//////////////////////////////////
|
323 |
+
// Verification
|
324 |
+
//
|
325 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
326 |
/**
|
327 |
* Get last result of recaptcha check
|
328 |
* @return string recaptcha html
|
329 |
*/
|
330 |
function get_last_result() {
|
331 |
+
return $this->captcha_instance()->get_last_result();
|
332 |
}
|
333 |
|
334 |
/**
|
335 |
* Check recaptcha
|
336 |
*
|
|
|
337 |
* @return bool false if check does not validate
|
338 |
*/
|
339 |
+
function recaptcha_check( ) {
|
340 |
+
return $this->captcha_instance()->check();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
341 |
}
|
342 |
+
|
343 |
/**
|
344 |
+
* check recaptcha on login
|
345 |
+
* filter function for `wp_authenticate_user`
|
346 |
+
*
|
347 |
+
* @param $user WP_User
|
348 |
+
* @return object user or wp_error
|
349 |
*/
|
350 |
+
function deny_login( $user ) {
|
351 |
+
if ( isset( $_POST["log"]) )
|
352 |
+
$user = $this->wp_error( $user );
|
353 |
+
return $user;
|
354 |
+
}
|
355 |
+
|
356 |
+
/**
|
357 |
+
* check recaptcha on registration
|
358 |
+
* filter function for `registration_errors`
|
359 |
+
*
|
360 |
+
* @param $errors WP_Error
|
361 |
+
* @return WP_Error with captcha error added if test fails.
|
362 |
+
*/
|
363 |
+
function registration_errors( $errors ) {
|
364 |
+
if ( isset( $_POST["user_login"]) )
|
365 |
+
$errors = $this->wp_error_add( $errors );
|
366 |
+
return $errors;
|
367 |
+
}
|
368 |
+
|
369 |
+
/**
|
370 |
+
* check recaptcha WPMU signup
|
371 |
+
* filter function for `wpmu_validate_user_signup`
|
372 |
+
*
|
373 |
+
* @see filter hook `wpmu_validate_user_signup`
|
374 |
+
*/
|
375 |
+
function wpmu_validate_user_signup( $result ) {
|
376 |
+
if ( isset( $_POST['stage'] ) && $_POST['stage'] == 'validate-user-signup' )
|
377 |
+
$result['errors'] = $this->wp_error_add( $result['errors'] , 'generic' );
|
378 |
+
return $result;
|
379 |
+
}
|
380 |
+
|
381 |
+
|
382 |
+
/**
|
383 |
+
* check recaptcha and return WP_Error on failure.
|
384 |
+
* filter function for `allow_password_reset`
|
385 |
+
*
|
386 |
+
* @param $param mixed return value of funtion when captcha validates
|
387 |
+
* @return mixed will return argument $param an success, else WP_Error
|
388 |
+
*/
|
389 |
+
function wp_error( $param , $error_code = 'captcha_error' ) {
|
390 |
+
if ( ! $this->recaptcha_check() ) {
|
391 |
+
return new WP_Error( $error_code , __("<strong>Error:</strong> the Captcha didn’t verify.",'wp-recaptcha-integration') );
|
392 |
+
} else {
|
393 |
+
return $param;
|
394 |
}
|
|
|
395 |
}
|
396 |
/**
|
397 |
+
* check recaptcha and return WP_Error on failure.
|
398 |
+
* filter function for `allow_password_reset`
|
399 |
+
*
|
400 |
+
* @param $param mixed return value of funtion when captcha validates
|
401 |
+
* @return mixed will return argument $param an success, else WP_Error
|
402 |
*/
|
403 |
+
function wp_error_add( $param , $error_code = 'captcha_error' ) {
|
404 |
+
if ( ! $this->recaptcha_check() ) {
|
405 |
+
return new WP_Error( $error_code , __("<strong>Error:</strong> the Captcha didn’t verify.",'wp-recaptcha-integration') );
|
406 |
+
} else {
|
407 |
+
return $param;
|
408 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
409 |
}
|
410 |
|
411 |
+
/**
|
412 |
+
* Check recaptcha and wp_die() on fail
|
413 |
+
* hooks into `pre_comment_on_post`, `lostpassword_post`
|
414 |
+
*/
|
415 |
+
function recaptcha_check_or_die( ) {
|
416 |
+
if ( ! $this->recaptcha_check() ) {
|
417 |
+
$err = new WP_Error('comment_err', __("<strong>Error:</strong> the Captcha didn’t verify.",'wp-recaptcha-integration') );
|
418 |
+
wp_die( $err );
|
419 |
+
}
|
420 |
+
}
|
421 |
+
|
422 |
+
|
423 |
+
//////////////////////////////////
|
424 |
+
// Options
|
425 |
+
//
|
426 |
+
|
427 |
/**
|
428 |
* Get plugin option by name.
|
429 |
*
|
452 |
}
|
453 |
}
|
454 |
|
455 |
+
/**
|
456 |
+
* @return bool return if google api is configured
|
457 |
+
*/
|
458 |
+
function has_api_key() {
|
459 |
+
return $this->_has_api_key;
|
460 |
+
}
|
461 |
+
|
462 |
+
|
463 |
+
//////////////////////////////////
|
464 |
+
// Activation
|
465 |
+
//
|
466 |
+
|
467 |
/**
|
468 |
* Fired on plugin activation
|
469 |
*/
|
528 |
}
|
529 |
return self::$_is_network_activated;
|
530 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
531 |
|
532 |
|
533 |
+
|
534 |
+
|
535 |
+
//////////////////////////////////
|
536 |
+
// Language
|
537 |
+
//
|
538 |
+
|
539 |
/**
|
540 |
* Rewrite WP get_locale() to recaptcha lang param.
|
541 |
*
|
581 |
*
|
582 |
* @return array languages supported by recaptcha.
|
583 |
*/
|
584 |
+
function get_supported_languages( ) {
|
585 |
+
return $this->captcha_instance()->get_supported_languages();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
586 |
}
|
587 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
588 |
}
|
589 |
|
590 |
+
/**
|
591 |
+
* Autoload WPAA Classes
|
592 |
+
*
|
593 |
+
* @param string $classname
|
594 |
+
*/
|
595 |
+
function wp_recaptcha_integration_autoload( $classname ) {
|
596 |
+
$class_path = dirname(__FILE__). sprintf('/inc/class-%s.php' , strtolower( $classname ) ) ;
|
597 |
+
if ( file_exists($class_path) )
|
598 |
+
require_once $class_path;
|
599 |
+
}
|
600 |
+
spl_autoload_register( 'wp_recaptcha_integration_autoload' );
|
601 |
+
|
602 |
+
|
603 |
+
|
604 |
WP_reCaptcha::instance();
|
605 |
|
606 |
+
|
607 |
if ( is_admin() )
|
608 |
+
WP_reCaptcha_Options::instance();
|