ini plugin
This commit is contained in:
@@ -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' );
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<?php
|
||||
|
||||
function wp_model_plugin_content() {
|
||||
global $first_script;
|
||||
console_log("in menu : first_script:");
|
||||
console_log($first_script);
|
||||
function fipfcard_plugin_content() {
|
||||
global $fipfcard_first_script;
|
||||
error_log("in menu : first_script:");
|
||||
error_log($fipfcard_first_script);
|
||||
|
||||
add_files_to_front( array(
|
||||
fipfcard_add_files_to_front( array(
|
||||
"menu/example_menu.js",
|
||||
));
|
||||
|
||||
echo create_html("menu/example_menu.html");
|
||||
echo fipfcard_create_html("menu/example_menu.html");
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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";
|
||||
|
||||
?>
|
||||
|
||||
2
private
2
private
Submodule private updated: ae15730a8f...a24d53b6c3
Submodule wordpress_docker updated: 846a41063e...8f8a4046b8
Reference in New Issue
Block a user