diff --git a/plugins/wp_model_plugin/styles/mystyle.css b/plugins/wp_model_plugin/css/mystyle.css similarity index 100% rename from plugins/wp_model_plugin/styles/mystyle.css rename to plugins/wp_model_plugin/css/mystyle.css diff --git a/plugins/wp_model_plugin/scripts/myscript.js b/plugins/wp_model_plugin/js/myscript.js similarity index 100% rename from plugins/wp_model_plugin/scripts/myscript.js rename to plugins/wp_model_plugin/js/myscript.js diff --git a/plugins/wp_model_plugin/scripts/myscript2.js b/plugins/wp_model_plugin/js/myscript2.js similarity index 100% rename from plugins/wp_model_plugin/scripts/myscript2.js rename to plugins/wp_model_plugin/js/myscript2.js diff --git a/plugins/wp_model_plugin/scripts/myscript3.js b/plugins/wp_model_plugin/js/myscript3.js similarity index 100% rename from plugins/wp_model_plugin/scripts/myscript3.js rename to plugins/wp_model_plugin/js/myscript3.js diff --git a/plugins/wp_model_plugin/utils/add_to_front.php b/plugins/wp_model_plugin/php/utils/add_to_front.php similarity index 88% rename from plugins/wp_model_plugin/utils/add_to_front.php rename to plugins/wp_model_plugin/php/utils/add_to_front.php index 46a21e2..436e159 100644 --- a/plugins/wp_model_plugin/utils/add_to_front.php +++ b/plugins/wp_model_plugin/php/utils/add_to_front.php @@ -14,14 +14,14 @@ function add_files_to_front($files_arr) { $file_ext = pathinfo($file, PATHINFO_EXTENSION); $file_basename = pathinfo($file, PATHINFO_FILENAME); if ($file_ext === "js") - $dir_path = 'scripts/'; + $dir_path = 'js/'; else if ($file_ext === "css") - $dir_path = 'styles/'; + $dir_path = 'css/'; else continue; - $file_url = plugin_dir_url(__DIR__).$dir_path.$file; - $file_path = plugin_dir_path(__DIR__).$dir_path.$file; + $file_url = PLUGIN_URL.$dir_path.$file; + $file_path = PLUGIN_DIR.$dir_path.$file; $file_version = date("ymd-Gis", filemtime($file_path)); if ($file_ext === "js") { @@ -51,7 +51,6 @@ function add_var_to_front($var_array) { $js_var = 'const ' . $key . ' = '; $js_var .= json_encode($var); $js_var .= ';'; - console_log("in php, js_var: " . $js_var); wp_add_inline_script('myscript', $js_var, 'before'); } } diff --git a/plugins/wp_model_plugin/utils/console_log.php b/plugins/wp_model_plugin/php/utils/console_log.php similarity index 88% rename from plugins/wp_model_plugin/utils/console_log.php rename to plugins/wp_model_plugin/php/utils/console_log.php index 0417430..f45ca58 100644 --- a/plugins/wp_model_plugin/utils/console_log.php +++ b/plugins/wp_model_plugin/php/utils/console_log.php @@ -5,8 +5,7 @@ https://stackify.com/how-to-log-to-console-in-php/ */ function console_log($output) { - global $CONSOLE_OFF; - if ($CONSOLE_OFF) + if (CONSOLE_OFF) return; $json_output = json_encode($output, JSON_HEX_TAG); $js_code = ''; diff --git a/plugins/wp_model_plugin/utils/create_html.php b/plugins/wp_model_plugin/php/utils/create_html.php similarity index 71% rename from plugins/wp_model_plugin/utils/create_html.php rename to plugins/wp_model_plugin/php/utils/create_html.php index 4e0b98d..8ce486a 100644 --- a/plugins/wp_model_plugin/utils/create_html.php +++ b/plugins/wp_model_plugin/php/utils/create_html.php @@ -4,12 +4,13 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @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 ) + - can be a string of 1 filename + - or an array of strings of filenames + ( https://stackoverflow.com/q/4747876/9497573 ) + - it's probably better to only add 1 file, and let it include other files 2. list of variables to make available to this files - - in the form of key => val - - recommanded to do it with compact() + - 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 @@ -22,8 +23,7 @@ https://stackoverflow.com/a/4402045/9497573 */ function create_html($files, $vars) { $files = (array)$files; - - $html_dir = plugin_dir_path(__DIR__).'html/'; + $html_dir = PLUGIN_DIR.'html/'; extract($vars); ob_start(); diff --git a/plugins/wp_model_plugin/php/utils/globals.php b/plugins/wp_model_plugin/php/utils/globals.php new file mode 100644 index 0000000..f0c1e83 --- /dev/null +++ b/plugins/wp_model_plugin/php/utils/globals.php @@ -0,0 +1,14 @@ + diff --git a/plugins/wp_model_plugin/plugin_hooks.php b/plugins/wp_model_plugin/plugin_hooks.php index ec8a6d6..c2ec1ae 100644 --- a/plugins/wp_model_plugin/plugin_hooks.php +++ b/plugins/wp_model_plugin/plugin_hooks.php @@ -9,14 +9,15 @@ Author URI: */ + + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -globale variable to desable server side -console_log all at once +plugin dir root */ +define( 'PLUGIN_DIR', plugin_dir_path(__FILE__) ); +define( 'PLUGIN_URL', plugin_dir_url(__FILE__) ); -$CONSOLE_OFF = true; -$CONSOLE_OFF = false; @@ -24,10 +25,10 @@ $CONSOLE_OFF = false; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * inclusions */ - -include_once(dirname(__FILE__) . '/utils/console_log.php'); -include_once(dirname(__FILE__) . '/utils/add_to_front.php'); -include_once(dirname(__FILE__) . '/utils/create_html.php'); +include_once(PLUGIN_DIR . '/php/utils/globals.php'); +include_once(PLUGIN_DIR . '/php/utils/console_log.php'); +include_once(PLUGIN_DIR . '/php/utils/add_to_front.php'); +include_once(PLUGIN_DIR . '/php/utils/create_html.php'); @@ -36,7 +37,6 @@ include_once(dirname(__FILE__) . '/utils/create_html.php'); * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * plugin shortcode */ - function main_shortcode() { add_files_to_front( array( @@ -75,11 +75,12 @@ function main_shortcode() { add_shortcode('wp_model_plugin', 'main_shortcode'); + + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * menu plugin */ - function plugin_menu() { add_menu_page( 'wp model plugin', // webpage title