120 lines
2.4 KiB
PHP
120 lines
2.4 KiB
PHP
<?php
|
|
/*
|
|
Plugin Name: wp_model_plugin
|
|
Plugin URI:
|
|
Description:
|
|
Author: hugogogo
|
|
Version: 1.1.0
|
|
Author URI:
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
plugin dir root
|
|
*/
|
|
define( 'PLUGIN_DIR', plugin_dir_path(__FILE__) );
|
|
define( 'PLUGIN_URL', plugin_dir_url(__FILE__) );
|
|
|
|
|
|
|
|
|
|
/*
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
inclusions
|
|
*/
|
|
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');
|
|
|
|
include_once(PLUGIN_DIR . '/php/menu/example_menu.php');
|
|
|
|
|
|
|
|
|
|
/*
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
plugin shortcode
|
|
*/
|
|
function 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('wp_model_plugin', 'main_shortcode');
|
|
|
|
|
|
|
|
|
|
/*
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
menu plugin
|
|
*/
|
|
function 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', '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' );
|
|
|
|
|
|
?>
|