updated options to make them not automatically loaded when added
This commit is contained in:
@@ -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');
|
||||
|
||||
?>
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user