wip make ajax automatically added
This commit is contained in:
@@ -5,16 +5,6 @@ function wp_model_plugin_content() {
|
||||
"menu/menu.js",
|
||||
));
|
||||
|
||||
$ajax_url = admin_url( 'admin-ajax.php' );
|
||||
$nonce = wp_create_nonce( 'wp-pageviews-nonce' );
|
||||
add_var_to_front(
|
||||
compact(
|
||||
"ajax_url",
|
||||
"nonce",
|
||||
),
|
||||
"menu"
|
||||
);
|
||||
|
||||
echo create_html("menu/menu.html");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@ function add_files_to_front($files_arr) {
|
||||
//wp_enqueue_script(<give_it_a_name>, /url/to/file, [depends on], version, defer? );
|
||||
//wp_enqueue_style( <give_it_a_name>, /url/to/file, [depends on], version, media );
|
||||
|
||||
// always adding ajax file first
|
||||
$files_arr = ["ajax.js", ...$files_arr];
|
||||
|
||||
$previous_css_basename = '';
|
||||
$previous_js_basename = '';
|
||||
foreach ($files_arr as $file) {
|
||||
@@ -33,6 +36,16 @@ function add_files_to_front($files_arr) {
|
||||
$previous_css_basename = $file_basename;
|
||||
}
|
||||
}
|
||||
|
||||
$ajax_url = admin_url( 'admin-ajax.php' );
|
||||
$nonce = wp_create_nonce( 'wp-pageviews-nonce' );
|
||||
add_var_to_front(
|
||||
compact(
|
||||
"ajax_url",
|
||||
"nonce",
|
||||
),
|
||||
"ajax"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,9 +62,10 @@ it also adds the ajax url
|
||||
add_var_to_front(compact("var1", "var2", "var3"));
|
||||
2. name of first embended script (if we want to have the variables
|
||||
availables to all js : it will be available to the script and all following)
|
||||
- default value is "init", assuming the first script is called "init.js"
|
||||
- default value is "ajax", assuming the first script is "ajax.js"
|
||||
since it's automatically added first by `add_files_to_front`
|
||||
*/
|
||||
function add_var_to_front($vars, $handle = "init") {
|
||||
function add_var_to_front($vars, $handle = "ajax") {
|
||||
$handle = pathinfo($handle, PATHINFO_FILENAME);
|
||||
$object_name = "php_data";
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ https://stackoverflow.com/a/4402045/9497573
|
||||
function create_html($files, $vars = null) {
|
||||
$files = (array)$files;
|
||||
$html_dir = PLUGIN_DIR.'html/';
|
||||
console_log("vars: ");
|
||||
console_log($vars);
|
||||
if (!is_null($vars))
|
||||
extract($vars);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user