Activity Stream
48,167 MEMBERS
6929 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 10 of 10
  1.     
    #1
    Member

    Default Wordpress username....

    Hi,

    Can someone please tell me that how can i limit the characters in the username of newly registered users ( on wordpress). Currently people can make as long of a username as they want and these are not going with my theme and things are looking messy.

    So if someone can tell me a little tweak or maybe a plugin, i'll be grateful.
    CloudShadow Reviewed by CloudShadow on . Wordpress username.... Hi, Can someone please tell me that how can i limit the characters in the username of newly registered users ( on wordpress). Currently people can make as long of a username as they want and these are not going with my theme and things are looking messy. So if someone can tell me a little tweak or maybe a plugin, i'll be grateful. Rating: 5

  2.   Sponsored Links

  3.     
    #2
    Banned
    Website's:
    google.com
    chk in database wp_usermeta

  4.     
    #3
    Too busy :|
    Website's:
    L337Fx.com BeastieBay.net

  5.     
    #4
    Banned
    Website's:
    google.com
    Changed the line in function validate_username( $username ) in wp-includes/registration.php, around line 25 for WP 2.2
    from:
    if ( $name != $username )
    to:
    if (($name != $username) || (strlen($username) > 10))
    It works.

  6.     
    #5
    Respected Member
    Website's:
    FreshWap.com KWWHunction.com
    First off lets look at the straightforward HTML file. We set up a form to hold our input fields, only the 'textarea' is used in this example.
    Here is the Html File which has the form we will use.

    PHP Code: 
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
        "http://www.w3.org/TR/html4/strict.dtd"
    >
    <
    html>
    <
    head>
        <
    title>maxchars</title>
        <
    script type="text/javascript" src="maxchars.js"></script>
        <link type="text/css" rel="stylesheet" href="maxchars.css">
    </head>
    <body>
        <div id="wrapper">
            <form id="myform" action="submit.php">
                <p><label for="name">Name</label>
                    <input type="text" name="name" id="name"></p>

                <p><label for="email">Email</label>
                    <input type="text" name="email" id="email"></p>

                <p><label for="msg">Message</label>
                    <textarea name="message" id="message" cols="50" 
                        rows="8" maxlength="50"></textarea>
                    <span id="limiter"></span></p>
            </form>
        </div>

    </body>
    </html> 
    The 'maxlength' attribute is deprecated, but for this example we will use it.
    That is all there is to the HTML, next we begin working with the Javascript.
    For this example we will 'wrap' the entire script into a master object, this is done to keep all variable self-contained and will not interfere with other scripts on the page.
    Here is the Javacript in full for all those copy & paste people.


    PHP Code: 
    var maxChars = {
            
    // cross-browser event handling for IE5+, NS6 and Mozilla 
            // By Scott Andrew 
        
    addEvent: function(elmevTypefnuseCapture) {
            if(
    elm.addEventListener) {
                
    elm.addEventListener(evTypefnuseCapture);
                return 
    true;
            } else if(
    elm.attachEvent) {
                var 
    elm.attachEvent('on' evTypefn);
                return 
    r;
            } else {
                
    elm['on' evType] = fn;
            }
        },

        
    attVal: function(elementattName) {
          return 
    parseInt(element.getAttribute(attName));
        },

        
    init: function() {
            if(!
    document.getElementsByTagName || !document.getElementById) {
                return;
            }
            
            
    maxChars.form document.getElementById('myform');
            
    maxChars.textarea document.getElementById('message');
            
    maxChars.maxlength maxChars.attVal(maxChars.textarea'maxlength');
            
    maxChars.limit_span document.getElementById('limiter');
            
    maxChars.limit_span.innerHTML '<strong>' maxChars.maxlength '</strong>' 
                
    ' characters remaining.';
            
            
    maxChars.addEvent(maxChars.textarea'keyup'maxChars.countlimitfalse);
        },

        
    countlimit: function(e) {
            var 
    placeholder;
            var 
    lengthleft maxChars.maxlength maxChars.textarea.value.length;

            if(
    && e.target) {
                
    placeholder e.target;
            }

            if(
    window.event && window.event.srcElement) {
                
    placeholder window.event.srcElement;
            }

            if(!
    placeholder) {
                return;
            } else if(
    lengthleft 0) {
                
    maxChars.textarea.value maxChars.textarea.value
                    
    .substring(0maxChars.maxlength);
            } else if(
    lengthleft 1) {
                
    maxChars.limit_span.innerHTML '<strong>' lengthleft '</strong>' 
                    
    ' characters remaining.';
            } else {
                
    maxChars.limit_span.innerHTML '<strong>' lengthleft '</strong>' 
                    
    ' character remaining.';
            }
        }

    }

    maxChars.addEvent(window'load'maxChars.initfalse); 
    Now lets run through the code to get an understanding of how it works.
    This is used to define the object and get things started


    PHP Code: 
    var maxChars = { 
    The initial function called when the page loads. Check to see if 'DOM' elements are available and if they aren't exit the script. We then grab the id of the form, textarea and span tag that display the remaining characters. The last step in this function is to set up a key listener event.

    PHP Code: 
    init: function() {
        if(!
    document.getElementsByTagName || !document.getElementById) {
            return;
        }
        
        
    maxChars.form document.getElementById('myform');
        
    maxChars.textarea document.getElementById('message');
        
    maxChars.maxlength maxChars.attVal(maxChars.textarea'maxlength');
        
    maxChars.limit_span document.getElementById('limiter');
        
    maxChars.limit_span.innerHTML '<strong>' maxChars.maxlength '</strong>' 
            
    ' characters remaining.';
        
        
    maxChars.addEvent(maxChars.textarea'keyup'maxChars.countlimitfalse);
    }, 
    For multiple browser support we will use a function to assign event listeners. IE uses on'eventname' where standards browsers use 'eventname'.

    PHP Code: 
    // cross-browser event handling for IE5+, NS6 and Mozilla 
    // By Scott Andrew 
    addEvent: function(elmevTypefnuseCapture) {
        if(
    elm.addEventListener) {
            
    elm.addEventListener(evTypefnuseCapture);
            return 
    true;
        } else if(
    elm.attachEvent) {
            var 
    elm.attachEvent('on' evTypefn);
            return 
    r;
        } else {
            
    elm['on' evType] = fn;
        }
    }, 
    This function will be used to get our 'deprecated' element later on in the script. It simply returns the value of the passed in element.


    PHP Code: 
    attVal: function(elementattName) {
      return 
    parseInt(element.getAttribute(attName));
    }, 
    Our last function in this script is to count and return the remaining characters.


    PHP Code: 
    countlimit: function(e) {
        var 
    placeholder;
        var 
    lengthleft maxChars.maxlength maxChars.textarea.value.length
    Check to see if the element is available. We use the tertiary condition to simply check for the event in a cross-broswer manner.


    PHP Code: 
        if(&& e.target) {
            
    placeholder e.target;
        }

        if(
    window.event && window.event.srcElement) {
            
    placeholder window.event.srcElement;
        } 
    Check to see if an event exists and if it does continue on with the rest of the script. If the remaining length is less than 0(zero) change the string to be grammatically correct


    PHP Code: 
        if(!placeholder) {
            return;
        } else if(
    lengthleft 0) {
            
    maxChars.textarea.value maxChars.textarea.value
                
    .substring(0maxChars.maxlength);
        } else if(
    lengthleft 1) {
            
    maxChars.limit_span.innerHTML '<strong>' lengthleft 
                
    '</strong>' ' characters remaining.';
        } else {
            
    maxChars.limit_span.innerHTML '<strong>' lengthleft 
                
    '</strong>' ' character remaining.';
        }

    Finally end the object


    PHP Code: 

    thanks
    Dear Haters,
    "I respect you so much, that's why I salute you with 1 middle finger!"

    Thank You !

  7.     
    #6
    Respected Member
    Website's:
    FreshWap.com KWWHunction.com
    or you can follow this simple method too

    -------------------------------------------------------------------------

    I?ve been working on a pretty complex project with WordPress MultiUser (soon to be MultiSite). This client needs several sites with hundreds of users divided into each site. I will be integrating the backend authentication with LDAP and discovered that a small percentage of their users have usernames with fewer than four characters.

    WordPress MU currently has a minimum limit of four characters set in its core. Unfortunately, this limit is still imposed in WordPress MS 3.0. The limit is probably there because usernames were used for the domain too and WP-Devs didn?t want to conflict with country codes. But that is not an issue for my client, so I wanted to kill the limit (without touching core).


    Basically, I wrote a quick mu-plugin that unset the error message when someone tries to add a user with fewer than four characters. Doing this removes any halts that would stop processing the new user. Here is my code:

    PHP Code: 
    function remove_username_char_limit($result) {
      if ( 
    is_wp_error$result'errors' ] ) && !empty( $result'errors' ]->errors ) ) {

        
    // Get all the error messages from $result
        
    $messages $result['errors']->get_error_messages();
        
    $i 0;
        foreach ( 
    $messages as $message ) {

          
    // Check if any message is the char limit message
          
    if ( == strcasecmp("Username must be at least 4 characters"$message)) {
            
    // Unset whole 'user_name' error array if only 1 message exists
            // and that message is the char limit error
            
    if ( == count($messages) ) {
              unset( 
    $result['errors']->errors['user_name'] );
            } else {
              
    // Otherwise just unset the char limit message
              
    unset( $result['errors']->errors['user_name'][$i] );
            }
          }    

          
    $i++;
        }
      }

      return 
    $result;
    }
    add_action('wpmu_validate_user_signup''remove_username_char_limit'); 
    enjoy
    Dear Haters,
    "I respect you so much, that's why I salute you with 1 middle finger!"

    Thank You !

  8.     
    #7
    Member
    @everyone

    I have already tried all the methods listed above( apart from CyberAff's). The one he posted is way too complex for such a simple thing, i'd rather not mess with so many things.


    EDIT:

    @Cyber

    The last method you posted is i think for removing the minimum character limit, rather than placing a maximum character one.

  9.     
    #8
    Banned
    Website's:
    google.com
    try this plugin simple and easy to use
    http://wordpress.org/extend/plugins/restrict-usernames/

  10.     
    #9
    Respected Member
    Website's:
    FreshWap.com KWWHunction.com
    Quote Originally Posted by CloudShadow View Post
    @everyone

    I have already tried all the methods listed above( apart from CyberAff's). The one he posted is way too complex for such a simple thing, i'd rather not mess with so many things.
    yes i know thats why i posted 2nd method see it and try to do it

    it will work

    thanks
    Dear Haters,
    "I respect you so much, that's why I salute you with 1 middle finger!"

    Thank You !

  11.     
    #10
    Member
    Quote Originally Posted by pioneer_fawad View Post
    try this plugin simple and easy to use
    http://wordpress.org/extend/plugins/restrict-usernames/
    I am already using this plugin, it restricts people from registering with specific username e.g with a foul word or something, it doesn't add a max character limit.

    The problem is that all the methods listed on sites are for older versions of WP, they dont work on WP 3.1.1

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Wordpress: Username Being cut in comment
    By CloudShadow in forum Wordpress
    Replies: 0
    Last Post: 16th Feb 2011, 03:09 PM
  2. how u came up with ur username ?
    By vizoomer in forum General Discussion
    Replies: 17
    Last Post: 13th Dec 2010, 09:12 PM

Tags for this Thread

BE SOCIAL