added better comments to explain functions

This commit is contained in:
asus
2024-02-09 14:31:00 +01:00
parent c41b184221
commit 0c0b406de0
7 changed files with 77 additions and 43 deletions

View File

@@ -1,5 +1,9 @@
<?php
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@param an array of files
*/
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 );
@@ -31,11 +35,14 @@ function add_files_to_front($files_arr) {
}
}
# this function expect an array of key => value
# with the key being name of the variable, like this :
# 'my_var' => 'value',
# simpler way to do it is to use compact when calling the function :
# add_var_to_front(compact("var1", "var2", "var3"));
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@param expect an array of key => value
with the key being name of the variable, like this :
'my_var' => 'value',
simpler way to do it is to use compact when calling the function :
add_var_to_front(compact("var1", "var2", "var3"));
*/
function add_var_to_front($var_array) {
extract($var_array);

View File

@@ -1,6 +1,9 @@
<?php
// https://stackify.com/how-to-log-to-console-in-php/
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
https://stackify.com/how-to-log-to-console-in-php/
*/
function console_log($output) {
global $CONSOLE_OFF;
if ($CONSOLE_OFF)

View File

@@ -1,15 +1,28 @@
<?php
# using ob_start() and ob_get_clean()
# allows to have php expansion inside the html loaded
# in opposition to the methode file_get_contents()
#
# https://stackoverflow.com/a/4402045/9497573
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@param two arguments :
1. html files to include in front
- can be a string of 1 filename
- or an array of strings of filenames
( https://stackoverflow.com/q/4747876/9497573 )
2. list of variables to make available to this files
- in the form of key => val
- recommanded to do it with compact()
ex: create_html( "file.html", compact("var1","var2",) );
ex: create_html( array("file1.html", "file2.html"), array("var1"=>"value") );
@return a string of html code
# takes two arguments :
# a list of the html files to include in front
# a list of variables to make available to this files
using ob_start() and ob_get_clean()
allows to have php expansion inside the html loaded
in opposition to the methode file_get_contents()
https://stackoverflow.com/a/4402045/9497573
*/
function create_html($files, $vars) {
$files = (array)$files;
$html_dir = plugin_dir_path(__DIR__).'html/';
extract($vars);