Prevent User from proceeding if they do not select a template

Hi,

I use the New Blog Templates plugin for my Multisite website. When the users do not select a template, e.g when they hit a 'return button' after they enter their site title and do not see the template selection, is there a way we can add some codes to prompt the user that he cannot proceed unless he select a template? If it is possible, can you advise the codes to add and how.

Thank you

Esther

  • Rupok

    Hi Esther,

    Thanks for asking. You can make your signup button disabled until your user select a blog template by creating a MU Plugin. For creating a MU Plugin, create a folder named "mu-plugins" inside your "wp-content" folder. Then inside that "mu-plugins" folder, create a file with any name and with a .php extension. Now paste the code inside that file and save.

    <?php
    add_action( 'wp_footer', 'disable_signup_button_wo_template' );
    function disable_signup_button_wo_template() {
        ?>
        <script type="text/javascript">
          jQuery(document).ready(function() {
    		jQuery('.blog_template-option select[name="blog_template"]').prepend("<option value='' selected='selected'>Please Select a Template</option>");
    		jQuery('#setupform input[value="Signup"]').prop('disabled', 'disabled');
    		jQuery('select').change(function(){
    		  jQuery('#setupform input[value="Signup"]').prop('disabled', false);
    		});
          });
        </script>
        <?php
    }

    For getting more idea on mu plugins, you can go through this article: http://premium.wpmudev.org/manuals/wpmu-manual-2/using-mu-plugins/

    Please Note, I've wrote this code assuming that you are using "As simple selection box" in New Blog Template Settings. If you are showing your blog templates in a different way, then this code won't work.

    Please let us know if it doesn't work or if you have any confusion. We will be glad to assist further.

    Have a nice day. Cheers!
    Rupok

  • Esther Goh Tok Mui

    Hi Rupok,

    Thank you very much and I really appreciate your help in providing me the code.

    I discovered that it works only when my network settings are set to ' Both sites and user accounts can be registered' . However, I need to have the network settings to allow only ' Logged in users may register new sites'. When I set it to the latter, the code did not work. The signup button is not disabled.

    I would need to have the New Blog Template settings set to 'As theme screenshot selection '.

    Would you be able to help me with the codes that will work for ' Logged in users may register new sites' and 'As theme screenshot selection ' settings, please?

    Thanks again for your kind help.

    Best Regards
    Esther

  • Kasia Swiderska

    Hello Esther,

    Have you tried to mark one of your templates as default one? Because when you do that in New Blog Templates that template will be automatically selected - so in fact there will be no need for any additional code for forcing template selection - because setting one of the template as default will already force that. On template list click "make a default" on one template and this one will be always pre-selected

    let me know what do you think

    kind regards,
    Kasia

  • Esther Goh Tok Mui

    Hi Kasia,

    Thank you very much. Yes! It works! However, there's something very strange. After the site is created and when I am provided with the site url to view, and I click on that link, it gives a 404 page. When I click back and click on the link again, the site appears beautifully. I tried registering another account and creating another site and repeat the above, again I am taken to 404 page and then when I try a second time it works. You can try registering for an account and a site here: https://iapps2u.com

    Regards
    Esther

  • Esther Goh Tok Mui

    Hi Kasia,

    After some troubleshooting, I discovered that when I took out the codes that limit to 1 blog per user, then it works perfectly. Otherwise, once I set the template to default and have the following codes which I got from the following support ticket : https://premium.wpmudev.org/forums/topic/multisite-only-allow-one-site-per-user
    I will get the 404 page. Not only that, all the sites previously registered with the template are also getting 404.

    function ds_one_blog_only($active_signup) {
    // get the array of the current user's blogs
    $blogs = get_blogs_of_user( get_current_user_id() );
    // all users may be members of blog 1 so remove it from the count, could be a "Dashboard" blog as well
    if ($blogs["1"]) unset($blogs["1"]);
    //if the user still has blogs, disable signup else continue with existing active_signup rules at SiteAdmin->Options
    $n = count($blogs);
    if($n == 1) {
    $active_signup = 'none';
    echo '';
    } elseif($n > 1) {
    $active_signup = 'none';
    echo '';
    } else {
    $active_signup = $active_signup;
    }
    return $active_signup; // return "all", "none", "blog" or "user"
    }
    add_filter('wpmu_active_signup', 'ds_one_blog_only');

    The above codes that limit 1 blog per user works very well previously, I have done almost 50 test sites creation and it was working perfectly. However, once I activate the blog template to be default, I will get 404 page problem.

    Esther

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.