Comments on: Allow Hyphenated Usernames in WordPress Multisite https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/ Sun, 24 Jan 2021 19:10:15 +0000 hourly 1 https://wordpress.org/?v=6.6.2 By: call0fcode https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-767 Sun, 24 Jan 2021 19:10:15 +0000 https://christianvarga.com/?p=436#comment-767 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:


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;
}

...
}

Just change the regular expression to be: /[^-_a-z0-9]/

]]>
By: call0fcode https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-769 Sun, 24 Jan 2021 16:49:00 +0000 https://christianvarga.com/?p=436#comment-769 In reply to Christian Varga.

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! 😉

]]>
By: Christian Varga https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-768 Sun, 24 Jan 2021 15:16:32 +0000 https://christianvarga.com/?p=436#comment-768 In reply to call0fcode.

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?

]]>
By: Christian Jung https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-736 Thu, 03 Aug 2017 06:10:00 +0000 https://christianvarga.com/?p=436#comment-736 In reply to Christian Varga.

Awesome, that’s what i call a quick reaction. Thanks!

]]>
By: Christian Varga https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-735 Wed, 02 Aug 2017 17:44:00 +0000 https://christianvarga.com/?p=436#comment-735 In reply to Christian Jung.

Cheers for the info mate, the snippet has now been updated with the new translation string!

]]>
By: Christian Jung https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-734 Wed, 02 Aug 2017 13:30:00 +0000 https://christianvarga.com/?p=436#comment-734 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

]]>
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" version="2.0">
<channel>
<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>
<![CDATA[ call0fcode ]]>
</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&#039;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: &lt;code&gt; function wpmu_validate_user_signup( $user_name, $user_email ) { ... if ( $user_name != $orig_username &#124;&#124; preg_match( &#039;/[^-_a-z0-9]/&#039;, $user_name ) ) { $errors-&#062;add( &#039;user_name&#039;, __( &#039;Usernames can only contain lowercase letters (a-z), -, _ and numbers.&#039; ) ); $user_name = $orig_username; } ... } &lt;/code&gt; Just change the regular expression to be: /[^&lt;b&gt;-_&lt;/b&gt;a-z0-9]/ ]]>
</description>
<content:encoded>
<![CDATA[ <p>For those reading this on 2021.</p> <p>I&#8217;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-&gt;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>
<![CDATA[ call0fcode ]]>
</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 &lt;a href=&quot;https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-768&quot;&gt;Christian Varga&lt;/a&gt;. Didn&#039;t try it cause I&#039;m kinda newie working with WordPress, but I&#039;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&#8217;t try it cause I&#8217;m kinda newie working with WordPress, but I&#8217;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 &lt;a href=&quot;https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-767&quot;&gt;call0fcode&lt;/a&gt;. 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 &#8211; 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 &lt;a href=&quot;https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-735&quot;&gt;Christian Varga&lt;/a&gt;. Awesome, that&#039;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&#8217;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 &lt;a href=&quot;https://christianvarga.com/allow-hyphenated-usernames-wordpress-multisite/#comment-734&quot;&gt;Christian Jung&lt;/a&gt;. 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: __( &#039;Usernames can only contain lowercase letters (a-z) and numbers.&#039; ) 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>__( &#8216;Usernames can only contain lowercase letters (a-z) and numbers.&#8217; )</p> <p>Thanks,<br /> Christian</p> ]]>
</content:encoded>
</item>
</channel>
</rss>