reCAPTCHA - Version 1.4.1

Version Description

  • Support for WooCommerce's login form
Download this release

Release Info

Developer ash.matadeen
Plugin Icon wp plugin reCAPTCHA
Version 1.4.1
Comparing to
See all releases

Version 1.4.1

css/no-captcha.css ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ #loginform div.g-recaptcha {
2
+ margin: 10px 0 20px -15px;
3
+ }
no-captcha.php ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: reCAPTCHA
4
+ * Plugin URI: http://ashmatadeen.com
5
+ * Description: Adds Google's reCAPTCHA to WP's login form
6
+ * Author: Ash Matadeen
7
+ * Author URI: http://ashmatadeen.com
8
+ * Version: 1.4.1
9
+ */
10
+
11
+ add_action( 'admin_menu', 'wr_no_captcha_menu' );
12
+ add_action( 'admin_init', 'wr_no_captcha_display_options' );
13
+ add_action( 'login_enqueue_scripts', 'wr_no_captcha_login_form_script' );
14
+ add_action( 'login_enqueue_scripts', 'wr_no_captcha_css' );
15
+ add_action( 'login_form', 'wr_no_captcha_render_login_captcha' );
16
+ add_filter( 'wp_authenticate_user', 'wr_no_captcha_verify_login_captcha', 10, 2 );
17
+
18
+ // Specific support for WooCommerce login form
19
+ // Using WooCommerce specific hooks because
20
+ // WooCommerce's login form does not use the expected wp_login_form()
21
+ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
22
+ add_action( 'woocommerce_login_form', 'wr_no_captcha_render_login_captcha' );
23
+ add_action( 'wp_enqueue_scripts', 'wr_no_captcha_login_form_script' );
24
+ add_action( 'wp_enqueue_scripts', 'wr_no_captcha_css' );
25
+ }
26
+
27
+ function wr_no_captcha_menu() {
28
+ add_options_page( 'Google reCAPTCHA options', 'reCAPTCHA options', 'manage_options', 'recaptcha-options', 'wr_no_captcha_options_page' );
29
+ }
30
+
31
+ function wr_no_captcha_options_page() {
32
+ ?>
33
+ <h2>Google noCAPTCHA reCAPTCHA for WordPress</h2>
34
+
35
+ <div class="wrap">
36
+
37
+ <div id="icon-options-general" class="icon32"></div>
38
+
39
+ <div id="poststuff">
40
+
41
+ <div id="post-body" class="metabox-holder columns-2">
42
+
43
+ <!-- main content -->
44
+ <div id="post-body-content">
45
+
46
+ <div class="meta-box-sortables ui-sortable">
47
+
48
+ <div class="postbox">
49
+ <div class="inside">
50
+ <form method="post" action="options.php">
51
+ <?php
52
+ settings_fields( 'keys_section' );
53
+ do_settings_sections( 'recaptcha-options' );
54
+ submit_button();
55
+ ?>
56
+ </form>
57
+
58
+ <form method="post" action="options.php">
59
+ <?php
60
+ settings_fields( 'messages_section' );
61
+ do_settings_sections( 'recaptcha-text-options' );
62
+ submit_button();
63
+ ?>
64
+ </form>
65
+ </div>
66
+
67
+ </div>
68
+ <!-- .postbox -->
69
+
70
+ </div>
71
+ <!-- .meta-box-sortables .ui-sortable -->
72
+
73
+ </div>
74
+ <!-- post-body-content -->
75
+
76
+ <!-- sidebar -->
77
+ <div id="postbox-container-1" class="postbox-container">
78
+
79
+ <div class="meta-box-sortables">
80
+
81
+ <div class="postbox">
82
+
83
+ <h3>Support this plugin</h3>
84
+
85
+ <div class="inside">
86
+ <p>Click the donate button below to donate an amount of your choice to support the development of this plugin. All donations go straight to the plugin developer.</p>
87
+ <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
88
+ <input type="hidden" name="cmd" value="_donations">
89
+ <input type="hidden" name="business" value="ash@webblerock.com">
90
+ <input type="hidden" name="lc" value="GB">
91
+ <input type="hidden" name="item_name" value="Ash Matadeen">
92
+ <input type="hidden" name="item_number" value="no-captcha">
93
+ <input type="hidden" name="no_note" value="0">
94
+ <input type="hidden" name="currency_code" value="GBP">
95
+ <input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHostedGuest">
96
+ <input type="image" src="https://www.paypalobjects.com/en_GB/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online.">
97
+ <img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
98
+ </form>
99
+ </div>
100
+ <!-- .inside -->
101
+
102
+ </div>
103
+ <!-- .postbox -->
104
+
105
+ </div>
106
+ <!-- .meta-box-sortables -->
107
+
108
+ </div>
109
+ <!-- #postbox-container-1 .postbox-container -->
110
+
111
+ </div>
112
+ <!-- #post-body .metabox-holder .columns-2 -->
113
+
114
+ <br class="clear">
115
+ </div>
116
+ <!-- #poststuff -->
117
+
118
+ </div> <!-- .wrap -->
119
+ <?php
120
+ }
121
+
122
+ function wr_no_captcha_display_options() {
123
+ add_settings_section( 'keys_section', 'API Credentials', 'wr_no_captcha_display_recaptcha_api_content', 'recaptcha-options' );
124
+ add_settings_field( 'wr_no_captcha_site_key', 'Site key', 'wr_no_captcha_key_input', 'recaptcha-options', 'keys_section' );
125
+ add_settings_field( 'wr_no_captcha_secret_key', 'Secret Key', 'wr_no_captcha_secret_key_input', 'recaptcha-options', 'keys_section' );
126
+ register_setting( 'keys_section', 'wr_no_captcha_site_key' );
127
+ register_setting( 'keys_section', 'wr_no_captcha_secret_key' );
128
+
129
+ add_settings_section( 'messages_section', 'Custom error message', 'wr_no_captcha_display_recaptcha_error_message_content', 'recaptcha-text-options' );
130
+ add_settings_field( 'wr_no_captcha_error_message_text', 'Custom error message text', 'wr_no_captcha_error_message_input', 'recaptcha-text-options', 'messages_section' );
131
+ register_setting( 'messages_section', 'wr_no_captcha_error_message_text' );
132
+ }
133
+
134
+ function wr_no_captcha_display_recaptcha_error_message_content() {
135
+ echo "<p>You can set your own error message here for when the bot test fails:</p>";
136
+ }
137
+
138
+ function wr_no_captcha_error_message_input() {
139
+ echo '<input size="60" type="text" name="wr_no_captcha_error_message_text" id="wr_no_captcha_error_message_text" value="'. get_option( 'wr_no_captcha_error_message_text' ) . '" />';
140
+ }
141
+
142
+ function wr_no_captcha_display_recaptcha_api_content() {
143
+ echo '<p>Please <a href="https://www.google.com/recaptcha/admin">register you domain</a> with Google to obtain the API keys and enter them below.</p>';
144
+ }
145
+
146
+ function wr_no_captcha_key_input() {
147
+ echo '<input type="text" name="wr_no_captcha_site_key" id="captcha_site_key" value="'. get_option( 'wr_no_captcha_site_key' ) . '" />';
148
+ }
149
+
150
+ function wr_no_captcha_secret_key_input() {
151
+ echo '<input type="text" name="wr_no_captcha_secret_key" id="captcha_secret_key" value="' . get_option( 'wr_no_captcha_secret_key' ) . '" />';
152
+ }
153
+
154
+ function wr_no_captcha_login_form_script() {
155
+ wp_register_script( 'no_captcha_login', 'https://www.google.com/recaptcha/api.js' );
156
+ wp_enqueue_script( 'no_captcha_login' );
157
+ }
158
+
159
+ function wr_no_captcha_render_login_captcha() {
160
+ if ( wr_no_captcha_api_keys_set() ) {
161
+ echo '<div class="g-recaptcha" data-sitekey="' . get_option( 'wr_no_captcha_site_key' ) . '"></div>';
162
+ require_once( plugin_dir_path( __FILE__ ) . 'noscript/noscript.php');
163
+ }
164
+ }
165
+
166
+ function wr_no_captcha_verify_login_captcha($user, $password) {
167
+ if ( isset( $_POST['g-recaptcha-response'] ) ) {
168
+ $no_captcha_secret = get_option( 'wr_no_captcha_secret_key' );
169
+ $response = wp_remote_get( 'https://www.google.com/recaptcha/api/siteverify?secret=' . $no_captcha_secret . '&response=' . $_POST['g-recaptcha-response'] );
170
+ $response = json_decode( $response['body'], true );
171
+ if ( true === $response['success'] ) {
172
+ return $user;
173
+ } else {
174
+ return new WP_Error( 'Captcha Invalid', wr_no_captcha_get_error_message() );
175
+ }
176
+ } else if ( ! wr_no_captcha_api_keys_set() ) {
177
+ return $user;
178
+ }
179
+ }
180
+
181
+ function wr_no_captcha_css() {
182
+ $src = plugins_url( 'css/no-captcha.css', __FILE__ );
183
+ wp_enqueue_style( 'no_captcha_css', $src );
184
+ }
185
+
186
+ function wr_no_captcha_get_error_message() {
187
+ $custom_error = get_option( 'wr_no_captcha_error_message_text' );
188
+ if ( $custom_error ) {
189
+ return __( $custom_error );
190
+ } else {
191
+ return __( '<strong>Robot test error</strong>: I suggest a new strategy, R2, let the Wookie win.' );
192
+ }
193
+ }
194
+
195
+ function wr_no_captcha_api_keys_set() {
196
+ if ( get_option( 'wr_no_captcha_secret_key' ) && get_option( 'wr_no_captcha_site_key' ) ) {
197
+ return true;
198
+ } else {
199
+ return false;
200
+ }
201
+ }
noscript/noscript.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <noscript>
2
+ <div style="width: 302px; height: 495px; margin-bottom: 20px; margin-left: -15px;">
3
+ <div style="width: 302px; height: 425px; position: relative;">
4
+ <div style="width: 302px; height: 425px; position: absolute;">
5
+ <iframe src="https://www.google.com/recaptcha/api/fallback?k=<?php echo get_option( 'wr_no_captcha_site_key' ); ?>"
6
+ frameborder="0" scrolling="no"
7
+ style="width: 302px; height:425px; border-style: none;">
8
+ </iframe>
9
+ </div>
10
+ <div style="width: 300px; height: 60px; border-style: none;
11
+ bottom: 12px; left: 1px; margin: 0px; padding: 0px; right: 1px;
12
+ background: #f9f9f9; border: 1px solid #c1c1c1; border-radius: 3px; position: absolute; top: 435px;">
13
+ <textarea id="g-recaptcha-response" name="g-recaptcha-response"
14
+ class="g-recaptcha-response"
15
+ style="width: 250px; height: 40px; border: 1px solid #c1c1c1;
16
+ margin: 10px 25px; padding: 0px; resize: none;" ></textarea>
17
+ </div>
18
+ </div>
19
+ </div>
20
+ </noscript>
readme.txt ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Plugin Name ===
2
+ Contributors: ash.matadeen
3
+ Donate link: http://ashmatadeen.com/donate
4
+ Tags: security, bots, recaptcha, nocaptcha, google, login
5
+ Requires at least: 4.2.2
6
+ Tested up to: 4.6.1
7
+ Stable tag: trunk
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ Prevent brute force logins on your WordPress site with Google's reCAPTCHA.
12
+
13
+
14
+ == Description ==
15
+ This plugin prevents brute force logins on your WordPress website by adding Google's easy to use [reCAPTCHA](https://www.google.com/recaptcha/) to the login form.
16
+
17
+
18
+ == Installation ==
19
+
20
+ 1. Upload `no-captcha` to the `/wp-content/plugins/` directory
21
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
22
+ 3. Register your domain with [Google reCAPTCHA](https://www.google.com/recaptcha/admin)
23
+ 4. In the admin, go to Settings > reCAPTCHA options and add in your API credentials
24
+ 5. Click save
25
+ 6. Party! 🎉
26
+
27
+ == Screenshots ==
28
+
29
+ 1. WordPress login screen
30
+ 2. reCAPTCHA admin settings screen
31
+
32
+ == Changelog ==
33
+
34
+ = 1.4.1 =
35
+ * Support for WooCommerce's login form
36
+
37
+ = 1.4 =
38
+ * Bug fix for when JavaScript is disabled/not available
39
+
40
+ = 1.3 =
41
+ * Initial release
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file