Get rid of inline JS code for public.js
This code was preventing WordPress from rendering the public.js script as deferred. The defer attribute can be applied only to scripts that are loaded via src. WP detected that there was an associated inline script and removed the defer attribute from the public.js script. In this commit, I moved the initialization of the error message to public.js and I pass the value via static object. [MAILPOET-5623]
This commit is contained in:
committed by
Aschepikov
parent
71cb252e8c
commit
c38b91f941
@@ -86,28 +86,12 @@ class AssetsController {
|
||||
true
|
||||
);
|
||||
|
||||
$ajaxFailedErrorMessage = __('An error has happened while performing a request, please try again later.', 'mailpoet');
|
||||
$this->wp->wpLocalizeScript('mailpoet_public', 'MailPoetForm', [
|
||||
'ajax_url' => $this->wp->adminUrl('admin-ajax.php'),
|
||||
'is_rtl' => (function_exists('is_rtl') ? (bool)is_rtl() : false),
|
||||
'ajax_common_error_message' => esc_js($ajaxFailedErrorMessage),
|
||||
]);
|
||||
|
||||
$ajaxFailedErrorMessage = __('An error has happened while performing a request, please try again later.', 'mailpoet');
|
||||
|
||||
$inlineScript = <<<EOL
|
||||
function initMailpoetTranslation() {
|
||||
if (typeof MailPoet !== 'undefined') {
|
||||
MailPoet.I18n.add('ajaxFailedErrorMessage', '%s')
|
||||
} else {
|
||||
setTimeout(initMailpoetTranslation, 250);
|
||||
}
|
||||
}
|
||||
setTimeout(initMailpoetTranslation, 250);
|
||||
EOL;
|
||||
$this->wp->wpAddInlineScript(
|
||||
'mailpoet_public',
|
||||
sprintf($inlineScript, esc_js($ajaxFailedErrorMessage)),
|
||||
'after'
|
||||
);
|
||||
}
|
||||
|
||||
public function setupAdminWidgetPageDependencies() {
|
||||
|
Reference in New Issue
Block a user