I'm currently trying to understand the integration between 2 Wordpress plugins: the WooCommerce Follow Up Emails plugin and the Ninja Forms plugin (with the ultimate goal, we can send a follow-up email template with a manual type as an action in response to submitting ninja forms). We use Ninja Forms 3 for what it's worth.
When defining the parameters of the Action class, I provide a list of templates to the user, so when defining an action, they can select the template to send. To get the email templates from the follow-up plugin, I use their API client , in particular the method get_emails()(which, in turn, translates to a GET call for the endpoint /emailsat their API URL).
The problem is this: on each page the action is called ninja_forms_register_actions, during which I create an instance of the action class. During the call, __constructwe fill in the settings for the action, and for this we call the API of subsequent letters. This initiates the loading of the page during which the action is called ninja_forms_register_actions...
Although I expected this problem, my planned solution did not help: I planned to use transients to store the result of the API call, for example:
private static function _get_templates()
{
error_log('_get_templates() started - ' . microtime(true));
if (false === ($templates = get_transient(self::TEMPLATE_TRANSIENT))) {
error_log('_get_templates() fetching - ' . microtime(true));
$fue_api = self::fue_api();
$templates = $fue_api->get_emails();
set_transient(self::TEMPLATE_TRANSIENT, $templates, self::TEMPLATE_TRANSIENT_EXPIRY);
error_log('_get_templates() fetched - ' . microtime(true));
}
error_log('_get_templates() done - ' . microtime(true));
return $templates;
}
However, the result in my magazines is as follows:
[22-May-2016 23:53:33 UTC] _get_templates() started - 1463961213.692187
[22-May-2016 23:53:33 UTC] _get_templates() fetching - 1463961213.694222
[22-May-2016 23:53:34 UTC] _get_templates() started - 1463961214.05998
[22-May-2016 23:53:34 UTC] _get_templates() fetching - 1463961214.061054
[22-May-2016 23:53:38 UTC] _get_templates() started - 1463961218.660683
[22-May-2016 23:53:38 UTC] _get_templates() fetching - 1463961218.661265
[22-May-2016 23:53:40 UTC] _get_templates() started - 1463961220.772228
[22-May-2016 23:53:40 UTC] _get_templates() fetching - 1463961220.774142
[22-May-2016 23:53:41 UTC] _get_templates() started - 1463961221.150277
[22-May-2016 23:53:41 UTC] _get_templates() fetching - 1463961221.654757
[22-May-2016 23:53:45 UTC] _get_templates() started - 1463961225.306565
[22-May-2016 23:53:45 UTC] _get_templates() fetching - 1463961225.308898
[22-May-2016 23:53:46 UTC] _get_templates() started - 1463961226.281794
[22-May-2016 23:53:46 UTC] _get_templates() fetching - 1463961226.283803
which continues until I kill the web server process or something else is not as strong as deleting / renaming the plugin folder, after which the transient is filled with the HTTP error code (which in itself is not surprising). It is so clear that my workaround is not working, as the transition process is still not set until the request is completed.
, , DOING_AJAX, - AJAX Ninja Forms, , DOING_AJAX , API FUE admin-ajax.php. :
private static function _get_templates()
{
error_log('_get_templates() started - ' . microtime(true));
if (false === get_option(self::TEMPLATE_LOCK_OPTION, false) && false === ($templates = get_transient(self::TEMPLATE_TRANSIENT))) {
delete_option(self::TEMPLATE_LOCK_OPTION);
add_option(self::TEMPLATE_LOCK_OPTION, true, '', 'no');
error_log('_get_templates() fetching - ' . microtime(true));
$fue_api = self::fue_api();
$templates = $fue_api->get_emails();
delete_option(self::TEMPLATE_LOCK_OPTION);
set_transient(self::TEMPLATE_TRANSIENT, $templates, self::TEMPLATE_TRANSIENT_EXPIRY);
error_log('_get_templates() fetched - ' . microtime(true));
}
error_log('_get_templates() done - ' . microtime(true));
return $templates;
}
, , , (, WPEngine et al). / , , , ?
: 100% - WP Cron - , , . , , . , .