Update script enqueueing for WordPress version 6.9
Backwards compatible for earlier versions, changes can be simplified if we only ever need to consider 6.9+
This commit is contained in:
@@ -52,10 +52,15 @@ class Enqueue {
|
|||||||
if ( file_exists( $theme_dir . $js_path ) ) {
|
if ( file_exists( $theme_dir . $js_path ) ) {
|
||||||
$version = filemtime( $theme_dir . $js_path );
|
$version = filemtime( $theme_dir . $js_path );
|
||||||
wp_enqueue_script( 'jquery' ); // Needed by downstream scripts; modules can't depend on classic scripts.
|
wp_enqueue_script( 'jquery' ); // Needed by downstream scripts; modules can't depend on classic scripts.
|
||||||
|
if ( version_compare( get_bloginfo('version'), '6.9', '>=' ) ) {
|
||||||
|
wp_enqueue_script_module( 'basicwp-theme', $theme_uri . $js_path, array(), $version, [ 'in_footer' => true ] );
|
||||||
|
wp_enqueue_script_module( 'basicwp-button', $theme_uri . '/static/js/components/button.js', array( 'basicwp-theme' ), $version, [ 'in_footer' => true ] );
|
||||||
|
} else {
|
||||||
wp_enqueue_script_module( 'basicwp-theme', $theme_uri . $js_path, array(), $version, true );
|
wp_enqueue_script_module( 'basicwp-theme', $theme_uri . $js_path, array(), $version, true );
|
||||||
wp_enqueue_script_module( 'basicwp-button', $theme_uri . '/static/js/components/button.js', array( 'basicwp-theme' ), $version, true );
|
wp_enqueue_script_module( 'basicwp-button', $theme_uri . '/static/js/components/button.js', array( 'basicwp-theme' ), $version, true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enqueue backend (admin/editor) CSS and JS files.
|
* Enqueue backend (admin/editor) CSS and JS files.
|
||||||
@@ -92,10 +97,15 @@ class Enqueue {
|
|||||||
if ( file_exists( $theme_dir . $admin_js_path ) ) {
|
if ( file_exists( $theme_dir . $admin_js_path ) ) {
|
||||||
$version = filemtime( $theme_dir . $admin_js_path );
|
$version = filemtime( $theme_dir . $admin_js_path );
|
||||||
wp_enqueue_script( 'jquery' ); // Needed by downstream scripts; modules can't depend on classic scripts.
|
wp_enqueue_script( 'jquery' ); // Needed by downstream scripts; modules can't depend on classic scripts.
|
||||||
|
if ( version_compare( get_bloginfo('version'), '6.9', '>=' ) ) {
|
||||||
|
wp_enqueue_script_module( 'basicwp-admin', $theme_uri . $admin_js_path, array(), $version, [ 'in_footer' => true ] );
|
||||||
|
wp_enqueue_script_module( 'basicwp-button', $theme_uri . '/static/js/components/button.js', array( 'basicwp-admin' ), $version, [ 'in_footer' => true ] );
|
||||||
|
} else {
|
||||||
wp_enqueue_script_module( 'basicwp-admin', $theme_uri . $admin_js_path, array(), $version, true );
|
wp_enqueue_script_module( 'basicwp-admin', $theme_uri . $admin_js_path, array(), $version, true );
|
||||||
wp_enqueue_script_module( 'basicwp-button', $theme_uri . '/static/js/components/button.js', array( 'basicwp-admin' ), $version, true );
|
wp_enqueue_script_module( 'basicwp-button', $theme_uri . '/static/js/components/button.js', array( 'basicwp-admin' ), $version, true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the Enqueue class.
|
// Initialize the Enqueue class.
|
||||||
|
|||||||
Reference in New Issue
Block a user