wip the nonce for the menu works
This commit is contained in:
@@ -22,6 +22,7 @@ include_once(plugin_dir_path(__FILE__) . '/php/calculations.php');
|
|||||||
|
|
||||||
include_once(plugin_dir_path(__FILE__) . '/menu/admin_menu.php');
|
include_once(plugin_dir_path(__FILE__) . '/menu/admin_menu.php');
|
||||||
include_once(plugin_dir_path(__FILE__) . '/menu/admin_menu_toggle.php');
|
include_once(plugin_dir_path(__FILE__) . '/menu/admin_menu_toggle.php');
|
||||||
|
include_once(plugin_dir_path(__FILE__) . '/menu/menu_content.php');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<form action="<?php echo $fetch_url.'/'.$base_rest_route.'/choose'; ?>" method="POST">
|
<form method="POST">
|
||||||
|
<?php wp_nonce_field('action_name', 'nonce_name'); ?>
|
||||||
<div>
|
<div>
|
||||||
<input type="checkbox" id="calculation_patch" name="calculation" checked />
|
<input type="checkbox" id="calculation_patch" name="calculation" checked />
|
||||||
<label for="calculation_patch">calculation patch</label>
|
<label for="calculation_patch">calculation patch</label>
|
||||||
|
|||||||
@@ -12,45 +12,12 @@ if (!defined('ABSPATH')) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* the construction of the admin menu page
|
* creates the plugin menu
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function plugin_content() {
|
|
||||||
$base_rest_route = Fbpatch::URL_BASE_REST_ROUTE;
|
|
||||||
$fetch_nonce = wp_create_nonce('wp_rest');
|
|
||||||
$fetch_url = get_site_url() . "/wp-json";
|
|
||||||
ob_start();
|
|
||||||
include(plugin_dir_path(__DIR__) . '/html/menu.html');
|
|
||||||
$html = ob_get_clean();
|
|
||||||
|
|
||||||
echo $html;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function choose_patches() {
|
|
||||||
error_log("---test---");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// handling routes and endpoints
|
|
||||||
// diff routes and endpoints : https://stackoverflow.com/q/56075017/9497573
|
|
||||||
function admin_menu_routes_endpoints() {
|
|
||||||
$base_rest_route = Fbpatch::URL_BASE_REST_ROUTE;
|
|
||||||
register_rest_route($base_rest_route, '/choose', array(
|
|
||||||
'methods' => 'POST',
|
|
||||||
'callback' => __NAMESPACE__.'\choose_patches',
|
|
||||||
));
|
|
||||||
};
|
|
||||||
add_action('rest_api_init', __NAMESPACE__.'\admin_menu_routes_endpoints');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* menu plugin
|
|
||||||
*/
|
|
||||||
function plugin_menu() {
|
function plugin_menu() {
|
||||||
$menu_page_title = 'fbpatch';
|
$menu_page_title = 'fbpatch';
|
||||||
$menu_title = 'fbpatch';
|
$menu_title = 'fbpatch';
|
||||||
|
|||||||
58
plugins/fbpatch/menu/menu_content.php
Normal file
58
plugins/fbpatch/menu/menu_content.php
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
namespace FBPATCH;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* the construction of the admin menu page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function plugin_content() {
|
||||||
|
$base_rest_route = Fbpatch::URL_BASE_REST_ROUTE;
|
||||||
|
$fetch_nonce = wp_create_nonce('wp_rest');
|
||||||
|
$fetch_url = get_site_url() . "/wp-json";
|
||||||
|
ob_start();
|
||||||
|
include(plugin_dir_path(__DIR__) . '/html/menu.html');
|
||||||
|
\FBPATCH\choose_patches();
|
||||||
|
$html = ob_get_clean();
|
||||||
|
|
||||||
|
echo $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function choose_patches() {
|
||||||
|
$nonce = $_POST['nonce_name'];
|
||||||
|
if (!wp_verify_nonce($nonce, 'action_name')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
error_log("is logged in: " . json_encode(is_user_logged_in()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//// handling routes and endpoints
|
||||||
|
//// diff routes and endpoints : https://stackoverflow.com/q/56075017/9497573
|
||||||
|
//function admin_menu_routes_endpoints() {
|
||||||
|
// $base_rest_route = Fbpatch::URL_BASE_REST_ROUTE;
|
||||||
|
// register_rest_route($base_rest_route, '/choose', array(
|
||||||
|
// 'methods' => 'POST',
|
||||||
|
// 'callback' => __NAMESPACE__.'\choose_patches',
|
||||||
|
// ));
|
||||||
|
//};
|
||||||
|
//add_action('rest_api_init', __NAMESPACE__.'\admin_menu_routes_endpoints');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user