updated options to make them not automatically loaded when added
This commit is contained in:
@@ -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.php');
|
||||||
include_once(PLGNTLS_class::root_path() . 'php/admin_menu/admin_menu_toggle.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');
|
include_once(PLGNTLS_class::root_path() . 'php/paypal/paypal.php');
|
||||||
|
|
||||||
|
|||||||
12
plugins/cipf_plugin/html/menu/cipf_menu.html
Normal file
12
plugins/cipf_plugin/html/menu/cipf_menu.html
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<!-- https://developer.wordpress.org/reference/hooks/admin_post_action/ -->
|
||||||
|
<form method="POST" action="<?php echo admin_url( 'admin-post.php' ); ?>">
|
||||||
|
<input type="hidden" name="action" value="<?php echo $admin_post_paypal; ?>">
|
||||||
|
<?php wp_nonce_field($nonce_paypal['_action'], $nonce_paypal['_name']); ?>
|
||||||
|
<div class="input_wrapper">
|
||||||
|
<input type="radio" id="sandbox" name="<?php echo $sandbox_live['_name']; ?>" value="<?php echo $sandbox_live['sandbox']; ?>" checked />
|
||||||
|
<label for="sandbox">sandbox</label>
|
||||||
|
<input type="radio" id="live" name="<?php echo $sandbox_live['_name']; ?>" value="<?php echo $sandbox_live['live']; ?>" />
|
||||||
|
<label for="live">live</label>
|
||||||
|
</div>
|
||||||
|
<input type="submit" value="send"/>
|
||||||
|
</form>
|
||||||
@@ -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 :
|
- to access the content of the data object properties of the ajax call :
|
||||||
use $_POST['property_name']
|
use $_POST['property_name']
|
||||||
*/
|
*/
|
||||||
function cipfcard_menu_fetch_handler() {
|
//function cipfcard_menu_fetch_handler() {
|
||||||
PLGNTLS_class::debug_infos();
|
// PLGNTLS_class::debug_infos();
|
||||||
return new WP_REST_Response('hello', 200);
|
// return new WP_REST_Response('hello', 200);
|
||||||
}
|
//}
|
||||||
function cipfcard_menu_endpoint() {
|
//function cipfcard_menu_endpoint() {
|
||||||
PLGNTLS_class::debug_infos();
|
// PLGNTLS_class::debug_infos();
|
||||||
register_rest_route('plgntls', '/get_data', array(
|
// register_rest_route('plgntls', '/get_data', array(
|
||||||
'methods' => 'POST',
|
// 'methods' => 'POST',
|
||||||
'callback' => 'cipfcard_menu_fetch_handler',
|
// 'callback' => 'cipfcard_menu_fetch_handler',
|
||||||
));
|
// ));
|
||||||
};
|
//};
|
||||||
add_action('rest_api_init', 'cipfcard_menu_endpoint');
|
//add_action('rest_api_init', 'cipfcard_menu_endpoint');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -12,10 +12,11 @@ if (!defined('ABSPATH')) {
|
|||||||
|
|
||||||
|
|
||||||
function toggle_menu_CIPF($menu_page_title, $menu_title, $menu_capability, $menu_slug, $menu_callback) {
|
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;
|
$toggle_menu = PLGNTLS_class::TOGGLE_ADMIN_MENU;
|
||||||
|
|
||||||
if (false === get_option($toggle_menu['_name'])) {
|
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']);
|
$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) {
|
function add_link_to_custer_plugin_CIPF($links) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
$slug_toggle = PLGNTLS_class::SLUG_TOOGLE_ADMIN_MENU;
|
$slug_toggle = PLGNTLS_class::SLUG_TOOGLE_ADMIN_MENU;
|
||||||
$toggle_menu = PLGNTLS_class::TOGGLE_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() {
|
function toggle_custer_plugin_menu_CIPF() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
$slug_toggle = PLGNTLS_class::SLUG_TOOGLE_ADMIN_MENU;
|
$slug_toggle = PLGNTLS_class::SLUG_TOOGLE_ADMIN_MENU;
|
||||||
$toggle_menu = PLGNTLS_class::TOGGLE_ADMIN_MENU;
|
$toggle_menu = PLGNTLS_class::TOGGLE_ADMIN_MENU;
|
||||||
|
|
||||||
|
|||||||
109
plugins/cipf_plugin/php/admin_menu/menu_content.php
Normal file
109
plugins/cipf_plugin/php/admin_menu/menu_content.php
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function add_plugin_content_CIPF() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$admin_post_paypal = PLGNTLS_class::ADMIN_POST_PAYPAL;
|
||||||
|
$nonce_paypal = PLGNTLS_class::ADMIN_MENU_NONCE_PAYPAL;
|
||||||
|
$sandbox_live = PLGNTLS_class::ADMIN_MENU_PAYPAL_SANDBOX_LIVE;
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
include(PLGNTLS_class::root_path() . '/html/menu/cipf_menu.html');
|
||||||
|
$html = ob_get_clean();
|
||||||
|
echo $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
* <form method="POST" action="<?php echo admin_url( 'admin-post.php' ); ?>">
|
||||||
|
* <input type="hidden" name="action" value="<?php echo $admin_post_patches; ?>">
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -119,10 +119,21 @@ class PLGNTLS_class {
|
|||||||
// SHORTCODES
|
// SHORTCODES
|
||||||
|
|
||||||
// OPTIONS
|
// 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 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 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
|
// FORMS
|
||||||
const FORM_PROF_COMMANDE_ID = 'prof_commande';
|
const FORM_PROF_COMMANDE_ID = 'prof_commande';
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ function toggle_menu($menu_page_title, $menu_title, $menu_capability, $menu_slug
|
|||||||
$toggle_menu = Custer::OPTION_TOGGLE_MENU;
|
$toggle_menu = Custer::OPTION_TOGGLE_MENU;
|
||||||
|
|
||||||
if (false === get_option($toggle_menu['_name'])) {
|
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']);
|
$toggle = get_option($toggle_menu['_name']);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ function toggle_menu($menu_page_title, $menu_title, $menu_capability, $menu_slug
|
|||||||
$toggle_menu = Fbpatch::OPTION_TOGGLE_MENU;
|
$toggle_menu = Fbpatch::OPTION_TOGGLE_MENU;
|
||||||
|
|
||||||
if (false === get_option($toggle_menu['_name'])) {
|
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']);
|
$toggle = get_option($toggle_menu['_name']);
|
||||||
|
|||||||
@@ -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
|
||||||
|
* <form method="POST" action="<?php echo admin_url( 'admin-post.php' ); ?>">
|
||||||
|
* <input type="hidden" name="action" value="<?php echo $admin_post_patches; ?>">
|
||||||
|
*
|
||||||
|
*/
|
||||||
function patches_choice() {
|
function patches_choice() {
|
||||||
$nonce = Fbpatch::NONCE;
|
$nonce = Fbpatch::NONCE;
|
||||||
if (!isset($_POST[$nonce['_name']])) {
|
if (!isset($_POST[$nonce['_name']])) {
|
||||||
@@ -43,12 +51,12 @@ function patches_choice() {
|
|||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
[24-Mar-2024 12:24:08 UTC] -> _POST {
|
[24-Mar-2024 12:24:08 UTC] -> _POST {
|
||||||
"action":"add_patches",
|
"action":"add_patches",
|
||||||
"nonce_name":"7eeb560dc0",
|
"nonce_name":"7eeb560dc0",
|
||||||
"_wp_http_referer":"\/wp-admin\/admin.php?page=fbpatch-plugin",
|
"_wp_http_referer":"\/wp-admin\/admin.php?page=fbpatch-plugin",
|
||||||
"hide_show":"on"
|
"hide_show":"on"
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
$pathes_on = array();
|
$pathes_on = array();
|
||||||
foreach($_POST as $key => $value) {
|
foreach($_POST as $key => $value) {
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class Fbpatch {
|
|||||||
*/
|
*/
|
||||||
$raw_patches_option = get_option(self::$_patches['_name']);
|
$raw_patches_option = get_option(self::$_patches['_name']);
|
||||||
if (false === $raw_patches_option) {
|
if (false === $raw_patches_option) {
|
||||||
add_option(self::$_patches['_name']);
|
add_option(self::$_patches['_name'], '', '', 'no');
|
||||||
}
|
}
|
||||||
$patches_option = unserialize($raw_patches_option);
|
$patches_option = unserialize($raw_patches_option);
|
||||||
if (empty($patches_option)) {
|
if (empty($patches_option)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user