ini plugin

This commit is contained in:
asus
2024-02-12 11:26:44 +01:00
parent ff7a9423a1
commit 3f38cf523a
8 changed files with 38 additions and 36 deletions

View File

@@ -15,11 +15,11 @@ no real needs to check if already included :
it's not a real pbm
(what is more efficient, check for double or overwritte object ?)
*/
function add_ajax_post() {
global $first_script;
global $ajax_file;
function fipfcard_add_ajax_post() {
global $fipfcard_first_script;
global $fipfcard_ajax_file;
$file = init_file($ajax_file);
$file = fipfcard_init_file($fipfcard_ajax_file);
// // check if ajax script was already enqueued
// global $wp_scripts;
@@ -27,7 +27,7 @@ function add_ajax_post() {
// if ($already_enqueued !== false)
// return ;
$first_script = $file->handle;
$fipfcard_first_script = $file->handle;
wp_enqueue_script( $file->handle, $file->url, $previous_js_basename, $file->version, true);
$_url = admin_url( 'admin-ajax.php' );
@@ -57,7 +57,7 @@ function add_ajax_post() {
- path : path to file in server
- version : used to avoid browser caching
*/
function init_file($file_name) {
function fipfcard_init_file($file_name) {
$file = (object)[];
$file->ext = pathinfo($file_name, PATHINFO_EXTENSION);
@@ -89,21 +89,21 @@ function init_file($file_name) {
- to add ajax script and variables
- default to true
*/
function add_files_to_front($files_arr, $add_ajax = true) {
function fipfcard_add_files_to_front($files_arr, $add_ajax = true) {
//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 );
global $first_script;
global $fipfcard_first_script;
if ($add_ajax === true)
add_ajax_post($file);
fipfcard_add_ajax_post();
$previous_css_basename = '';
$previous_js_basename = '';
foreach ($files_arr as $file_name) {
$file = init_file($file_name);
$file = fipfcard_init_file($file_name);
if ($file->ext === "js") {
if (is_null($first_script))
$first_script = $file->handle;
if (is_null($fipfcard_first_script))
$fipfcard_first_script = $file->handle;
wp_enqueue_script( $file->handle, $file->url, $previous_js_basename, $file->version, true);
$previous_js_basename = $file->basename;
}
@@ -129,10 +129,10 @@ pass variables to js front as global variables
this name is the filename + "_" + extension :
init.js -> init_js
*/
function add_var_to_front($vars, $handle = null) {
function fipfcard_add_var_to_front($vars, $handle = null) {
if (is_null($handle)) {
global $first_script;
$handle = $first_script;
global $fipfcard_first_script;
$handle = $fipfcard_first_script;
}
extract($vars);

View File

@@ -21,7 +21,7 @@ in opposition to the methode file_get_contents()
https://stackoverflow.com/a/4402045/9497573
*/
function create_html($files, $vars = null) {
function fipfcard_create_html($files, $vars = null) {
$files = (array)$files;
$html_dir = FIPFCARD_PLUGIN_DIR.'html/';
if (!is_null($vars))

View File

@@ -9,14 +9,14 @@ const vs define : https://stackoverflow.com/questions/2447791/php-define-vs-cons
/* switch console_log
const CONSOLE_OFF = true;
*/
const CONSOLE_OFF = false;
const FIPFCARD_CONSOLE_OFF = false;
/* a variable that will contain the name of the first script enqueued
*/
$first_script = null;
$fipfcard_first_script = null;
/* path to ajax.js file, from root of js dir
*/
$ajax_file = "utils/ajax.js";
$fipfcard_ajax_file = "utils/ajax.js";
?>