- added const dir path and url
- better file organisation
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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 = '<script>console.log(' . $json_output . ');</script>';
|
||||
@@ -7,6 +7,7 @@
|
||||
- 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()
|
||||
@@ -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();
|
||||
14
plugins/wp_model_plugin/php/utils/globals.php
Normal file
14
plugins/wp_model_plugin/php/utils/globals.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
globals variables
|
||||
const vs define : https://stackoverflow.com/questions/2447791/php-define-vs-const
|
||||
*/
|
||||
|
||||
/* switch console_log
|
||||
const CONSOLE_OFF = true;
|
||||
*/
|
||||
const CONSOLE_OFF = false;
|
||||
|
||||
?>
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user