- v 0.3.2 : can hide or show admin menu

This commit is contained in:
asus
2024-03-17 23:00:39 +01:00
parent fcb15c97d1
commit 82b6593dd9
8 changed files with 285 additions and 13 deletions

View File

@@ -4,7 +4,7 @@ Plugin Name: cipf_plugin
Plugin URI: Plugin URI:
Description: Description:
Author: hugogogo Author: hugogogo
Version: 0.3.1 Version: 0.3.2
Author URI: Author URI:
*/ */
@@ -32,7 +32,8 @@ include_once( plugin_dir_path(__FILE__) . '/utils/plgntls_class.php');
include_once(PLGNTLS_class::root_path() . 'php/utils/globals.php'); include_once(PLGNTLS_class::root_path() . 'php/utils/globals.php');
include_once(PLGNTLS_class::root_path() . 'utils/console_log.php'); include_once(PLGNTLS_class::root_path() . 'utils/console_log.php');
include_once(PLGNTLS_class::root_path() . 'php/admin_menu/example_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/paypal/paypal.php'); include_once(PLGNTLS_class::root_path() . 'php/paypal/paypal.php');

View File

@@ -13,23 +13,21 @@ if (!defined('ABSPATH')) {
/* /*
* menu plugin * menu plugin
*/ */
function cipfcard_plugin_menu() { function cipf_plugin_menu_CIPF() {
PLGNTLS_class::debug_infos(); PLGNTLS_class::debug_infos();
add_menu_page $menu_page_title = 'cipf';
( $menu_title = 'cipf';
'cipf_card', // webpage title $menu_capability = 'manage_options';
'cipf_card', // menu title $menu_slug = 'cipf-plugin';
'manage_options', // capability $menu_callback = 'add_plugin_content_CIPF';
'cipfcard-plugin', // menu_slug toggle_menu_CIPF($menu_page_title, $menu_title, $menu_capability, $menu_slug, $menu_callback);
'cipfcard_plugin_content' // callback function to display page content
);
} }
add_action('admin_menu', 'cipfcard_plugin_menu'); add_action('admin_menu', 'cipf_plugin_menu_CIPF');
function cipfcard_plugin_content() { function add_plugin_content_CIPF() {
PLGNTLS_class::debug_infos(); PLGNTLS_class::debug_infos();
$cipfcard = new PLGNTLS_class(); $cipfcard = new PLGNTLS_class();

View File

@@ -0,0 +1,107 @@
<?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 toggle_menu_CIPF($menu_page_title, $menu_title, $menu_capability, $menu_slug, $menu_callback) {
$toggle_menu = PLGNTLS_class::TOGGLE_ADMIN_MENU;
if (false === get_option($toggle_menu['_name'])) {
add_option($toggle_menu['_name'], $toggle_menu['hide']);
}
$toggle = get_option($toggle_menu['_name']);
if ($toggle === $toggle_menu['hide']) {
remove_menu_page($menu_slug);
}
else if ($toggle === $toggle_menu['show']) {
add_menu_page($menu_page_title, $menu_title, $menu_capability, $menu_slug, $menu_callback);
}
}
/*
* add link under the plugin in the plugins admin page
*
*/
function add_link_to_custer_plugin_CIPF($links) {
$slug_toggle = PLGNTLS_class::SLUG_TOOGLE_ADMIN_MENU;
$toggle_menu = PLGNTLS_class::TOGGLE_ADMIN_MENU;
$toggle = get_option($toggle_menu['_name']);
if ($toggle === $toggle_menu['hide']) {
$links[] = '<a href="/'.$slug_toggle['_name'].'?'.$slug_toggle['toggle'].'='.$slug_toggle['show'].'">show menu</a>';
}
else if ($toggle === $toggle_menu['show']) {
$links[] = '<a href="/'.$slug_toggle['_name'].'?'.$slug_toggle['toggle'].'='.$slug_toggle['hide'].'">hide menu</a>';
}
return $links;
}
add_filter('plugin_action_links_cipf_plugin/cipf_plugin.php', 'add_link_to_custer_plugin_CIPF');
/*
* handle the toggle menu when url is reached
*
*/
function toggle_custer_plugin_menu_CIPF() {
$slug_toggle = PLGNTLS_class::SLUG_TOOGLE_ADMIN_MENU;
$toggle_menu = PLGNTLS_class::TOGGLE_ADMIN_MENU;
global $wp;
$current_slug = $wp->request;
if ($current_slug !== $slug_toggle['_name']) {
return;
}
$show = null;
if (!isset($_GET)) {
$show = null;
}
else if (empty($_GET)) {
$show = null;
}
if (!isset($_GET[$slug_toggle['toggle']])) {
$show = null;
}
else if ($_GET[$slug_toggle['toggle']] === $slug_toggle['show']) {
$show = true;
}
else if ($_GET[$slug_toggle['toggle']] === $slug_toggle['hide']) {
$show = false;
}
if ($show === true) {
update_option($toggle_menu['_name'], $toggle_menu['show']);
}
else if ($show === false) {
update_option($toggle_menu['_name'], $toggle_menu['hide']);
}
$plugins_menu_url = admin_url('plugins.php');
wp_redirect($plugins_menu_url, 301);
exit;
}
add_action('template_redirect', 'toggle_custer_plugin_menu_CIPF');
?>

View File

@@ -107,6 +107,9 @@ class PLGNTLS_class {
const USER_INFO_DATE_FORMAT = 'd/m/Y'; // for user_infos.php (date format : https://www.php.net/manual/fr/datetime.format.php) const USER_INFO_DATE_FORMAT = 'd/m/Y'; // for user_infos.php (date format : https://www.php.net/manual/fr/datetime.format.php)
const ADMIN_VALIDATE_PROF_FIELD = 'admin_activate_prof_cipf'; // for admin_modif_prof.php const ADMIN_VALIDATE_PROF_FIELD = 'admin_activate_prof_cipf'; // for admin_modif_prof.php
// 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'];
private static $_DEBUG_INFOS = false; private static $_DEBUG_INFOS = false;

View File

@@ -0,0 +1,48 @@
<?php
namespace CUSTER;
/*
* 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 custer_plugin_content() {
echo "<p>hello</p>";
}
/*
* menu plugin
*/
function custer_plugin_menu() {
$menu_page_title = 'custer';
$menu_title = 'custer';
$menu_capability = 'manage_options';
$menu_slug = 'custer-plugin';
$menu_callback = __NAMESPACE__.'\custer_plugin_content';
\CUSTER\toggle_menu($menu_page_title, $menu_title, $menu_capability, $menu_slug, $menu_callback);
}
add_action('admin_menu', __NAMESPACE__.'\custer_plugin_menu');
?>

View File

@@ -0,0 +1,108 @@
<?php
namespace CUSTER;
/*
* 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 toggle_menu($menu_page_title, $menu_title, $menu_capability, $menu_slug, $menu_callback) {
$toggle_menu = Custer::TOGGLE_ADMIN_MENU;
if (false === get_option($toggle_menu['_name'])) {
add_option($toggle_menu['_name'], $toggle_menu['hide']);
}
$toggle = get_option($toggle_menu['_name']);
if ($toggle === $toggle_menu['hide']) {
remove_menu_page($menu_slug);
}
else if ($toggle === $toggle_menu['show']) {
add_menu_page($menu_page_title, $menu_title, $menu_capability, $menu_slug, $menu_callback);
}
}
/*
* add link under the plugin in the plugins admin page
*
*/
function add_link_to_custer_plugin($links) {
$slug_toggle = Custer::SLUG_TOOGLE_ADMIN_MENU;
$toggle_menu = Custer::TOGGLE_ADMIN_MENU;
$toggle = get_option($toggle_menu['_name']);
if ($toggle === $toggle_menu['hide']) {
$links[] = '<a href="/'.$slug_toggle['_name'].'?'.$slug_toggle['toggle'].'='.$slug_toggle['show'].'">show menu</a>';
}
else if ($toggle === $toggle_menu['show']) {
$links[] = '<a href="/'.$slug_toggle['_name'].'?'.$slug_toggle['toggle'].'='.$slug_toggle['hide'].'">hide menu</a>';
}
return $links;
}
add_filter('plugin_action_links_custer/custer.php', __NAMESPACE__.'\add_link_to_custer_plugin');
/*
* handle the toggle menu when url is reached
*
*/
function toggle_custer_plugin_menu() {
$slug_toggle = Custer::SLUG_TOOGLE_ADMIN_MENU;
$toggle_menu = Custer::TOGGLE_ADMIN_MENU;
global $wp;
$current_slug = $wp->request;
if ($current_slug !== $slug_toggle['_name']) {
return;
}
$show = null;
if (!isset($_GET)) {
$show = null;
}
else if (empty($_GET)) {
$show = null;
}
if (!isset($_GET[$slug_toggle['toggle']])) {
$show = null;
}
else if ($_GET[$slug_toggle['toggle']] === $slug_toggle['show']) {
$show = true;
}
else if ($_GET[$slug_toggle['toggle']] === $slug_toggle['hide']) {
$show = false;
}
if ($show === true) {
update_option($toggle_menu['_name'], $toggle_menu['show']);
}
else if ($show === false) {
update_option($toggle_menu['_name'], $toggle_menu['hide']);
}
$plugins_menu_url = admin_url('plugins.php');
wp_redirect($plugins_menu_url, 301);
exit;
}
add_action('template_redirect', __NAMESPACE__.'\toggle_custer_plugin_menu');
?>

View File

@@ -24,6 +24,9 @@ include_once(plugin_dir_path(__FILE__) . '/format_user_infos.php');
include_once(plugin_dir_path(__FILE__) . '/user_infos.php'); include_once(plugin_dir_path(__FILE__) . '/user_infos.php');
include_once(plugin_dir_path(__FILE__) . '/filter_mail.php'); include_once(plugin_dir_path(__FILE__) . '/filter_mail.php');
include_once(plugin_dir_path(__FILE__) . '/admin_menu.php');
include_once(plugin_dir_path(__FILE__) . '/admin_menu_toggle.php');
//add_shortcode('custer_change_id', 'CUSTER\shortcode_change_id'); //add_shortcode('custer_change_id', 'CUSTER\shortcode_change_id');

View File

@@ -18,6 +18,9 @@ if (!defined('ABSPATH')) {
class Custer { class Custer {
const USER_INFO_DATE_FORMAT = 'd/m/Y'; // for user_infos.php (date format : https://www.php.net/manual/fr/datetime.format.php) const USER_INFO_DATE_FORMAT = 'd/m/Y'; // for user_infos.php (date format : https://www.php.net/manual/fr/datetime.format.php)
const SLUG_TOOGLE_ADMIN_MENU = ['_name'=>'toogle_admin_menu_url_custer', 'toggle'=>'toggle', 'show'=>'show', 'hide'=>'hide'];
const TOGGLE_ADMIN_MENU = ['_name'=>'toggle_admin_menu_option_custer', 'show'=>'show', 'hide'=>'hide'];
private static $_backup_current_user = null; private static $_backup_current_user = null;
@@ -40,6 +43,7 @@ class Custer {
} }
} }