Version Description
- Fix: Fatal error in settings
- Fix: messed up HTML comments
- Code: Put NinjaForms + CF7 handling into singletons
Download this release
Release Info
Developer | podpirate |
Plugin | WordPress ReCaptcha Integration |
Version | 1.0.7 |
Comparing to | |
See all releases |
Code changes from version 1.0.6 to 1.0.7
- inc/class-wp_recaptcha_contactform7.php +122 -0
- inc/class-wp_recaptcha_ninjaforms.php +129 -0
- inc/class-wp_recaptcha_nocaptcha.php +4 -7
- inc/class-wp_recaptcha_recaptcha.php +2 -2
- inc/contact_form_7_recaptcha.php +0 -83
- inc/ninja_forms_field_recaptcha.php +0 -101
- readme.txt +6 -1
- wp-recaptcha-integration.php +3 -3
inc/class-wp_recaptcha_contactform7.php
ADDED
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Class to manage ContactForm 7 Support
|
7 |
+
*/
|
8 |
+
class WP_reCaptcha_ContactForm7 {
|
9 |
+
/**
|
10 |
+
* Holding the singleton instance
|
11 |
+
*/
|
12 |
+
private static $_instance = null;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* @return WP_reCaptcha
|
16 |
+
*/
|
17 |
+
public static function instance(){
|
18 |
+
if ( is_null( self::$_instance ) )
|
19 |
+
self::$_instance = new self();
|
20 |
+
return self::$_instance;
|
21 |
+
}
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Prevent from creating more instances
|
25 |
+
*/
|
26 |
+
private function __clone() { }
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Prevent from creating more than one instance
|
30 |
+
*/
|
31 |
+
private function __construct() {
|
32 |
+
add_action( 'wpcf7_init', array( &$this , 'add_shortcode_recaptcha' ) );
|
33 |
+
add_action( 'wp_enqueue_scripts' , array( &$this , 'recaptcha_enqueue_script') );
|
34 |
+
add_action( 'admin_init', array( &$this , 'add_tag_generator_recaptcha' ), 45 );
|
35 |
+
add_filter( 'wpcf7_validate_recaptcha', array( &$this , 'recaptcha_validation_filter' ) , 10, 2 );
|
36 |
+
add_filter( 'wpcf7_validate_recaptcha*', array( &$this , 'recaptcha_validation_filter' ) , 10, 2 );
|
37 |
+
}
|
38 |
+
|
39 |
+
|
40 |
+
function add_shortcode_recaptcha() {
|
41 |
+
wpcf7_add_shortcode(
|
42 |
+
array( 'recaptcha','recaptcha*'),
|
43 |
+
array(&$this,'recaptcha_shortcode_handler'), true );
|
44 |
+
}
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
function recaptcha_shortcode_handler( $tag ) {
|
49 |
+
if ( ! WP_reCaptcha::instance()->is_required() )
|
50 |
+
return apply_filters( 'wp_recaptcha_disabled_html' ,'');
|
51 |
+
$tag = new WPCF7_Shortcode( $tag );
|
52 |
+
if ( empty( $tag->name ) )
|
53 |
+
return '';
|
54 |
+
|
55 |
+
$recaptcha_html = WP_reCaptcha::instance()->recaptcha_html();
|
56 |
+
$validation_error = wpcf7_get_validation_error( $tag->name );
|
57 |
+
|
58 |
+
$html = sprintf(
|
59 |
+
'<span class="wpcf7-form-control-wrap %1$s">%2$s %3$s</span>',
|
60 |
+
$tag->name, $recaptcha_html, $validation_error );
|
61 |
+
|
62 |
+
return $html;
|
63 |
+
}
|
64 |
+
|
65 |
+
function recaptcha_enqueue_script() {
|
66 |
+
wp_enqueue_script('wpcf7-recaptcha-integration',plugins_url('/js/wpcf7.js',dirname(__FILE__)),array('contact-form-7'));
|
67 |
+
}
|
68 |
+
|
69 |
+
|
70 |
+
|
71 |
+
function add_tag_generator_recaptcha() {
|
72 |
+
if ( ! function_exists( 'wpcf7_add_tag_generator' ) )
|
73 |
+
return;
|
74 |
+
wpcf7_add_tag_generator( 'recaptcha', __( 'reCAPTCHA', 'wp-recaptcha-integration' ),
|
75 |
+
'wpcf7-tg-pane-recaptcha', array(&$this,'recaptcha_settings_callback') );
|
76 |
+
}
|
77 |
+
|
78 |
+
|
79 |
+
|
80 |
+
function recaptcha_settings_callback( $contact_form ) {
|
81 |
+
$type = 'recaptcha';
|
82 |
+
|
83 |
+
?>
|
84 |
+
<div id="wpcf7-tg-pane-<?php echo $type; ?>" class="hidden">
|
85 |
+
<form action="">
|
86 |
+
<table>
|
87 |
+
<tr><td><input type="checkbox" checked="checked" disabled="disabled" name="required" onclick="return false" /> <?php echo esc_html( __( 'Required field?', 'contact-form-7' ) ); ?></td></tr>
|
88 |
+
<tr><td><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?><br /><input type="text" name="name" class="tg-name oneline" /></td><td></td></tr>
|
89 |
+
</table>
|
90 |
+
<div class="tg-tag">
|
91 |
+
<?php echo esc_html( __( "Copy this code and paste it into the form left.", 'contact-form-7' ) ); ?><br />
|
92 |
+
<input type="text" name="<?php echo $type; ?>" class="tag wp-ui-text-highlight code" readonly="readonly" onfocus="this.select()" />
|
93 |
+
</div>
|
94 |
+
</form>
|
95 |
+
</div>
|
96 |
+
<?php
|
97 |
+
}
|
98 |
+
|
99 |
+
|
100 |
+
|
101 |
+
function recaptcha_validation_filter( $result, $tag ) {
|
102 |
+
if ( ! WP_reCaptcha::instance()->is_required() )
|
103 |
+
return $result;
|
104 |
+
|
105 |
+
$tag = new WPCF7_Shortcode( $tag );
|
106 |
+
$name = $tag->name;
|
107 |
+
|
108 |
+
if ( ! WP_reCaptcha::instance()->recaptcha_check() ) {
|
109 |
+
$message = __("The Captcha didn’t verify.",'wp-recaptcha-integration');
|
110 |
+
if ( method_exists($result, 'invalidate' ) ) { // since CF7 4.1
|
111 |
+
$result->invalidate( $tag , $message );
|
112 |
+
} else {
|
113 |
+
$result['valid'] = false;
|
114 |
+
$result['reason'][$name] = $message;
|
115 |
+
}
|
116 |
+
}
|
117 |
+
return $result;
|
118 |
+
}
|
119 |
+
|
120 |
+
|
121 |
+
}
|
122 |
+
|
inc/class-wp_recaptcha_ninjaforms.php
ADDED
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class to manage NinjaForms Support
|
5 |
+
*/
|
6 |
+
class WP_reCaptcha_NinjaForms {
|
7 |
+
/**
|
8 |
+
* Holding the singleton instance
|
9 |
+
*/
|
10 |
+
private static $_instance = null;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* @return WP_reCaptcha
|
14 |
+
*/
|
15 |
+
public static function instance(){
|
16 |
+
if ( is_null( self::$_instance ) )
|
17 |
+
self::$_instance = new self();
|
18 |
+
return self::$_instance;
|
19 |
+
}
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Prevent from creating more instances
|
23 |
+
*/
|
24 |
+
private function __clone() { }
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Prevent from creating more than one instance
|
28 |
+
*/
|
29 |
+
private function __construct() {
|
30 |
+
add_action('init', array(&$this,'register_field_recaptcha'));
|
31 |
+
add_action('wp_footer',array(&$this,'recaptcha_script'),9999);
|
32 |
+
add_filter('ninja_forms_field',array(&$this,'recaptcha_field_data'),10,2);
|
33 |
+
}
|
34 |
+
function register_field_recaptcha(){
|
35 |
+
$args = array(
|
36 |
+
'name' => __( 'reCAPTCHA', 'wp-recaptcha-integration' ),
|
37 |
+
'edit_function' => '',
|
38 |
+
'display_function' => array( &$this , 'field_recaptcha_display' ),
|
39 |
+
'group' => 'standard_fields',
|
40 |
+
'edit_label' => true,
|
41 |
+
'edit_label_pos' => true,
|
42 |
+
'edit_req' => false,
|
43 |
+
'edit_custom_class' => false,
|
44 |
+
'edit_help' => true,
|
45 |
+
'edit_meta' => false,
|
46 |
+
'sidebar' => 'template_fields',
|
47 |
+
'display_label' => true,
|
48 |
+
'edit_conditional' => false,
|
49 |
+
'conditional' => array(
|
50 |
+
'value' => array(
|
51 |
+
'type' => 'text',
|
52 |
+
),
|
53 |
+
),
|
54 |
+
'pre_process' => array( &$this , 'field_recaptcha_pre_process' ),
|
55 |
+
'process_field' => false,
|
56 |
+
'limit' => 1,
|
57 |
+
'edit_options' => array(
|
58 |
+
),
|
59 |
+
'req' => true,
|
60 |
+
);
|
61 |
+
|
62 |
+
ninja_forms_register_field('_recaptcha', $args);
|
63 |
+
}
|
64 |
+
|
65 |
+
function recaptcha_field_data( $data, $field_id ) {
|
66 |
+
$field_row = ninja_forms_get_field_by_id($field_id);
|
67 |
+
if ( $field_row['type'] == '_recaptcha' )
|
68 |
+
$data['show_field'] = WP_reCaptcha::instance()->is_required();
|
69 |
+
return $data;
|
70 |
+
}
|
71 |
+
|
72 |
+
function recaptcha_script($id) {
|
73 |
+
/*
|
74 |
+
refresh captcha after form submission.
|
75 |
+
*/
|
76 |
+
$flavor = WP_reCaptcha::instance()->get_option( 'recaptcha_flavor' );
|
77 |
+
switch ( $flavor ) {
|
78 |
+
case 'recaptcha':
|
79 |
+
$html = '<script type="text/javascript">
|
80 |
+
// reload recaptcha after failed ajax form submit
|
81 |
+
jQuery(document).on("submitResponse.default", function(e, response){
|
82 |
+
Recaptcha.reload();
|
83 |
+
});
|
84 |
+
</script>';
|
85 |
+
break;
|
86 |
+
case 'grecaptcha':
|
87 |
+
$html = '<script type="text/javascript">
|
88 |
+
// reload recaptcha after failed ajax form submit
|
89 |
+
(function($){
|
90 |
+
$(document).on("submitResponse.default", function(e, response){
|
91 |
+
if ( grecaptcha ) {
|
92 |
+
var wid = $(\'#ninja_forms_form_\'+response.form_id).find(\'.g-recaptcha\').data(\'widget-id\');
|
93 |
+
grecaptcha.reset(wid);
|
94 |
+
}
|
95 |
+
});
|
96 |
+
})(jQuery);
|
97 |
+
</script>';
|
98 |
+
break;
|
99 |
+
}
|
100 |
+
WP_reCaptcha::instance()->begin_inject(false,', Ninja form integration');
|
101 |
+
echo $html;
|
102 |
+
WP_reCaptcha::instance()->end_inject();
|
103 |
+
}
|
104 |
+
|
105 |
+
function field_recaptcha_display($field_id, $data){
|
106 |
+
if ( WP_reCaptcha::instance()->is_required() )
|
107 |
+
WP_reCaptcha::instance()->print_recaptcha_html();
|
108 |
+
else
|
109 |
+
echo apply_filters( 'wp_recaptcha_disabled_html' ,'');
|
110 |
+
}
|
111 |
+
|
112 |
+
function field_recaptcha_pre_process( $field_id, $user_value ){
|
113 |
+
global $ninja_forms_processing;
|
114 |
+
$recaptcha_error = __("<strong>Error:</strong> the Captcha didn’t verify.",'wp-recaptcha-integration');
|
115 |
+
|
116 |
+
$field_row = ninja_forms_get_field_by_id($field_id);
|
117 |
+
$field_data = $field_row['data'];
|
118 |
+
$form_row = ninja_forms_get_form_by_field_id($field_id);
|
119 |
+
$form_id = $form_row['id'];
|
120 |
+
|
121 |
+
|
122 |
+
$require_recaptcha = WP_reCaptcha::instance()->is_required();
|
123 |
+
|
124 |
+
if ( $ninja_forms_processing->get_action() != 'save' && $ninja_forms_processing->get_action() != 'mp_save' && $require_recaptcha && ! WP_reCaptcha::instance()->recaptcha_check() ){
|
125 |
+
$ninja_forms_processing->add_error('recaptcha-general', $recaptcha_error, 'general');
|
126 |
+
$ninja_forms_processing->add_error('recaptcha-'.$field_id, $recaptcha_error, $field_id);
|
127 |
+
}
|
128 |
+
}
|
129 |
+
}
|
inc/class-wp_recaptcha_nocaptcha.php
CHANGED
@@ -7,7 +7,7 @@
|
|
7 |
*/
|
8 |
class WP_reCaptcha_NoCaptcha extends WP_reCaptcha_Captcha {
|
9 |
|
10 |
-
|
11 |
'ar' => 'Arabic',
|
12 |
'bg' => 'Bulgarian',
|
13 |
'ca' => 'Catalan',
|
@@ -96,9 +96,8 @@ class WP_reCaptcha_NoCaptcha extends WP_reCaptcha_Captcha {
|
|
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 |
-
|
101 |
-
<script type="text/javascript">
|
102 |
var recaptcha_widgets={};
|
103 |
function recaptchaLoadCallback(){
|
104 |
try {
|
@@ -137,9 +136,7 @@ class WP_reCaptcha_NoCaptcha extends WP_reCaptcha_Captcha {
|
|
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 |
|
7 |
*/
|
8 |
class WP_reCaptcha_NoCaptcha extends WP_reCaptcha_Captcha {
|
9 |
|
10 |
+
protected $supported_languages = array(
|
11 |
'ar' => 'Arabic',
|
12 |
'bg' => 'Bulgarian',
|
13 |
'ca' => 'Catalan',
|
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 |
+
?><script type="text/javascript">
|
|
|
101 |
var recaptcha_widgets={};
|
102 |
function recaptchaLoadCallback(){
|
103 |
try {
|
136 |
jQuery(document).ajaxComplete( recaptchaLoadCallback );
|
137 |
|
138 |
</script><?php
|
139 |
+
?><script src="https://www.google.com/recaptcha/api.js?onload=recaptchaLoadCallback&render=explicit<?php echo $language_param ?>" async defer></script><?php
|
|
|
|
|
140 |
}
|
141 |
|
142 |
|
inc/class-wp_recaptcha_recaptcha.php
CHANGED
@@ -7,7 +7,7 @@
|
|
7 |
*/
|
8 |
class WP_reCaptcha_ReCaptcha extends WP_reCaptcha_Captcha {
|
9 |
|
10 |
-
|
11 |
'en' => 'English',
|
12 |
'nl' => 'Dutch',
|
13 |
'fr' => 'French',
|
@@ -71,6 +71,7 @@ class WP_reCaptcha_ReCaptcha extends WP_reCaptcha_Captcha {
|
|
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') {
|
@@ -84,7 +85,6 @@ class WP_reCaptcha_ReCaptcha extends WP_reCaptcha_Captcha {
|
|
84 |
});
|
85 |
</script><?php
|
86 |
}
|
87 |
-
break;
|
88 |
}
|
89 |
public function get_html() {
|
90 |
$public_key = WP_reCaptcha::instance()->get_option( 'recaptcha_publickey' );
|
7 |
*/
|
8 |
class WP_reCaptcha_ReCaptcha extends WP_reCaptcha_Captcha {
|
9 |
|
10 |
+
protected $supported_languages = array(
|
11 |
'en' => 'English',
|
12 |
'nl' => 'Dutch',
|
13 |
'fr' => 'French',
|
71 |
}
|
72 |
public function print_foot() {
|
73 |
if ( WP_reCaptcha::instance()->get_option( 'recaptcha_disable_submit' ) ) {
|
74 |
+
|
75 |
?><script type="text/javascript">
|
76 |
document.addEventListener('keyup',function(e){
|
77 |
if (e.target && typeof e.target.getAttribute=='function' && e.target.getAttribute('ID')=='recaptcha_response_field') {
|
85 |
});
|
86 |
</script><?php
|
87 |
}
|
|
|
88 |
}
|
89 |
public function get_html() {
|
90 |
$public_key = WP_reCaptcha::instance()->get_option( 'recaptcha_publickey' );
|
inc/contact_form_7_recaptcha.php
DELETED
@@ -1,83 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
function wpcf7_add_shortcode_recaptcha() {
|
4 |
-
wpcf7_add_shortcode(
|
5 |
-
array( 'recaptcha','recaptcha*'),
|
6 |
-
'wpcf7_recaptcha_shortcode_handler', true );
|
7 |
-
}
|
8 |
-
add_action( 'wpcf7_init', 'wpcf7_add_shortcode_recaptcha' );
|
9 |
-
|
10 |
-
|
11 |
-
function wpcf7_recaptcha_shortcode_handler( $tag ) {
|
12 |
-
if ( ! WP_reCaptcha::instance()->is_required() )
|
13 |
-
return apply_filters( 'wp_recaptcha_disabled_html' ,'');
|
14 |
-
$tag = new WPCF7_Shortcode( $tag );
|
15 |
-
if ( empty( $tag->name ) )
|
16 |
-
return '';
|
17 |
-
|
18 |
-
$recaptcha_html = WP_reCaptcha::instance()->recaptcha_html();
|
19 |
-
$validation_error = wpcf7_get_validation_error( $tag->name );
|
20 |
-
|
21 |
-
$html = sprintf(
|
22 |
-
'<span class="wpcf7-form-control-wrap %1$s">%2$s %3$s</span>',
|
23 |
-
$tag->name, $recaptcha_html, $validation_error );
|
24 |
-
|
25 |
-
return $html;
|
26 |
-
}
|
27 |
-
|
28 |
-
function wpcf7_recaptcha_enqueue_script() {
|
29 |
-
wp_enqueue_script('wpcf7-recaptcha-integration',plugins_url('/js/wpcf7.js',dirname(__FILE__)),array('contact-form-7'));
|
30 |
-
}
|
31 |
-
add_action('wp_enqueue_scripts','wpcf7_recaptcha_enqueue_script');
|
32 |
-
|
33 |
-
function wpcf7_add_tag_generator_recaptcha() {
|
34 |
-
if ( ! function_exists( 'wpcf7_add_tag_generator' ) )
|
35 |
-
return;
|
36 |
-
wpcf7_add_tag_generator( 'recaptcha', __( 'reCAPTCHA', 'wp-recaptcha-integration' ),
|
37 |
-
'wpcf7-tg-pane-recaptcha', 'wpcf7_recaptcha_settings_callback' );
|
38 |
-
}
|
39 |
-
add_action( 'admin_init', 'wpcf7_add_tag_generator_recaptcha', 45 );
|
40 |
-
|
41 |
-
|
42 |
-
function wpcf7_recaptcha_settings_callback( $contact_form ) {
|
43 |
-
$type = 'recaptcha';
|
44 |
-
|
45 |
-
?>
|
46 |
-
<div id="wpcf7-tg-pane-<?php echo $type; ?>" class="hidden">
|
47 |
-
<form action="">
|
48 |
-
<table>
|
49 |
-
<tr><td><input type="checkbox" checked="checked" disabled="disabled" name="required" onclick="return false" /> <?php echo esc_html( __( 'Required field?', 'contact-form-7' ) ); ?></td></tr>
|
50 |
-
<tr><td><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?><br /><input type="text" name="name" class="tg-name oneline" /></td><td></td></tr>
|
51 |
-
</table>
|
52 |
-
<div class="tg-tag">
|
53 |
-
<?php echo esc_html( __( "Copy this code and paste it into the form left.", 'contact-form-7' ) ); ?><br />
|
54 |
-
<input type="text" name="<?php echo $type; ?>" class="tag wp-ui-text-highlight code" readonly="readonly" onfocus="this.select()" />
|
55 |
-
</div>
|
56 |
-
</form>
|
57 |
-
</div>
|
58 |
-
<?php
|
59 |
-
}
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
function wpcf7_recaptcha_validation_filter( $result, $tag ) {
|
65 |
-
if ( ! WP_reCaptcha::instance()->is_required() )
|
66 |
-
return $result;
|
67 |
-
|
68 |
-
$tag = new WPCF7_Shortcode( $tag );
|
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 |
-
}
|
82 |
-
add_filter( 'wpcf7_validate_recaptcha', 'wpcf7_recaptcha_validation_filter', 10, 2 );
|
83 |
-
add_filter( 'wpcf7_validate_recaptcha*', 'wpcf7_recaptcha_validation_filter', 10, 2 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inc/ninja_forms_field_recaptcha.php
DELETED
@@ -1,101 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
function ninja_forms_register_field_recaptcha(){
|
6 |
-
$args = array(
|
7 |
-
'name' => __( 'reCAPTCHA', 'wp-recaptcha-integration' ),
|
8 |
-
'edit_function' => '',
|
9 |
-
'display_function' => 'ninja_forms_field_recaptcha_display',
|
10 |
-
'group' => 'standard_fields',
|
11 |
-
'edit_label' => true,
|
12 |
-
'edit_label_pos' => true,
|
13 |
-
'edit_req' => false,
|
14 |
-
'edit_custom_class' => false,
|
15 |
-
'edit_help' => true,
|
16 |
-
'edit_meta' => false,
|
17 |
-
'sidebar' => 'template_fields',
|
18 |
-
'display_label' => true,
|
19 |
-
'edit_conditional' => false,
|
20 |
-
'conditional' => array(
|
21 |
-
'value' => array(
|
22 |
-
'type' => 'text',
|
23 |
-
),
|
24 |
-
),
|
25 |
-
'pre_process' => 'ninja_forms_field_recaptcha_pre_process',
|
26 |
-
'process_field' => false,
|
27 |
-
'limit' => 1,
|
28 |
-
'edit_options' => array(
|
29 |
-
),
|
30 |
-
'req' => true,
|
31 |
-
);
|
32 |
-
|
33 |
-
ninja_forms_register_field('_recaptcha', $args);
|
34 |
-
}
|
35 |
-
if ( function_exists('ninja_forms_register_field') ) {
|
36 |
-
add_action('init', 'ninja_forms_register_field_recaptcha');
|
37 |
-
add_action('wp_footer','ninja_forms_recaptcha_script',9999);
|
38 |
-
add_filter('ninja_forms_field','ninja_forms_recaptcha_field_data',10,2);
|
39 |
-
}
|
40 |
-
|
41 |
-
function ninja_forms_recaptcha_field_data( $data, $field_id ) {
|
42 |
-
$field_row = ninja_forms_get_field_by_id($field_id);
|
43 |
-
if ( $field_row['type'] == '_recaptcha' )
|
44 |
-
$data['show_field'] = WP_reCaptcha::instance()->is_required();
|
45 |
-
return $data;
|
46 |
-
}
|
47 |
-
|
48 |
-
function ninja_forms_recaptcha_script($id) {
|
49 |
-
$flavor = WP_reCaptcha::instance()->get_option( 'recaptcha_flavor' );
|
50 |
-
switch ( $flavor ) {
|
51 |
-
case 'recaptcha':
|
52 |
-
$html = '<script type="text/javascript">
|
53 |
-
// reload recaptcha after failed ajax form submit
|
54 |
-
jQuery(document).on("submitResponse.default", function(e, response){
|
55 |
-
Recaptcha.reload();
|
56 |
-
});
|
57 |
-
</script>';
|
58 |
-
break;
|
59 |
-
case 'grecaptcha':
|
60 |
-
$html = '<script type="text/javascript">
|
61 |
-
// reload recaptcha after failed ajax form submit
|
62 |
-
(function($){
|
63 |
-
$(document).on("submitResponse.default", function(e, response){
|
64 |
-
if ( grecaptcha ) {
|
65 |
-
var wid = $(\'#ninja_forms_form_\'+response.form_id).find(\'.g-recaptcha\').data(\'widget-id\');
|
66 |
-
grecaptcha.reset(wid);
|
67 |
-
}
|
68 |
-
});
|
69 |
-
})(jQuery);
|
70 |
-
</script>';
|
71 |
-
break;
|
72 |
-
}
|
73 |
-
WP_reCaptcha::instance()->begin_inject(false,', Ninja form integration');
|
74 |
-
echo $html;
|
75 |
-
WP_reCaptcha::instance()->end_inject();
|
76 |
-
}
|
77 |
-
|
78 |
-
function ninja_forms_field_recaptcha_display($field_id, $data){
|
79 |
-
if ( WP_reCaptcha::instance()->is_required() )
|
80 |
-
WP_reCaptcha::instance()->print_recaptcha_html();
|
81 |
-
else
|
82 |
-
echo apply_filters( 'wp_recaptcha_disabled_html' ,'');
|
83 |
-
}
|
84 |
-
|
85 |
-
function ninja_forms_field_recaptcha_pre_process( $field_id, $user_value ){
|
86 |
-
global $ninja_forms_processing;
|
87 |
-
$recaptcha_error = __("<strong>Error:</strong> the Captcha didn’t verify.",'wp-recaptcha-integration');
|
88 |
-
|
89 |
-
$field_row = ninja_forms_get_field_by_id($field_id);
|
90 |
-
$field_data = $field_row['data'];
|
91 |
-
$form_row = ninja_forms_get_form_by_field_id($field_id);
|
92 |
-
$form_id = $form_row['id'];
|
93 |
-
|
94 |
-
|
95 |
-
$require_recaptcha = WP_reCaptcha::instance()->is_required();
|
96 |
-
|
97 |
-
if ( $ninja_forms_processing->get_action() != 'save' && $ninja_forms_processing->get_action() != 'mp_save' && $require_recaptcha && ! WP_reCaptcha::instance()->recaptcha_check() ){
|
98 |
-
$ninja_forms_processing->add_error('recaptcha-general', $recaptcha_error, 'general');
|
99 |
-
$ninja_forms_processing->add_error('recaptcha-'.$field_id, $recaptcha_error, $field_id);
|
100 |
-
}
|
101 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,11 @@ I will migrate all the translation stuff there.
|
|
144 |
|
145 |
== Changelog ==
|
146 |
|
|
|
|
|
|
|
|
|
|
|
147 |
= 1.0.6 =
|
148 |
- Code: separate classes for recaptcha / nocaptcha
|
149 |
- Code: Class autoloader
|
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.7
|
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.7 =
|
148 |
+
- Fix: Fatal error in settings
|
149 |
+
- Fix: messed up HTML comments
|
150 |
+
- Code: Put NinjaForms + CF7 handling into singletons
|
151 |
+
|
152 |
= 1.0.6 =
|
153 |
- Code: separate classes for recaptcha / nocaptcha
|
154 |
- Code: Class autoloader
|
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 |
*/
|
@@ -113,12 +113,12 @@ class WP_reCaptcha {
|
|
113 |
// NinjaForms support
|
114 |
// check if ninja forms is present
|
115 |
if ( class_exists('Ninja_Forms') || function_exists('ninja_forms_register_field') )
|
116 |
-
|
117 |
|
118 |
// CF7 support
|
119 |
// check if contact form 7 forms is present
|
120 |
if ( function_exists('wpcf7') )
|
121 |
-
|
122 |
|
123 |
// WooCommerce support
|
124 |
// check if woocommerce is present
|
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
|
7 |
Author: Jörn Lund
|
8 |
Author URI: https://github.com/mcguffin/
|
9 |
*/
|
113 |
// NinjaForms support
|
114 |
// check if ninja forms is present
|
115 |
if ( class_exists('Ninja_Forms') || function_exists('ninja_forms_register_field') )
|
116 |
+
WP_reCaptcha_NinjaForms::instance();
|
117 |
|
118 |
// CF7 support
|
119 |
// check if contact form 7 forms is present
|
120 |
if ( function_exists('wpcf7') )
|
121 |
+
WP_reCaptcha_ContactForm7::instance();
|
122 |
|
123 |
// WooCommerce support
|
124 |
// check if woocommerce is present
|