From aae40be620b5f4bb9fbd9bdefca67faa10dc5c6a Mon Sep 17 00:00:00 2001 From: asus Date: Sat, 23 Mar 2024 18:25:43 +0100 Subject: [PATCH] wip menu can now receive form with rest api, but no nonce --- plugins/cipf_plugin/utils/plgntls_fetch.js | 1 - plugins/fbpatch/html/menu.html | 11 ++++++++++ plugins/fbpatch/menu/admin_menu.php | 25 +++++++++++++++++++++- plugins/fbpatch/php/fbpatch_class.php | 1 + 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 plugins/fbpatch/html/menu.html diff --git a/plugins/cipf_plugin/utils/plgntls_fetch.js b/plugins/cipf_plugin/utils/plgntls_fetch.js index 2190cdf..0e3a503 100644 --- a/plugins/cipf_plugin/utils/plgntls_fetch.js +++ b/plugins/cipf_plugin/utils/plgntls_fetch.js @@ -9,7 +9,6 @@ export function PLGNTLS_fetch(url, options = {}) { options.headers = options.headers || {}; options.headers['X-WP-Nonce'] = PLGNTLS_data.fetch_nonce, - console.log("options:", options); return fetch(url, options); } diff --git a/plugins/fbpatch/html/menu.html b/plugins/fbpatch/html/menu.html new file mode 100644 index 0000000..3270276 --- /dev/null +++ b/plugins/fbpatch/html/menu.html @@ -0,0 +1,11 @@ +
+
+ + +
+
+ + +
+ +
diff --git a/plugins/fbpatch/menu/admin_menu.php b/plugins/fbpatch/menu/admin_menu.php index 695afa2..80de664 100644 --- a/plugins/fbpatch/menu/admin_menu.php +++ b/plugins/fbpatch/menu/admin_menu.php @@ -17,10 +17,33 @@ if (!defined('ABSPATH')) { * */ function plugin_content() { - echo "

hello

"; + $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'); + diff --git a/plugins/fbpatch/php/fbpatch_class.php b/plugins/fbpatch/php/fbpatch_class.php index 20a3aad..ffaf3ab 100644 --- a/plugins/fbpatch/php/fbpatch_class.php +++ b/plugins/fbpatch/php/fbpatch_class.php @@ -19,6 +19,7 @@ class Fbpatch { const SLUG_TOOGLE_ADMIN_MENU = ['_name'=>'toogle_admin_menu_url_fbpatch', 'toggle'=>'toggle', 'show'=>'show', 'hide'=>'hide']; const OPTION_TOGGLE_MENU = ['_name'=>'toggle_admin_menu_option_fbpatch', 'show'=>'show', 'hide'=>'hide']; + const URL_BASE_REST_ROUTE = 'fbpatch_plugin/api/v1'; // for routes, in php/paypal/routes.php && php/admin_modif_prof.php //private static $_is_