Results 1 to 10 of 10
-
8th Apr 2011, 03:47 AM #1OPMember
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
-
11th Apr 2011, 01:41 PM #2BannedWebsite's:
google.comchk in database wp_usermeta
-
11th Apr 2011, 01:42 PM #3Too busy :|Website's:
L337Fx.com BeastieBay.net
-
11th Apr 2011, 01:42 PM #4BannedWebsite's:
google.comChanged 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.
-
11th Apr 2011, 01:43 PM #5Respected MemberWebsite's:
FreshWap.com KWWHunction.comFirst 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>
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(elm, evType, fn, useCapture) {
if(elm.addEventListener) {
elm.addEventListener(evType, fn, useCapture);
return true;
} else if(elm.attachEvent) {
var r = elm.attachEvent('on' + evType, fn);
return r;
} else {
elm['on' + evType] = fn;
}
},
attVal: function(element, attName) {
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.countlimit, false);
},
countlimit: function(e) {
var placeholder;
var lengthleft = maxChars.maxlength - maxChars.textarea.value.length;
if(e && 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(0, maxChars.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.init, false);
This is used to define the object and get things started
PHP Code:var maxChars = {
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.countlimit, false);
},
PHP Code:// cross-browser event handling for IE5+, NS6 and Mozilla
// By Scott Andrew
addEvent: function(elm, evType, fn, useCapture) {
if(elm.addEventListener) {
elm.addEventListener(evType, fn, useCapture);
return true;
} else if(elm.attachEvent) {
var r = elm.attachEvent('on' + evType, fn);
return r;
} else {
elm['on' + evType] = fn;
}
},
PHP Code:attVal: function(element, attName) {
return parseInt(element.getAttribute(attName));
},
PHP Code:countlimit: function(e) {
var placeholder;
var lengthleft = maxChars.maxlength - maxChars.textarea.value.length;
PHP Code:if(e && e.target) {
placeholder = e.target;
}
if(window.event && window.event.srcElement) {
placeholder = window.event.srcElement;
}
PHP Code:if(!placeholder) {
return;
} else if(lengthleft < 0) {
maxChars.textarea.value = maxChars.textarea.value
.substring(0, maxChars.maxlength);
} else if(lengthleft > 1) {
maxChars.limit_span.innerHTML = '<strong>' + lengthleft
+ '</strong>' + ' characters remaining.';
} else {
maxChars.limit_span.innerHTML = '<strong>' + lengthleft
+ '</strong>' + ' character remaining.';
}
}
PHP Code:}
Dear Haters,
"I respect you so much, that's why I salute you with 1 middle finger!"
Thank You !
-
11th Apr 2011, 01:49 PM #6Respected MemberWebsite's:
FreshWap.com KWWHunction.comor 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 ( 0 == 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 ( 1 == 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');
Dear Haters,
"I respect you so much, that's why I salute you with 1 middle finger!"
Thank You !
-
11th Apr 2011, 01:50 PM #7OPMember
@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.
-
11th Apr 2011, 01:51 PM #8BannedWebsite's:
google.comtry this plugin simple and easy to use
http://wordpress.org/extend/plugins/restrict-usernames/
-
11th Apr 2011, 01:53 PM #9Respected MemberWebsite's:
FreshWap.com KWWHunction.com
-
11th Apr 2011, 01:58 PM #10OPMember
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
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Wordpress: Username Being cut in comment
By CloudShadow in forum WordpressReplies: 0Last Post: 16th Feb 2011, 03:09 PM -
how u came up with ur username ?
By vizoomer in forum General DiscussionReplies: 17Last Post: 13th Dec 2010, 09:12 PM
themaManager - edit and manage...
Version 4.04 released. Open older version (or...