Skip to content

Commit 5c77189

Browse files
authored
move loading frontend scripts to the shortcode
1 parent 7c899cb commit 5c77189

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

classes/class-cpt-wplf-form.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,13 @@ class="libre-form libre-form-<?php echo esc_attr( $id . ' ' . $xclass ); ?>"
536536
</form>
537537
<?php
538538
$output = ob_get_clean();
539+
540+
wp_enqueue_script( 'wplf-form-js' );
541+
wp_localize_script( 'wplf-form-js', 'ajax_object', array(
542+
'ajax_url' => admin_url( 'admin-ajax.php' ),
543+
'ajax_credentials' => apply_filters( 'wplf_ajax_fetch_credentials_mode', 'same-origin' ),
544+
) );
545+
539546
return $output;
540547
}
541548

@@ -558,16 +565,6 @@ function maybe_enqueue_frontend_script() {
558565
WPLF_VERSION,
559566
true
560567
);
561-
562-
if ( is_a( $post, 'WP_Post' ) ) {
563-
if ( has_shortcode( $post->post_content, 'libre-form' ) || $post->post_type === 'wplf-form' ) {
564-
wp_enqueue_script( 'wplf-form-js' );
565-
wp_localize_script( 'wplf-form-js', 'ajax_object', array(
566-
'ajax_url' => admin_url( 'admin-ajax.php' ),
567-
'ajax_credentials' => apply_filters( 'wplf_ajax_fetch_credentials_mode', 'same-origin' ),
568-
) );
569-
}
570-
}
571568
}
572569

573570

0 commit comments

Comments
 (0)