-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcodepotent-registration-honeypot.php
70 lines (61 loc) · 2.83 KB
/
codepotent-registration-honeypot.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* -----------------------------------------------------------------------------
* Plugin Name: Registration Honeypot
* Description: Add a honeypot input to the ClassicPress registration form to prevent spambots from creating accounts.
* Version: 1.1.3
* Requires CP: 1.0
* Requires PHP: 5.6
* Author: Simone Fioravanti
* Author URI: https://software.gieffeedizioni.it
* Plugin URI: https://software.gieffeedizioni.it
* Text Domain: codepotent-registration-honeypot
* Domain Path: /languages
* -----------------------------------------------------------------------------
* This is free software released under the terms of the General Public License,
* version 2, or later. It is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Full
* text of the license is available at https://www.gnu.org/licenses/gpl-2.0.txt.
* -----------------------------------------------------------------------------
* Copyright 2021, John Alarcon (Code Potent)
* -----------------------------------------------------------------------------
* Adopted by Simone Fioravanti, 06/01/2021
* -----------------------------------------------------------------------------
*/
// Declare the namespace.
namespace CodePotent\RegistrationHoneypot;
// Prevent direct access.
if (!defined('ABSPATH')) {
die();
}
// Include constants file.
require_once(plugin_dir_path(__FILE__).'includes/constants.php');
// Include update client.
require_once(plugin_dir_path(__FILE__).'classes/UpdateClient.class.php');
// Enqueue Javascript.
add_action('login_footer', __NAMESPACE__.'\enqueue_login_script');
function enqueue_login_script() {
wp_enqueue_script('registration-extra', plugin_dir_url(__FILE__).'scripts/login.js', ['jquery']);
}
// Enqueue CSS.
add_action('login_enqueue_scripts', __NAMESPACE__.'\enqueue_login_style');
function enqueue_login_style() {
wp_enqueue_style('registration-extra', plugin_dir_url(__FILE__).'styles/login.css');
}
// Add honeypot input.
add_action('register_form', __NAMESPACE__.'\append_honeypot_input');
function append_honeypot_input() {
echo '<p class="register_additional">';
echo '<label for="register_additional">'.esc_html__('Leave this field empty.', 'codepotent-registration-honeypot').'</label><br />';
echo '<input type="text" name="register_additional" id="register_additional" value="" autocomplete="off" /></label>';
echo '</p>';
}
// Prevent spambot registrations.
add_action('register_post', __NAMESPACE__.'\check_honeypot_input', 0);
add_action('login_form_register', __NAMESPACE__.'\check_honeypot_input', 0);
function check_honeypot_input() {
if (empty($_POST['register_additional'])) { //phpcs:ignore WordPress.Security.NonceVerification.Missing
return;
}
wp_die(esc_html__('Automated registration is disabled.', 'codepotent-registration-honeypot'));
}