• Resolved tabbis

    (@tabbis)


    I’m currently using this code snippet to stop users from registering with spaces in usernames. However, in 2.5.3 it causes a fatal error can anyone help?


    add_filter ( ‘sanitize_user’, ‘my_um_remove_user_spaces’, 10, 3); function my_um_remove_user_spaces( $username, $raw_username, $strict = false ) { if( strpos( trim( $username ), ‘ ‘ )) { UM()->form()->add_error( ‘user_login’, __( ‘You are not allowed to have spaces in your username.’, ‘ultimate-member’ ) ); } return $username; }

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Mykyta Synelnikov

    (@nsinelnikov)

    Hi @tabbis

    I think that better to use the code snippet below:

    function my_um_submit_form_errors_hook__registration( $args ) {
    	if ( isset( $args['user_login'] ) && false !== strpos( wp_unslash( trim( $args['user_login'] ) ), '' ) ) {
    		UM()->form()->add_error( 'user_login', __( 'You are not allowed to have spaces in your username.', 'ultimate-member' ) );
    	}
    }
    add_action( 'um_submit_form_errors_hook__registration', 'my_um_submit_form_errors_hook__registration', 11, 1 );

    Let me know if that works,
    Best Regards!

    Thread Starter tabbis

    (@tabbis)

    Hi thanks for your help unfortunaly this is not working and still allowes users to be registered with spaces in their usernames

    @tabbis

    You can try this code snippet instead with the space test updated:

    function my_um_submit_form_errors_hook__registration( $args ) {
    	if ( isset( $args['user_login'] ) && false !== strpos( wp_unslash( trim( $args['user_login'] ) ), ' ' ) ) {
    		UM()->form()->add_error( 'user_login', __( 'You are not allowed to have spaces in your username.', 'ultimate-member' ) );
    	}
    }
    add_action( 'um_submit_form_errors_hook__registration', 'my_um_submit_form_errors_hook__registration', 11, 1 );

    @tabbis — I was curious, have you encountered issues with allowing usernames with spaces, or is it just a stylistic preference, in your case?

    Plugin Author Mykyta Synelnikov

    (@nsinelnikov)

    Hi @tabbis

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread if any other questions come up and we’d be happy to help. ??

    Regards

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Username Spaces 2.5.3 Error’ is closed to new replies.