forked from pixeljar/BuddyPress-Honeypot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpj-buddypress-honeypot.php
85 lines (73 loc) · 2.74 KB
/
pj-buddypress-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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/*
Plugin Name: Pixel Jar BuddyPress Honeypot
Plugin URI: http://pixeljar.net/buddypress-honeypot
Description: Simple plugin to add a honeypot to the BuddyPress registration form to prevent spam registrations.
Version: 1.1
Author: Pixel Jar
Author URI: http://pixeljar.net
*/
/**
* Copyright (c) 2012 Pixel Jar. All rights reserved.
*
* Released under the GPL license
* http://www.opensource.org/licenses/gpl-license.php
*
* This is an add-on for WordPress
* http://wordpress.org/
*
* **********************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* **********************************************************************
*/
// INTERNATIONALIZATION
load_plugin_textdomain( 'pj-buddypress-honeypot', null, basename( dirname( __FILE__ ) ) );
class pjbp_honeypot {
/**
* default values for the honeypot
* change these via filters if you
* start getting spam registrations
*/
CONST BPPJ_HONEYPOT_NAME = 'oh_no_you_dint';
CONST BPPJ_HONEYPOT_ID = 'sucka';
function __construct() {
add_action( 'bp_after_signup_profile_fields', array( &$this, 'add_honeypot' ) );
add_filter( 'bp_core_validate_user_signup', array( &$this, 'check_honeypot' ) );
}
/**
* Add a hidden text input that users won't see
* so it should always be empty. If it's filled out
* we know it's a spambot or some other hooligan
*
* @filter bppj_honeypot_name
* @filter bppj_honeypot_id
*/
function add_honeypot() {
echo '<div style="display: none;">';
echo '<input type="text" name="'.apply_filters( 'bppj_honeypot_name', self::BPPJ_HONEYPOT_NAME ).'" id="'.apply_filters( 'bppj_honeypot_id', self::BPPJ_HONEYPOT_ID ).'" />';
echo '</div>';
}
/**
* Check to see if the honeypot field has a value.
* If it does, return an error
*
* @filter bppj_honeypot_name
* @filter bppj_honeypot_fail_message
*/
function check_honeypot( $result = array() ) {
global $bp;
$bppj_honeypot_name = apply_filters( 'bppj_honeypot_name', self::BPPJ_HONEYPOT_NAME );
if( isset( $_POST[$bppj_honeypot_name] ) && !empty( $_POST[$bppj_honeypot_name] ) )
$result['errors']->add( 'pjbp_honeypot', apply_filters( 'bppj_honeypot_fail_message', __( "You're totally a spammer. Go somewhere else with your spammy ways." ) ) );
return $result;
}
}
new pjbp_honeypot;