BUG – jquery.validate.js only loads when user logged in

To one and all,

I believe this is a bug.

I am using the following shortcode in a separate page to register a specific membership. This page is not associated as the ‘Register’ page in Membership 2 -> Settings.

[ms-membership-register-user title=”” label_register=”Register a Pro-Rata Membership” membership_id=”4621″]

It loads jquery.validate.js properly when logged in using the same browser. However, I get a jQuery(…:wink:.validate is not a function when not logged in. This is because jquery.validate.js is not being registered/enqueued for logged out users.

Here is the page: http://awca.nl/dev/membership/register-pro-rata-membership/

I’ve looked at the code in class-ms-controller-frontend.php and it looks like the .js file is only loaded when ‘$is_ms_page’ is true. Apparently, my page is giving a ‘$is_ms_page’ is false?

Any help would be greatly appreciated. And thanks in advance.

  • Adam Czajczyk
    • Support Gorilla

    Hey Web Coordinator,

    I hope you’re well today and thank you for your question!

    I’ve checked the plugins code and I’m pretty much sure that you’re right. It seems that the script is indeed being loaded only if the page is a “membership page” or a user is an “admin” user.

    I think enqueueing the script via the theme should help here:

    function my_validate_ms_js() {
    wp_enqueue_script('jquery-validate', 'wp-content/plugins/membership/app/assets/js/jquery.validate.js',array( 'jquery' ));
    }
    add_action( 'wp_enqueue_scripts', 'my_validate_ms_js' );

    Let me know if it helped, please!

    Cheers,

    Adam

  • Web Coordinator
    • Site Builder, Child of Zeus

    Hey Adam,

    I suspected that this would be the solution. However, the current solution you suggested would load the script twice if the visitor was in fact logged in. Also since the visitor isn’t logged in, the $handle name isn’t registered so I had to solve it by including the minified jquery.validate.min.js file in the theme and calling it this way:

    function my_validate_ms_js() {

    if ( !is_user_logged_in() ) {

    wp_register_script(‘jquery-validate’, get_template_directory_uri() . ‘/js/jquery.validate.min.js’, array(‘jquery’:wink:,’1.1′, true);

    wp_enqueue_script(‘jquery-validate’:wink:;

    }

    }

    add_action( ‘wp_enqueue_scripts’, ‘my_validate_ms_js’ );

    Thanks for confirming my hunch. Hopefully this can be resolved in a future update. However, then I will also get double scripts. Guess I’ll just have to keep my eye out for the update.

    Cheers,

    Jason (webdeveloper for the Web Coordinator)

  • Web Coordinator
    • Site Builder, Child of Zeus

    Adam,

    I take back what I said. The $handle script name is in fact registered for logged out users so all I had to do was enqueue the file like this:

    function my_validate_ms_js() {

    if ( !is_user_logged_in() ) {

    wp_enqueue_script(‘jquery-validate’:wink:;

    }

    }

    add_action( ‘wp_enqueue_scripts’, ‘my_validate_ms_js’ );