Support

Home Forums WP User Integration JS script is not loading after logged in?

JS script is not loading after logged in?

Posted: March 29, 2018 at 12:51 am


micahbeverly

March 29, 2018 at 12:51 am

I am using wp user integration plugin for event Espresso and I have applied settings like this:

Force Login For Registration: Yes
Auto Create User with registrations: NO
Default role for auto-created users: Subscriber.

This is all working fine Except when user Login via Registration checkout form (EE process), the information of user information get’s displayed on a registration form. But actually, WordPress site does not know if a user is logged in or not since you are not refreshing the Page(AJAX).

How do I refresh a page after a user gets logged in?


Tony

  • Support Staff

March 29, 2018 at 3:06 am

Hi there,

We don’t refresh the page as we already do an AJAX request to log the user in, WordPress knows the user is logged in, it just doesn’t show it on that specific page without reloading it as the login is done on another request (the AJAX request).

As far as EE is concerned the user is logged in, it doesn’t need the rest of the page to show the user is logged in and will continue to work, can I ask why you need the page to refresh?


micahbeverly

March 29, 2018 at 7:10 am

I am loading My Custom JS Script on AHEE__Single_Page_Checkout___initialize_reg_step__wpuser_login hook. Also inside the function call, I’m checking if a user is logged in or not for enqueuing Script.
Even when I removed user logged in condition, the function doesn’t get called and hence does not load Script.
Is there another hook to load JS? but still, I need to check user as the information I’m passing through the script is related to a user.


Josh

  • Support Staff

March 29, 2018 at 7:21 am

Hi there,

The hook to load JS most WordPress developers recommend is the
wp_enqueue_scripts action hook. You’ll find more information and code examples in these resources:

https://developer.wordpress.org/reference/hooks/wp_enqueue_scripts/

http://www.wpbeginner.com/wp-tutorials/how-to-properly-add-javascripts-and-styles-in-wordpress/


micahbeverly

March 29, 2018 at 8:35 am

Okay, here’s my code.
I had added JS. (the recommended way)
function wdmloadEEJS()
{
if (wp_get_current_user()) {
$parent = wp_get_current_user();

$parentChildren = get_user_meta($parent->ID, ‘wdm_child_info’, 1);

wp_register_script(‘wdmEERegisterJS’, plugins_url(‘/assets/js/wdmEERegisterValidation.js’, __FILE__), array(‘jquery’), ‘1.2.0’, true);
wp_localize_script(‘wdmEERegisterJS’, ‘wdmObjectRegisteration’, array(‘ajaxurl’ => admin_url(‘admin-ajax.php’),’childrenInfo’=> $parentChildren));
wp_enqueue_script(‘wdmEERegisterJS’);
}
}
add_action(‘AHEE__attendee_information__reg_step_start’,’wdmloadEEJS’, 10);

IMP: I just Wanted to reload that page after ajax call. Is there a way
to implement this?


Josh

  • Support Staff

March 29, 2018 at 9:08 am

I’m afraid your code makes no sense to me, but I can point out that the correct usage of the wp_enqueue_scripts action hook would look like this:

add_action('wp_enqueue_scripts', 'wdmloadEEJS');

Then you’ll probably need to add some logic within your callback function to ensure the code executes only when needed. For example:

if( did_action( 'AHEE__attendee_information__reg_step_start' ) === 1 ){
// code goes here
}

The support post ‘JS script is not loading after logged in?’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso