wip trying to create better options to include scripts with attributes
This commit is contained in:
@@ -18,6 +18,7 @@ class PLGNTLS_class
|
||||
private $_prefix;
|
||||
private $_js_dependencies;
|
||||
private $_css_dependencies;
|
||||
private $_scripts_modules;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -26,6 +27,7 @@ class PLGNTLS_class
|
||||
$this->_first_script = null;
|
||||
$this->_js_dependencies = array();
|
||||
$this->_css_dependencies = array();
|
||||
$this->_scripts_modules = array();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,12 +196,29 @@ class PLGNTLS_class
|
||||
$previous_css_basename = $script->handle;
|
||||
}
|
||||
}
|
||||
|
||||
$this->make_scripts_modules();
|
||||
|
||||
/*
|
||||
* uncomment to print all enqueued scripts, can be usefull
|
||||
*/
|
||||
global $wp_scripts;
|
||||
error_log("wp_scripts->queue:");
|
||||
error_log(json_encode($wp_scripts->queue));
|
||||
*/
|
||||
}
|
||||
// funciton is just a wrapper, only to facilitate writing
|
||||
private function make_scripts_modules() {
|
||||
// https://developer.wordpress.org/reference/hooks/wp_script_attributes/
|
||||
// https://wordpress.stackexchange.com/questions/66843/attach-a-private-function-at-a-hook
|
||||
add_filter( 'wp_script_attributes', fn() => $this->add_type_module(), 10, 1 );
|
||||
}
|
||||
private function add_type_module($attr) {
|
||||
if (empty($attr['id']))
|
||||
return $attr;
|
||||
if ($attr['id'] === 'PLGNTLS_plgntls_fetch_js-js') {
|
||||
$attr['type'] = 'module';
|
||||
}
|
||||
return $attr;
|
||||
}
|
||||
|
||||
private function check_dependencies(&$script, $previous_basename)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
function PLGNTLS_fetch(url, options = {}) {
|
||||
//function PLGNTLS_fetch(url, options = {}) {
|
||||
export function PLGNTLS_fetch(url, options = {}) {
|
||||
console.log("inside PLGNTLS_fetch");
|
||||
url = PLGNTLS_data.fetch_url + url;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user