diff --git a/plugins/cipf_plugin/cipf_plugin.php b/plugins/cipf_plugin/cipf_plugin.php index e9c92ed..c527acd 100644 --- a/plugins/cipf_plugin/cipf_plugin.php +++ b/plugins/cipf_plugin/cipf_plugin.php @@ -30,6 +30,7 @@ include_once(PLGNTLS_class::root_path() . 'utils/console_log.php'); include_once(PLGNTLS_class::root_path() . 'php/admin_menu/admin_menu.php'); include_once(PLGNTLS_class::root_path() . 'php/admin_menu/admin_menu_toggle.php'); +include_once(PLGNTLS_class::root_path() . 'php/admin_menu/menu_content.php'); include_once(PLGNTLS_class::root_path() . 'php/paypal/paypal.php'); diff --git a/plugins/cipf_plugin/html/menu/cipf_menu.html b/plugins/cipf_plugin/html/menu/cipf_menu.html new file mode 100644 index 0000000..044b2e5 --- /dev/null +++ b/plugins/cipf_plugin/html/menu/cipf_menu.html @@ -0,0 +1,12 @@ + +
diff --git a/plugins/cipf_plugin/php/admin_menu/admin_menu.php b/plugins/cipf_plugin/php/admin_menu/admin_menu.php index 18193f9..59b92bb 100644 --- a/plugins/cipf_plugin/php/admin_menu/admin_menu.php +++ b/plugins/cipf_plugin/php/admin_menu/admin_menu.php @@ -27,26 +27,6 @@ add_action('admin_menu', 'cipf_plugin_menu_CIPF'); -function add_plugin_content_CIPF() { - PLGNTLS_class::debug_infos(); - $cipfcard = new PLGNTLS_class(); - - $my_css = ' - #mytext { - background-color: lightblue; - } - #mytext_2 { - background-color: lightgreen; - } - '; - echo $cipfcard->add_to_front( array( - array("js/menu/example_menu.js", 'type'=>'module'), - "css/menu/menu.css", - "PLGNTLS_menu_css" => array('css'=>$my_css), - "js/menu/example_menu_2.js", - "html/menu/example_menu.html", - )); -} /* @@ -59,17 +39,17 @@ ajax - to access the content of the data object properties of the ajax call : use $_POST['property_name'] */ -function cipfcard_menu_fetch_handler() { - PLGNTLS_class::debug_infos(); - return new WP_REST_Response('hello', 200); -} -function cipfcard_menu_endpoint() { - PLGNTLS_class::debug_infos(); - register_rest_route('plgntls', '/get_data', array( - 'methods' => 'POST', - 'callback' => 'cipfcard_menu_fetch_handler', - )); -}; -add_action('rest_api_init', 'cipfcard_menu_endpoint'); +//function cipfcard_menu_fetch_handler() { +// PLGNTLS_class::debug_infos(); +// return new WP_REST_Response('hello', 200); +//} +//function cipfcard_menu_endpoint() { +// PLGNTLS_class::debug_infos(); +// register_rest_route('plgntls', '/get_data', array( +// 'methods' => 'POST', +// 'callback' => 'cipfcard_menu_fetch_handler', +// )); +//}; +//add_action('rest_api_init', 'cipfcard_menu_endpoint'); ?> diff --git a/plugins/cipf_plugin/php/admin_menu/admin_menu_toggle.php b/plugins/cipf_plugin/php/admin_menu/admin_menu_toggle.php index c01b58e..4dfda19 100644 --- a/plugins/cipf_plugin/php/admin_menu/admin_menu_toggle.php +++ b/plugins/cipf_plugin/php/admin_menu/admin_menu_toggle.php @@ -12,10 +12,11 @@ if (!defined('ABSPATH')) { function toggle_menu_CIPF($menu_page_title, $menu_title, $menu_capability, $menu_slug, $menu_callback) { + PLGNTLS_class::debug_infos(); $toggle_menu = PLGNTLS_class::TOGGLE_ADMIN_MENU; if (false === get_option($toggle_menu['_name'])) { - add_option($toggle_menu['_name'], $toggle_menu['hide']); + add_option($toggle_menu['_name'], $toggle_menu['hide'], '', 'no'); } $toggle = get_option($toggle_menu['_name']); @@ -38,6 +39,7 @@ function toggle_menu_CIPF($menu_page_title, $menu_title, $menu_capability, $menu * */ function add_link_to_custer_plugin_CIPF($links) { + PLGNTLS_class::debug_infos(); $slug_toggle = PLGNTLS_class::SLUG_TOOGLE_ADMIN_MENU; $toggle_menu = PLGNTLS_class::TOGGLE_ADMIN_MENU; @@ -61,6 +63,7 @@ add_filter('plugin_action_links_cipf_plugin/cipf_plugin.php', 'add_link_to_custe * */ function toggle_custer_plugin_menu_CIPF() { + PLGNTLS_class::debug_infos(); $slug_toggle = PLGNTLS_class::SLUG_TOOGLE_ADMIN_MENU; $toggle_menu = PLGNTLS_class::TOGGLE_ADMIN_MENU; diff --git a/plugins/cipf_plugin/php/admin_menu/menu_content.php b/plugins/cipf_plugin/php/admin_menu/menu_content.php new file mode 100644 index 0000000..d1dd7a7 --- /dev/null +++ b/plugins/cipf_plugin/php/admin_menu/menu_content.php @@ -0,0 +1,109 @@ +"> +* +* +*/ +function paypal_credentials_CIPF() { + PLGNTLS_class::debug_infos(); + $nonce_paypal = PLGNTLS_class::ADMIN_MENU_NONCE_PAYPAL; + $sandbox_live = PLGNTLS_class::ADMIN_MENU_PAYPAL_SANDBOX_LIVE; + + if (!isset($_POST[$nonce_paypal['_name']])) { + redirect_menu_referer_CIPF($_POST); + exit; + } + if (!wp_verify_nonce($_POST[$nonce_paypal['_name']], $nonce_paypal['_action'])) { + redirect_menu_referer_CIPF($_POST); + exit; + } + + // do actions here + error_log("received form, _POST: " . json_encode($_POST)); + $is_sandbox = false; + if ($_POST[$sandbox_live['_name']] === $sandbox_live['sandbox']) { + $is_sandbox = true; + } + error_log("is sandbox: " . json_encode($is_sandbox)); + + /* + const OPTION_PAYPAL = [ + '_name'=>'cipf_paypal_credentials', + '_default' => [ + 'is_sandbox' =>true, + 'client_id' =>PAYPAL_HUGO_SBOX_CLIENT_ID, + 'client_secret'=>PAYPAL_HUGO_SBOX_CLIENT_SECRET, + ], + ]; + $paypal_credentials_option = get_option(PLGNTLS_class::OPTION_PAYPAL['_name']); + if (false === $paypal_credentials_option) { + add_option($paypal_credentials_option['_name'], serialize($paypal_credentials_option['_default']), '', 'no'); + } + $patches_option = unserialize($raw_patches_option); + $serialize_patches_option = serialize($patches_option); + update_option(self::$_patches['_name'], $serialize_patches_option); + */ + + redirect_menu_referer_CIPF($_POST); +} +add_action('admin_post_'.PLGNTLS_class::ADMIN_POST_PAYPAL, 'paypal_credentials_CIPF'); + + + + +function redirect_menu_referer_CIPF($post) { + PLGNTLS_class::debug_infos(); + if (!isset($post)) { + wp_redirect(admin_url(), 301); + exit; + } + if (is_null($post)) { + wp_redirect(admin_url(), 301); + exit; + } + if (empty($post)) { + wp_redirect(admin_url(), 301); + exit; + } + + if (!isset($post['_wp_http_referer'])) { + wp_redirect(admin_url(), 301); + exit; + } + + wp_redirect(home_url($post['_wp_http_referer']), 301); + exit; +} + + + +?> diff --git a/plugins/cipf_plugin/utils/plgntls_class.php b/plugins/cipf_plugin/utils/plgntls_class.php index 8cf5c59..1a76b83 100644 --- a/plugins/cipf_plugin/utils/plgntls_class.php +++ b/plugins/cipf_plugin/utils/plgntls_class.php @@ -119,10 +119,21 @@ class PLGNTLS_class { // SHORTCODES // OPTIONS + const OPTION_PAYPAL = [ + '_name'=>'cipf_paypal_credentials', + '_default' => [ + 'is_sandbox' =>true, + 'client_id' =>PAYPAL_HUGO_SBOX_CLIENT_ID, + 'client_secret'=>PAYPAL_HUGO_SBOX_CLIENT_SECRET, + ], + ]; - // MENU + // ADMIN MENU const SLUG_TOOGLE_ADMIN_MENU = ['_name'=>'toogle_admin_menu_url_cipf', 'toggle'=>'toggle', 'show'=>'show', 'hide'=>'hide']; const TOGGLE_ADMIN_MENU = ['_name'=>'toggle_admin_menu_option_cipf', 'show'=>'show', 'hide'=>'hide']; + const ADMIN_POST_PAYPAL = 'paypal_credentials_CIPF'; + const ADMIN_MENU_NONCE_PAYPAL = ['_name'=>'nonce_admin_menu_paypal_cipf', '_action'=>'action_admin_menu_paypal_cipf']; + const ADMIN_MENU_PAYPAL_SANDBOX_LIVE = ['_name'=>'sandbox_live', 'sandbox'=>'sandbox', 'live'=>'live']; // FORMS const FORM_PROF_COMMANDE_ID = 'prof_commande'; diff --git a/plugins/custer/admin_menu_toggle.php b/plugins/custer/admin_menu_toggle.php index 89eeff2..77102f9 100644 --- a/plugins/custer/admin_menu_toggle.php +++ b/plugins/custer/admin_menu_toggle.php @@ -16,7 +16,7 @@ function toggle_menu($menu_page_title, $menu_title, $menu_capability, $menu_slug $toggle_menu = Custer::OPTION_TOGGLE_MENU; if (false === get_option($toggle_menu['_name'])) { - add_option($toggle_menu['_name'], $toggle_menu['hide']); + add_option($toggle_menu['_name'], $toggle_menu['hide'], '', 'no'); } $toggle = get_option($toggle_menu['_name']); diff --git a/plugins/fbpatch/menu/admin_menu_toggle.php b/plugins/fbpatch/menu/admin_menu_toggle.php index a9f7ec8..cdff7eb 100644 --- a/plugins/fbpatch/menu/admin_menu_toggle.php +++ b/plugins/fbpatch/menu/admin_menu_toggle.php @@ -16,7 +16,7 @@ function toggle_menu($menu_page_title, $menu_title, $menu_capability, $menu_slug $toggle_menu = Fbpatch::OPTION_TOGGLE_MENU; if (false === get_option($toggle_menu['_name'])) { - add_option($toggle_menu['_name'], $toggle_menu['hide']); + add_option($toggle_menu['_name'], $toggle_menu['hide'], '', 'no'); } $toggle = get_option($toggle_menu['_name']); diff --git a/plugins/fbpatch/menu/menu_content.php b/plugins/fbpatch/menu/menu_content.php index 2009dce..e0c9b5f 100644 --- a/plugins/fbpatch/menu/menu_content.php +++ b/plugins/fbpatch/menu/menu_content.php @@ -28,7 +28,15 @@ function plugin_content() { - +/* +* use this hook 'admin_post_{$action}' to receive a form post +* https://developer.wordpress.org/reference/hooks/admin_post_action/ +* +* add the url to the action atrtibute of form, and the value of the action in an hidden input +*