Files
2024_WEBSITE_fipf/plugins/fipfcard_plugin/fipfcard_plugin.php
2024-02-12 10:13:02 +01:00

120 lines
2.5 KiB
PHP

<?php
/*
Plugin Name: fipfcard_plugin
Plugin URI:
Description:
Author: hugogogo
Version: 1.1.0
Author URI:
*/
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
plugin dir root
*/
define( 'FIPFCARD_PLUGIN_DIR', plugin_dir_path(__FILE__) );
define( 'FIPFCARD_PLUGIN_URL', plugin_dir_url(__FILE__) );
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
inclusions
*/
include_once(FIPFCARD_PLUGIN_DIR . '/php/utils/globals.php');
include_once(FIPFCARD_PLUGIN_DIR . '/php/utils/console_log.php');
include_once(FIPFCARD_PLUGIN_DIR . '/php/utils/add_to_front.php');
include_once(FIPFCARD_PLUGIN_DIR . '/php/utils/create_html.php');
include_once(FIPFCARD_PLUGIN_DIR . '/php/menu/example_menu.php');
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
plugin shortcode
*/
function fipfcard_main_shortcode() {
add_files_to_front( array(
"example_style.css",
"example_init.js",
"example_script2.js",
"example_script3.js",
));
$myvar_1 = "I am one";
$myvar_2 = "I am two";
add_var_to_front( compact(
"myvar_1",
"myvar_2",
));
$names = ["hugo", "camille"];
$ages = ["13", "34", "56"];
$html_front = create_html(
array(
"example_index.html",
"example_index2.html",
),
compact(
"names",
"ages",
)
);
return $html_front;
}
add_shortcode('fipfcard_plugin', 'fipfcard_main_shortcode');
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
menu plugin
*/
function fipfcard_plugin_menu() {
add_menu_page(
'wp model plugin', // webpage title
'model plugin', // menu title
'manage_options', // capability
'wp-model-plugin', // menu_slug
'wp_model_plugin_content' // callback function to display page content
);
}
add_action('admin_menu', 'fipfcard_plugin_menu');
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ajax
- https://stackoverflow.com/questions/43557755/how-to-call-ajax-in-wordpress
- in `add_action( 'wp_ajax_get_data', 'my_ajax_handler' );`
the 'wp_ajax_get_data' is a hooks formated as 'wp_ajax_{$action}'
the `$action` param is passed in the data object of the ajax call
- to access the content of the data object properties of the ajax call :
use $_POST['property_name']
*/
function my_ajax_handler() {
wp_send_json_success( array(
'It works',
"data_received" => $_POST['data'],
),
200
);
}
add_action( 'wp_ajax_get_data', 'my_ajax_handler' );
?>