<title>
Comments on: Allow Hyphenated Usernames in WordPress Multisite </title>
<atom:link href="https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/feed/" rel="self" type="application/rss+xml"/>
<link>https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/</link>
<description/>
<lastBuildDate>Sun, 24 Jan 2021 19:10:15 +0000</lastBuildDate>
<sy:updatePeriod>
hourly </sy:updatePeriod>
<sy:updateFrequency>
1 </sy:updateFrequency>
<generator>https://wordpress.org/?v=6.6.2</generator>
<item>
<title>
By: call0fcode </title>
<link>https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-767</link>
<dc:creator>
...</dc:creator>
<pubDate>Sun, 24 Jan 2021 19:10:15 +0000</pubDate>
<guid isPermaLink="false">https://christianvarga.com/?p=436#comment-767</guid>
<description>
<![CDATA[ For those reading this on 2021.
I'm creating a multisite on WordPress 5.6 and I could allow hyphenated usernames by changing the following on the original wpmu_validate_user_signup function in wp-includes/ms-functions.php:
<code>
function wpmu_validate_user_signup( $user_name, $user_email ) {
...
if ( $user_name != $orig_username || preg_match( '/[^-_a-z0-9]/', $user_name ) ) {
$errors->add( 'user_name', __( 'Usernames can only contain lowercase letters (a-z), -, _ and numbers.' ) );
$user_name = $orig_username;
}
...
}
</code>
Just change the regular expression to be: /[^<b>-_</b>a-z0-9]/ ]]>
...</description>
<content:encoded>
<![CDATA[ <p>For those reading this on 2021.</p>
<p>I’m creating a multisite on WordPress 5.6 and I could allow hyphenated usernames by changing the following on the original wpmu_validate_user_signup function in wp-includes/ms-functions.php:</p>
<p><code><br />
function wpmu_validate_user_signup( $user_name, $user_email ) {<br />
...</p>
<p> if ( $user_name != $orig_username || preg_match( '/[^-_a-z0-9]/', $user_name ) ) {<br />
$errors->add( 'user_name', __( 'Usernames can only contain lowercase letters (a-z), -, _ and numbers.' ) );<br />
$user_name = $orig_username;<br />
}</p>
<p> ...<br />
}<br />
</code></p>
<p>Just change the regular expression to be: /[^<b>-_</b>a-z0-9]/</p>
]]>
...</content:encoded>
...</item>
<item>
<title>
By: call0fcode </title>
<link>https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-769</link>
<dc:creator>
...</dc:creator>
<pubDate>Sun, 24 Jan 2021 16:49:00 +0000</pubDate>
<guid isPermaLink="false">https://christianvarga.com/?p=436#comment-769</guid>
<description>
<![CDATA[ In reply to <a href="https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-768">Christian Varga</a>.
Didn't try it cause I'm kinda newie working with WordPress, but I'm going to do a research and change code correspondingly. It makes sense what you say that the WordPress core may be changed in coming versions and thus the changed functionality. Thanks for the tip! ;) ]]>
...</description>
<content:encoded>
<![CDATA[ <p>In reply to <a href="https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-768">Christian Varga</a>.</p>
<p>Didn’t try it cause I’m kinda newie working with WordPress, but I’m going to do a research and change code correspondingly. It makes sense what you say that the WordPress core may be changed in coming versions and thus the changed functionality. Thanks for the tip! 😉</p>
]]>
...</content:encoded>
...</item>
<item>
<title>
By: Christian Varga </title>
<link>https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-768</link>
<dc:creator>
<![CDATA[ Christian Varga ]]>
...</dc:creator>
<pubDate>Sun, 24 Jan 2021 15:16:32 +0000</pubDate>
<guid isPermaLink="false">https://christianvarga.com/?p=436#comment-768</guid>
<description>
<![CDATA[ In reply to <a href="https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-767">call0fcode</a>.
It isn’t really safe to change code in wp-includes as Wordpress may update core code automatically at any time. Also it might not be possible for people running managed installations.
The safest way to modify behaviour is via hooks - does the hook not work in 5.6? ]]>
...</description>
<content:encoded>
<![CDATA[ <p>In reply to <a href="https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-767">call0fcode</a>.</p>
<p>It isn’t really safe to change code in wp-includes as WordPress may update core code automatically at any time. Also it might not be possible for people running managed installations. </p>
<p>The safest way to modify behaviour is via hooks – does the hook not work in 5.6?</p>
]]>
...</content:encoded>
...</item>
<item>
<title>
By: Christian Jung </title>
<link>https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-736</link>
<dc:creator>
<![CDATA[ Christian Jung ]]>
...</dc:creator>
<pubDate>Thu, 03 Aug 2017 06:10:00 +0000</pubDate>
<guid isPermaLink="false">https://christianvarga.com/?p=436#comment-736</guid>
<description>
<![CDATA[ In reply to <a href="https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-735">Christian Varga</a>.
Awesome, that's what i call a quick reaction. Thanks! ]]>
...</description>
<content:encoded>
<![CDATA[ <p>In reply to <a href="https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-735">Christian Varga</a>.</p>
<p>Awesome, that’s what i call a quick reaction. Thanks!</p>
]]>
...</content:encoded>
...</item>
<item>
<title>
By: Christian Varga </title>
<link>https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-735</link>
<dc:creator>
<![CDATA[ Christian Varga ]]>
...</dc:creator>
<pubDate>Wed, 02 Aug 2017 17:44:00 +0000</pubDate>
<guid isPermaLink="false">https://christianvarga.com/?p=436#comment-735</guid>
<description>
<![CDATA[ In reply to <a href="https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-734">Christian Jung</a>.
Cheers for the info mate, the snippet has now been updated with the new translation string! ]]>
...</description>
<content:encoded>
<![CDATA[ <p>In reply to <a href="https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-734">Christian Jung</a>.</p>
<p>Cheers for the info mate, the snippet has now been updated with the new translation string!</p>
]]>
...</content:encoded>
...</item>
<item>
<title>
By: Christian Jung </title>
<link>https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-734</link>
<dc:creator>
<![CDATA[ Christian Jung ]]>
...</dc:creator>
<pubDate>Wed, 02 Aug 2017 13:30:00 +0000</pubDate>
<guid isPermaLink="false">https://christianvarga.com/?p=436#comment-734</guid>
<description>
<![CDATA[ Just wanted to note: Still works fine, as soon as you change the translated text to the new wording in https://core.trac.wordpress.org/browser/tags/4.8/src/wp-includes/ms-functions.php#L420, which is:
__( 'Usernames can only contain lowercase letters (a-z) and numbers.' )
Thanks,
Christian ]]>
...</description>
<content:encoded>
<![CDATA[ <p>Just wanted to note: Still works fine, as soon as you change the translated text to the new wording in <a href="https://core.trac.wordpress.org/browser/tags/4.8/src/wp-includes/ms-functions.php#L420" rel="nofollow ugc">https://core.trac.wordpress.org/browser/tags/4.8/src/wp-includes/ms-functions.php#L420</a>, which is:</p>
<p>__( ‘Usernames can only contain lowercase letters (a-z) and numbers.’ )</p>
<p>Thanks,<br />
Christian</p>
]]>
...</content:encoded>
...</item>