From 3f38cf523a6e91b9efcdb8fc094f2dc26a9b182b Mon Sep 17 00:00:00 2001 From: asus Date: Mon, 12 Feb 2024 11:26:44 +0100 Subject: [PATCH] ini plugin --- plugins/fipfcard_plugin/fipfcard_plugin.php | 18 +++++------ .../fipfcard_plugin/js/menu/example_menu.js | 2 ++ .../fipfcard_plugin/php/menu/example_menu.php | 12 ++++---- .../php/utils/add_to_front.php | 30 +++++++++---------- .../fipfcard_plugin/php/utils/create_html.php | 2 +- plugins/fipfcard_plugin/php/utils/globals.php | 6 ++-- private | 2 +- wordpress_docker | 2 +- 8 files changed, 38 insertions(+), 36 deletions(-) diff --git a/plugins/fipfcard_plugin/fipfcard_plugin.php b/plugins/fipfcard_plugin/fipfcard_plugin.php index 14b6a51..63a32e0 100644 --- a/plugins/fipfcard_plugin/fipfcard_plugin.php +++ b/plugins/fipfcard_plugin/fipfcard_plugin.php @@ -41,7 +41,7 @@ plugin shortcode */ function fipfcard_main_shortcode() { - add_files_to_front( array( + fipfcard_add_files_to_front( array( "example_style.css", "example_init.js", "example_script2.js", @@ -51,7 +51,7 @@ function fipfcard_main_shortcode() { $myvar_1 = "I am one"; $myvar_2 = "I am two"; - add_var_to_front( compact( + fipfcard_add_var_to_front( compact( "myvar_1", "myvar_2", )); @@ -59,7 +59,7 @@ function fipfcard_main_shortcode() { $names = ["hugo", "camille"]; $ages = ["13", "34", "56"]; - $html_front = create_html( + $html_front = fipfcard_create_html( array( "example_index.html", "example_index2.html", @@ -83,11 +83,11 @@ menu plugin */ function fipfcard_plugin_menu() { add_menu_page( - 'wp model plugin', // webpage title - 'model plugin', // menu title + 'fipf_card', // webpage title + 'fipf_card', // menu title 'manage_options', // capability - 'wp-model-plugin', // menu_slug - 'wp_model_plugin_content' // callback function to display page content + 'fipfcard-plugin', // menu_slug + 'fipfcard_plugin_content' // callback function to display page content ); } add_action('admin_menu', 'fipfcard_plugin_menu'); @@ -105,7 +105,7 @@ ajax - to access the content of the data object properties of the ajax call : use $_POST['property_name'] */ -function my_ajax_handler() { +function fipfcard_ajax_handler() { wp_send_json_success( array( 'It works', "data_received" => $_POST['data'], @@ -113,7 +113,7 @@ function my_ajax_handler() { 200 ); } -add_action( 'wp_ajax_get_data', 'my_ajax_handler' ); +add_action( 'wp_ajax_get_data', 'fipfcard_ajax_handler' ); ?> diff --git a/plugins/fipfcard_plugin/js/menu/example_menu.js b/plugins/fipfcard_plugin/js/menu/example_menu.js index 206c5b8..afa2176 100644 --- a/plugins/fipfcard_plugin/js/menu/example_menu.js +++ b/plugins/fipfcard_plugin/js/menu/example_menu.js @@ -3,5 +3,7 @@ const sendButton = document.getElementById('mybutton'); sendButton.addEventListener('click', () => { const inputValue = inputElement.value; + console.log("inputValue:"); + console.log(inputValue); ajax_post(inputValue, 'get_data'); }); diff --git a/plugins/fipfcard_plugin/php/menu/example_menu.php b/plugins/fipfcard_plugin/php/menu/example_menu.php index c69058d..52af7b6 100644 --- a/plugins/fipfcard_plugin/php/menu/example_menu.php +++ b/plugins/fipfcard_plugin/php/menu/example_menu.php @@ -1,15 +1,15 @@ diff --git a/plugins/fipfcard_plugin/php/utils/add_to_front.php b/plugins/fipfcard_plugin/php/utils/add_to_front.php index 14a07db..cb0cb78 100644 --- a/plugins/fipfcard_plugin/php/utils/add_to_front.php +++ b/plugins/fipfcard_plugin/php/utils/add_to_front.php @@ -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(, /url/to/file, [depends on], version, defer? ); //wp_enqueue_style( , /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); diff --git a/plugins/fipfcard_plugin/php/utils/create_html.php b/plugins/fipfcard_plugin/php/utils/create_html.php index 71f3a53..b02716f 100644 --- a/plugins/fipfcard_plugin/php/utils/create_html.php +++ b/plugins/fipfcard_plugin/php/utils/create_html.php @@ -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)) diff --git a/plugins/fipfcard_plugin/php/utils/globals.php b/plugins/fipfcard_plugin/php/utils/globals.php index 1d38805..14260f2 100644 --- a/plugins/fipfcard_plugin/php/utils/globals.php +++ b/plugins/fipfcard_plugin/php/utils/globals.php @@ -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"; ?> diff --git a/private b/private index ae15730..a24d53b 160000 --- a/private +++ b/private @@ -1 +1 @@ -Subproject commit ae15730a8f0b2a794b7a8aa4fa771fa625da881c +Subproject commit a24d53b6c32759529921e6b0b273a2477c7ba36e diff --git a/wordpress_docker b/wordpress_docker index 846a410..8f8a404 160000 --- a/wordpress_docker +++ b/wordpress_docker @@ -1 +1 @@ -Subproject commit 846a41063ec205c889bf1a08779ea4bd8aa4d9c6 +Subproject commit 8f8a4046b8c9d17a8bd5e2d9f022d6d26653477a