Skip to content

Commit 157ece2

Browse files
author
Antti Kuosmanen
committed
Localise frontend script when registering, not enqueing
1 parent a0bc975 commit 157ece2

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

classes/class-cpt-wplf-form.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,8 @@ class="libre-form libre-form-<?php echo esc_attr( $id . ' ' . $xclass ); ?>"
542542
<?php
543543
$output = ob_get_clean();
544544

545+
// enqueue our footer script here
545546
wp_enqueue_script( 'wplf-form-js' );
546-
wp_localize_script( 'wplf-form-js', 'ajax_object', array(
547-
'ajax_url' => admin_url( 'admin-ajax.php' ),
548-
'ajax_credentials' => apply_filters( 'wplf_ajax_fetch_credentials_mode', 'same-origin' ),
549-
) );
550547

551548
return $output;
552549
}
@@ -570,6 +567,12 @@ function maybe_enqueue_frontend_script() {
570567
WPLF_VERSION,
571568
true
572569
);
570+
571+
// add dynamic variables to the script's scope
572+
wp_localize_script( 'wplf-form-js', 'ajax_object', array(
573+
'ajax_url' => admin_url( 'admin-ajax.php' ),
574+
'ajax_credentials' => apply_filters( 'wplf_ajax_fetch_credentials_mode', 'same-origin' ),
575+
) );
573576
}
574577

575578

0 commit comments

Comments
 (0)