Allow caps letters for blog_url when signing up for a site.

Hi Ash i was wondering if the code snippet you gave on post https://premium.wpmudev.org/forums/topic/how-to-allow-user-to-signup-on-multisite-with-caps-letter#post-1206687 could be modified to do the same for the blog_url when signing up for a new site during registration? I want to convert to lowercase if the user iphone automatically makes it caps.

Thanks!

  • Vaughan

    Hi Jordan,

    Hope you're well?

    I haven't tried this, as by default WP only allows lowercase, and it builds the URL from the blog name.

    But can you try adding this function to a mu-plugin:

    <?php
    add_filter( 'newblogname', 'wpmudev_allow_upper_blogname' );
    function wpmudev_allow_upper_blogname($blogname) {
    	if ( preg_match( '/[^A-Za-z0-9]+/', $blogname ) ) {
    		return new WP_Error( 'blogname', __( 'Site names can only contain letters (a-z) and numbers.' ) );
    	}
    
        return strtolower($blogname);
    }

    Hope this helps

    Add this to a file called functions.php

    Then upload this file to /wp-content/mu-plugins/

    I haven't tested this, so it might not work as is.

  • jordan

    Thanks for the answer. I have been trying to implement it to perform the task i need. I have a question about the code you provided.

    First i see that the blogname is used but i want this to apply to blog_url.

    Second from the comments in the code, is it auto assigning the blogname or dos the user still need to enter a value?

    I have been trying to make blog_url automatically entered for the user. I have succeeded in doing so with buddypress signup form. When a user goes to the sign up form the blog-url is randomly and automatically assigned and that field is hidden for the sign up form. Now i am using Pro Sites and am trying to achieve the same thing or instead of a random url it could build the url from the Site Title field.

    In trying to understand your code would it help in what i am trying to achieve?

  • Ash

    Hello jordan

    Please try the following code:

    add_action( 'wp_footer', function() {
        ?>
        <script type="text/javascript">
        jQuery(function($) {
            $( '#blogname' ).keyup(function() {
                var val = $(this).val().toLowerCase();
                $(this).val(val);
            });
        });
        </script>
        <?php
    } );

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Hope it helps Please feel free to ask more question if you have any.

    Cheers
    Ash