Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+5 votes
713 views
in Q2A Core by
Don't allow some usernames like admin administrator or my site name
by
I was thinking about this one as well, good idea.

1 Answer

+7 votes
by

This is quite easily done with a filter plugin. Here's an example similar to what I use on my site:

function filter_handle( &$handle, $olduser )
{
  // allow admins to have whatever name they like
  if ( qa_get_logged_in_level() > QA_USER_LEVEL_ADMIN )
    return null;

  if ( preg_match('/admin|sitename/i', $handle) )
     return 'Sorry, that username is not allowed.';

  return null;
}

That matches anything with "admin" or "sitename" anywhere in the handle. 

Hope that helps!

by
HI Scott,

can we add this sample to adjust ? :

if ( preg_match('/admin|sitename|administrator|moderator/i', $handle) )
     return 'Sorry, that username is not allowed.';

Thank you
Claude
by
Yes, but you don't need 'administrator' in there as 'admin' already matches that. It's matching each word anywhere in the username.

Instead of using preg_match you can just check for specific names, like
if ($handle == 'admin' || $handle == 'administrator')
by
Thank you very much Scott for you help
by
Thanks for this tip scott. I Appreciate.
by
Has anyone turned this into an actual plugin?  Even with the code sample above and the plugin documentation it looks pretty daunting.
...