Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Error reporting modification #1

Open
wants to merge 4 commits into from

2 participants

@dcavins

Switched the plugin over to using $bp->signup->errors instead of $result, because the original approach was registering an error, but wasn't stopping submission of the form. Tested under BP 1.6 & 1.7.

I'm not sure this is the best way, though, so I would appreciate your thoughts.

-David

@dcavins dcavins Changed error reporting
Switched the plugin over to using $bp->signup->errors instead of
$result, because the original approach was registering an error, but
wasn't stopping submission of the form.
e31c7f9
@dcavins

Oh, this is more complicated than I thought. On a vanilla BP install, your method allows WP_Errors to do its work on duplicate usernames/e-mail addresses and highlights those fields appropriately, but doesn't seem to prevent form submission/user creation. However, the method I proposed, which does prevent form submission, breaks WP_Errors, so duplicate usernames get a generic BP error message across the top of the form, which is not helpful. (There are several plugins that use the $bp->signup->errors style, and they all appear to break WP_Errors, at least with BP 1.7.)

Sorry for the complication.

@brandondove
Owner

Could that possibly be a bug in BP 1.7?

dcavins added some commits
@dcavins dcavins Used correct hook for user validation
Hook I used previously was emptying the WP_Errors array, which isn't a
good thing.
123737d
@dcavins dcavins Add correct hook c548856
@dcavins dcavins Error array output
Captures the error states behind-the-scenes of user validation in
BuddyPress with two version of the honeypot plugin.
0cec2a8
@dcavins

Hi Brandon-

I'm not really sure. 1.7's version of bp_core_validate_user_signup is pretty different than 1.6's. I did some testing to see what was actually happening with the error arrays behind the scenes, using a fresh user and a duplicate user to test error states. I've added that as a text file if you're interested in seeing the results.

Truthfully, the method you originally proposed seems perfect and mirrors the methods used in the new version of bp_core_validate_user_signup in 1.7, so I'm not sure why it's not stopping the registration process.

-David

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 28, 2013
  1. @dcavins

    Changed error reporting

    dcavins authored
    Switched the plugin over to using $bp->signup->errors instead of
    $result, because the original approach was registering an error, but
    wasn't stopping submission of the form.
Commits on Feb 5, 2013
  1. @dcavins

    Used correct hook for user validation

    dcavins authored
    Hook I used previously was emptying the WP_Errors array, which isn't a
    good thing.
  2. @dcavins

    Add correct hook

    dcavins authored
  3. @dcavins

    Error array output

    dcavins authored
    Captures the error states behind-the-scenes of user validation in
    BuddyPress with two version of the honeypot plugin.
This page is out of date. Refresh to see the latest.
Showing with 246 additions and 6 deletions.
  1. +5 −6 pj-buddypress-honeypot.php
  2. +241 −0 user-error-result.txt
View
11 pj-buddypress-honeypot.php
@@ -45,7 +45,7 @@ class pjbp_honeypot {
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_filter( 'bp_signup_validate', array( &$this, 'check_honeypot' ) );
}
/**
@@ -70,15 +70,14 @@ function add_honeypot() {
* @filter bppj_honeypot_name
* @filter bppj_honeypot_fail_message
*/
- function check_honeypot( $result = array() ) {
+ function check_honeypot() {
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;
+ if( isset( $_POST[$bppj_honeypot_name] ) && !empty( $_POST[$bppj_honeypot_name] ) )
+ $bp->signup->errors['pjbp_honeypot'] = __('Sorry, something went wrong with your registration','buddypress');
+
}
}
View
241 user-error-result.txt
@@ -0,0 +1,241 @@
+// Using the $result['errors']->add() method
+// Keeps username and e-mail address errors intact
+// Doesn't prevent registration completion under BP 1.7
+
+// Before bp_core_validate_user_signup filtering, new user
+Array
+(
+ [user_name] => smersh
+ [user_email] => smersh@mail.me
+ [errors] => WP_Error Object
+ (
+ [errors] => Array
+ (
+ )
+
+ [error_data] => Array
+ (
+ )
+
+ )
+
+)
+
+// After bp_core_validate_user_signup filtering, new user
+Array
+(
+ [user_name] => smersh
+ [user_email] => smersh@mail.me
+ [errors] => WP_Error Object
+ (
+ [errors] => Array
+ (
+ [pjbp_honeypot] => Array
+ (
+ [0] => You're totally a spammer. Go somewhere else with your spammy ways.
+ )
+
+ )
+
+ [error_data] => Array
+ (
+ )
+
+ )
+
+)
+
+// Before bp_core_validate_user_signup filtering, duplicated user
+Array
+(
+ [user_name] => smersh
+ [user_email] => smersh@mail.me
+ [errors] => WP_Error Object
+ (
+ [errors] => Array
+ (
+ [user_name] => Array
+ (
+ [0] => Sorry, that username already exists!
+ )
+
+ [user_email] => Array
+ (
+ [0] => Sorry, that email address is already used!
+ )
+
+ )
+
+ [error_data] => Array
+ (
+ )
+
+ )
+
+)
+
+// After bp_core_validate_user_signup filtering, duplicated user
+
+Array
+(
+ [user_name] => smersh
+ [user_email] => smersh@mail.me
+ [errors] => WP_Error Object
+ (
+ [errors] => Array
+ (
+ [user_name] => Array
+ (
+ [0] => Sorry, that username already exists!
+ )
+
+ [user_email] => Array
+ (
+ [0] => Sorry, that email address is already used!
+ )
+
+ [pjbp_honeypot] => Array
+ (
+ [0] => You're totally a spammer. Go somewhere else with your spammy ways.
+ )
+
+ )
+
+ [error_data] => Array
+ (
+ )
+
+ )
+
+)
+
+
+
+
+
+
+// Using the $bp->signup->errors method
+// Breaks display of username and e-mail address errors
+// Prevents registration completion under BP 1.7
+
+// Before bp_core_validate_user_signup filtering, new user
+WP_Error Array
+(
+ [user_name] => leonard
+ [user_email] => leonard@mail.me
+ [errors] => WP_Error Object
+ (
+ [errors] => Array
+ (
+ )
+
+ [error_data] => Array
+ (
+ )
+
+ )
+
+)
+
+// Before honeypot action, new user
+$bp->signup->errors
+(nothing written)
+
+// After bp_core_validate_user_signup filtering, new user
+WP_Error Array
+(
+ [user_name] => leonard
+ [user_email] => leonard@mail.me
+ [errors] => WP_Error Object
+ (
+ [errors] => Array
+ (
+ )
+
+ [error_data] => Array
+ (
+ )
+
+ )
+
+)
+
+// After honeypot action, new user
+$bp->signup->errors
+Array
+(
+ [pjbp_honeypot] => Sorry, something went wrong with your registration
+)
+
+// Before bp_core_validate_user_signup filtering, duplicate user
+WP_Error Array
+(
+ [user_name] => leonard
+ [user_email] => leonard@mail.me
+ [errors] => WP_Error Object
+ (
+ [errors] => Array
+ (
+ [user_name] => Array
+ (
+ [0] => Sorry, that username already exists!
+ )
+
+ [user_email] => Array
+ (
+ [0] => Sorry, that email address is already used!
+ )
+
+ )
+
+ [error_data] => Array
+ (
+ )
+
+ )
+
+)
+
+// Before honeypot, dupe user
+WP_Errors $bp->error Array
+(
+ [signup_username] => Sorry, that username already exists!
+ [signup_email] => Sorry, that email address is already used!
+)
+
+// After bp_core_validate_user_signup filtering, duplicate user
+ WP_Error Array
+(
+ [user_name] => leonard
+ [user_email] => leonard@mail.me
+ [errors] => WP_Error Object
+ (
+ [errors] => Array
+ (
+ [user_name] => Array
+ (
+ [0] => Sorry, that username already exists!
+ )
+
+ [user_email] => Array
+ (
+ [0] => Sorry, that email address is already used!
+ )
+
+ )
+
+ [error_data] => Array
+ (
+ )
+
+ )
+
+)
+
+// After honeypot, dupe user
+WP_Errors $bp->error Array
+(
+ [signup_username] => Sorry, that username already exists!
+ [signup_email] => Sorry, that email address is already used!
+ [pjbp_honeypot] => Sorry, something went wrong with your registration
+)
Something went wrong with that request. Please try again.