Skip to:

Clear WP Errors at Signup

  • rhysewest


    Hi all,

    I have customized the way Buddypress registers members by checking to see if the Display Name already exists. If a Display Name is found, I create a new WP error. The problem is, once the user changes their Display Name to something that isn’t found, the error persists when you get the success signup screen. I’ve tried manually clearing it, but not getting any results.

    A few details:

    Wordpress Version: 4.7.1
    Buddypress Version: 2.7.4

    I’d like to keep my site anonymous if that’s ok.

    Here is what I’ve done in the php files to achieve this:


    public static function add_backcompat( $user_login = '', $user_password = '', $user_email = '', $usermeta = array() ) {
        global $wpdb;
        $display_capture = sanitize_title($usermeta["field_1"]); //CUSTOM CODE
        $display_capture = ucfirst(strtolower($display_capture)); //CUSTOM CODE
        $user_id = wp_insert_user( array(
        'user_login'   => $user_login,
        'user_pass'    => $user_password,
        'display_name' => $display_capture, //CUSTOM CODE
        'user_email'   => $user_email
         ) );


    function wp_insert_user( $userdata ) {
        global $wpdb;
        Lots of code before here...
        if ( empty( $userdata['display_name'] ) ) {
    	if ( $update ) {
    	    $display_name = $user_login;
    	} elseif ( $meta['first_name'] && $meta['last_name'] ) {
    	    /* translators: 1: first name, 2: last name */
    	    $display_name = sprintf( _x( '%1$s %2$s', 'Display name based on first name and last name' ), $meta['first_name'], $meta['last_name'] );
    	} elseif ( $meta['first_name'] ) {
    	    $display_name = $meta['first_name'];
    	} elseif ( $meta['last_name'] ) {
    	    $display_name = $meta['last_name'];
    	} else {
    	    $display_name = $user_login;
        } else {
    	$display_name = $userdata['display_name'];
        //CUSTOM CODE
        $display_name = ucfirst(strtolower($display_name));
        $display_name_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE display_name = %s AND user_login != %s LIMIT 1" , $display_name, $user_login));
        if($display_name_check) {
    	return new WP_Error( 'existing_display_name', __( 'Sorry, that display name already exists!' ) );
        Lots of code after here...

    This successfully checks for the existence of a display name already in the database. It displays an error like it should and doesn’t allow the user to register. Now the only issue, how to clear the error when the user changes the display name to something not in the database?

    As stated earlier, once the error occurs, it will persist through to the success message. I’ve confirmed that the error does not occur if the user selects a display name not currently being used on the first registration attempt.

    I appreciate your time and help, thank you.

  • You must be logged in to reply to this topic.
Skip to toolbar