{"id":78278,"date":"2012-05-21T12:00:40","date_gmt":"2012-05-21T16:00:40","guid":{"rendered":"http:\/\/wpmu.org\/?p=78278"},"modified":"2012-05-19T00:48:08","modified_gmt":"2012-05-19T04:48:08","slug":"how-to-restrict-usernames-and-disable-nicknames-in-wordpress","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/how-to-restrict-usernames-and-disable-nicknames-in-wordpress\/","title":{"rendered":"How to Restrict Usernames and Disable Nicknames in WordPress"},"content":{"rendered":"<p><a rel=\"lightbox[78278]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/how-to-restrict-usernames-and-disable-nicknames-in-wordpress\/trouble-big\/\" rel=\"attachment wp-att-78279\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78279\" title=\"trouble-big\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/05\/trouble-big.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"643\" height=\"406\" \/><\/a><br \/>\nIf you allow users to register for your site, then you may eventually get a few troublemakers that want to stir things up by using offensive usernames or wreak havoc by pretending to be part of site\u2019s staff (going by the username Admin or Help or Support, etc.).<\/p>\n<p>&nbsp;<\/p>\n<h2><strong>Restrict Usernames<\/strong><\/h2>\n<p>The first step you can take to stop this type of thing is to download and activate a plugin called <a href=\"http:\/\/wordpress.org\/extend\/plugins\/restrict-usernames\/\" target=\"_blank\">Restrict Usernames<\/a>.<\/p>\n<p>This plugin will allow you to restrict certain names from being registered (such as \u201cadmin\u201d) or even names that contain a restricted username (such as \u201cjoeadmin\u201d or \u201cHead Admin\u201d etc.). Of course you can also prohibit obscene words. (I&#8217;d give you some examples of those too, but I&#8217;m afraid I don&#8217;t know any.)<\/p>\n<p>Here\u2019s an example. I restricted the username \u201cadmin\u201d so that it couldn\u2019t be used as even part of username. And this is what someone trying to register a name with \u201cadmin\u201d in it sees.<\/p>\n<p><a rel=\"lightbox[78278]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/how-to-restrict-usernames-and-disable-nicknames-in-wordpress\/username-not-allowed\/\" rel=\"attachment wp-att-78281\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78281\" title=\"username-not-allowed\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/05\/username-not-allowed.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"701\" height=\"546\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Here\u2019s a list of some ideas from the plugin\u2019s author for what you might want to prevent or require in a username:<\/p>\n<ul>\n<li>Prevent usernames that contain foul, offensive, or otherwise undesired words<\/li>\n<li>Prevent squatting on usernames that you may want to use in the future (but don&#8217;t want to actually create the account for just yet) (essentially placing a hold on the username)<\/li>\n<li>Prevent official-sounding usernames from being used (i.e. help, support, pr, info, sales)<\/li>\n<li>Prevent official username syntax from being used (i.e. if all of your administrators use a prefix to identify themselves, you don&#8217;t want a visitor to use that prefix)<\/li>\n<li>Prevent spaces from being used in a username (which WordPress allows by default)<\/li>\n<li>Require that a username begin, end, or contain one of a set of substrings (i.e. &#8220;support_&#8221;, &#8220;admin_&#8221;)<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n\n<p>&nbsp;<\/p>\n<h2><strong>Disable Nicknames<\/strong><\/h2>\n<p>The Restrict Usernames plugin above does its job, but there\u2019s still one problem. Users can register with an innocuous username, and then they can change their nickname to anything they like on their profile page. It\u2019s their nickname that\u2019s seen on the public front end of the site, so in a way, that&#8217;s even more important than the username.<\/p>\n<p><a rel=\"lightbox[78278]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/how-to-restrict-usernames-and-disable-nicknames-in-wordpress\/nickname\/\" rel=\"attachment wp-att-78282\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78282\" title=\"nickname\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/05\/nickname.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"700\" height=\"455\" \/><\/a> I couldn\u2019t find a plugin to take care of this problem, but I did finally find <a href=\"http:\/\/wordpress.stackexchange.com\/questions\/32785\/how-to-remove-these-fields-from-the-profile-section\" target=\"_blank\">a snippet of code<\/a> you can put into your functions file. (Note: this snippet is adjusted slightly from the original source. Thanks to WPMU DEV developer Ve Bailovity.)<\/p>\n<p>Place the following code in your function.php file.<strong> (Appearance &gt; Editor &gt; Theme Functions \u2013 functions.php)<\/strong><\/p>\n<p>&nbsp;<\/p>\n<pre>\/\/ remove nickname\r\nfunction prefix_hide_personal_options() {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (current_user_can('manage_options')) return false;\r\n?&gt;\r\n&lt;script type=\"text\/javascript\"&gt;\r\n\u00a0 jQuery(document).ready(function( $ ){\r\n\u00a0\u00a0\u00a0 $(\"#nickname,#display_name\").parent().parent().remove();\r\n\u00a0 });\r\n&lt;\/script&gt;\r\n&lt;?php\r\n}\r\nif (is_admin()) add_action('personal_options', 'prefix_hide_personal_options');<\/pre>\n<p>&nbsp;<\/p>\n<p>Once you do this, you\u2019ll notice the nickname section disappears from the Profile page. The Administrator will still be able to see and edit nicknames, however.<\/p>\n<p><a rel=\"lightbox[78278]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/how-to-restrict-usernames-and-disable-nicknames-in-wordpress\/nickname-section-gone\/\" rel=\"attachment wp-att-78283\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78283\" title=\"nickname-section-gone\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/05\/nickname-section-gone.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"700\" height=\"318\" \/><\/a><\/p>\n<p>(Note: If you\u2019d like to turn this bit of code into your own personal plugin, you can <a href=\"https:\/\/wpmudev.com\/blog\/how-to-create-your-own-super-simple-wordpress-plugins\/\" target=\"_blank\">learn how to do that here<\/a>.)<\/p>\n<h2><strong>Protect the Integrity of Your Site<\/strong><\/h2>\n<p>Taking these two steps above (installing the plugin and including the code snippet) can help protect your site\u2019s integrity. Bots are trouble enough, but a human troublemaker can be creative and hard to stop.<br \/>\n<\/p>\n<p>Photo: <a href=\"http:\/\/www.bigstockphoto.com\/image-2853306\/stock-vector-business-concepts:-hello,-my-name-is\" target=\"_blank\">Business Concepts: Hello, My Name Is<\/a> from BigStock<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Prevent users from passing themselves off as administrators or using obscene handles.<\/p>\n","protected":false},"author":84404,"featured_media":78280,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[4],"tags":[300],"tutorials_categories":[],"class_list":["post-78278","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-plugins","tag-users"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/78278","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/84404"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=78278"}],"version-history":[{"count":1,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/78278\/revisions"}],"predecessor-version":[{"id":216214,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/78278\/revisions\/216214"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/78280"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=78278"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=78278"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=78278"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=78278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}