Skip Navigation

[Resolved] How to delay running code in toolset custom code section AFTER CRED login

This thread is resolved. Here is a description of the problem and solution.

Problem:

I want to update the array by using custom code written in toolset custom code section. The code has been written and it works fine if I use the on-demand feature of toolset and append the file

Solution:

It needs custom codes, for example:

https://toolset.com/forums/topic/how-to-delay-running-code-in-toolset-custom-code-section-after-cred-login/#post-2094131

Relevant Documentation:

https://codex.wordpress.org/AJAX_in_Plugins

This support ticket is created 2 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by himanshuS 2 years, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#2093529

I have been using a lot of VIEWS shortcodes and TYPES shortcodes to create dynamic pages.

The site was very slow because of these shortcodes so I decided to create a user_meta array that contains information from most commonly run attributes. This saves processing time and loads the page faster.

I want to update the array by using custom code written in toolset custom code section. The code has been written and it works fine if I use the on-demand feature of toolset and append the file to the url - hidden link

However, this creates a problem that the page does not load UNTIL the file-name.php is fully executed. This causes a delay. As I am using a toolset form to login and toolset custom cod section to write the code, I was wondering if there is a way to run the code for a specific user AFTER the user logs in. This way the page will show data from the last update and by the time the user refreshes the page, the latest code would have run and the data would be 100% accurate.

The file-name.php is user specific so I need to run it when a user logs in. I tried to do this with cron job but it appears that cron-job does not run for a specific user.

AI am on US time and would prefer a US person to manage this ticket.

#2094131

Hello,

There isn't such kind of built-in feature with Toolset plugins, in your case, I suggest you try to add a AJAX action after specific user load the frontend pages/post, for example:
1) Add an AJAX action, and trigger a PHP function
https://codex.wordpress.org/AJAX_in_Plugins

2) In this PHP function, check the user's roles:
https://developer.wordpress.org/reference/functions/wp_get_current_user/
and run your custom PHP file

#2100763

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.