try wordpress rest api instead of ajax

This commit is contained in:
asus
2024-02-23 23:43:23 +01:00
parent 0f15b67e8b
commit 38260912cd
5 changed files with 91 additions and 53 deletions

View File

@@ -52,18 +52,20 @@ class PLGNTLS_class
public function add_to_front($scripts_arr = null, $vars = null) {
if (!is_array($vars))
$vars = array();
if (!is_null($scripts_arr))
{
console_log("in is null scripts_arr");
// add ajax file at beginning of files list
array_unshift($scripts_arr, "utils/plugin_ajax.js");
$nonce = array("ajax_nonce" => wp_create_nonce('wp-pageviews-nonce'));
$url = array("ajax_url" => admin_url('admin-ajax.php'));
if (!is_array($vars))
$vars = array();
$ajax_url = array("ajax_url" => admin_url('admin-ajax.php'));
$vars = array_merge($vars, $nonce);
$vars = array_merge($vars, $url);
$vars = array_merge($vars, $ajax_url);
}
$fetch_url = array("fetch_url" => get_site_url() . "/wp-json");
$vars = array_merge($vars, $fetch_url);
$scripts = array();
foreach($scripts_arr as $key => $script_name) {