From 82b6593dd992f7263f7b6c3a9e5b546a72423d52 Mon Sep 17 00:00:00 2001
From: asus
Date: Sun, 17 Mar 2024 23:00:39 +0100
Subject: [PATCH] - v 0.3.2 : can hide or show admin menu
---
plugins/cipf_plugin/cipf_plugin.php | 5 +-
.../{example_menu.php => admin_menu.php} | 20 ++--
.../php/admin_menu/admin_menu_toggle.php | 107 +++++++++++++++++
plugins/cipf_plugin/utils/plgntls_class.php | 3 +
plugins/custer/admin_menu.php | 48 ++++++++
plugins/custer/admin_menu_toggle.php | 108 ++++++++++++++++++
plugins/custer/custer.php | 3 +
plugins/custer/custer_class.php | 4 +
8 files changed, 285 insertions(+), 13 deletions(-)
rename plugins/cipf_plugin/php/admin_menu/{example_menu.php => admin_menu.php} (79%)
create mode 100644 plugins/cipf_plugin/php/admin_menu/admin_menu_toggle.php
create mode 100644 plugins/custer/admin_menu.php
create mode 100644 plugins/custer/admin_menu_toggle.php
diff --git a/plugins/cipf_plugin/cipf_plugin.php b/plugins/cipf_plugin/cipf_plugin.php
index 0e9acde..4adfad9 100644
--- a/plugins/cipf_plugin/cipf_plugin.php
+++ b/plugins/cipf_plugin/cipf_plugin.php
@@ -4,7 +4,7 @@ Plugin Name: cipf_plugin
Plugin URI:
Description:
Author: hugogogo
-Version: 0.3.1
+Version: 0.3.2
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() . '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');
diff --git a/plugins/cipf_plugin/php/admin_menu/example_menu.php b/plugins/cipf_plugin/php/admin_menu/admin_menu.php
similarity index 79%
rename from plugins/cipf_plugin/php/admin_menu/example_menu.php
rename to plugins/cipf_plugin/php/admin_menu/admin_menu.php
index 36c1ab0..18193f9 100644
--- a/plugins/cipf_plugin/php/admin_menu/example_menu.php
+++ b/plugins/cipf_plugin/php/admin_menu/admin_menu.php
@@ -13,23 +13,21 @@ if (!defined('ABSPATH')) {
/*
* menu plugin
*/
-function cipfcard_plugin_menu() {
+function cipf_plugin_menu_CIPF() {
PLGNTLS_class::debug_infos();
- add_menu_page
- (
- 'cipf_card', // webpage title
- 'cipf_card', // menu title
- 'manage_options', // capability
- 'cipfcard-plugin', // menu_slug
- 'cipfcard_plugin_content' // callback function to display page content
- );
+ $menu_page_title = 'cipf';
+ $menu_title = 'cipf';
+ $menu_capability = 'manage_options';
+ $menu_slug = 'cipf-plugin';
+ $menu_callback = 'add_plugin_content_CIPF';
+ toggle_menu_CIPF($menu_page_title, $menu_title, $menu_capability, $menu_slug, $menu_callback);
}
-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();
$cipfcard = new PLGNTLS_class();
diff --git a/plugins/cipf_plugin/php/admin_menu/admin_menu_toggle.php b/plugins/cipf_plugin/php/admin_menu/admin_menu_toggle.php
new file mode 100644
index 0000000..c01b58e
--- /dev/null
+++ b/plugins/cipf_plugin/php/admin_menu/admin_menu_toggle.php
@@ -0,0 +1,107 @@
+show menu';
+ }
+ else if ($toggle === $toggle_menu['show']) {
+ $links[] = 'hide menu';
+ }
+ 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');
+
+
+
+
+
+?>
diff --git a/plugins/cipf_plugin/utils/plgntls_class.php b/plugins/cipf_plugin/utils/plgntls_class.php
index e9bfe3a..9dc40c7 100644
--- a/plugins/cipf_plugin/utils/plgntls_class.php
+++ b/plugins/cipf_plugin/utils/plgntls_class.php
@@ -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 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;
diff --git a/plugins/custer/admin_menu.php b/plugins/custer/admin_menu.php
new file mode 100644
index 0000000..3b04a26
--- /dev/null
+++ b/plugins/custer/admin_menu.php
@@ -0,0 +1,48 @@
+hello
";
+}
+
+
+
+
+
+
+/*
+* 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');
+
+
+
+
+
+
+
+?>
diff --git a/plugins/custer/admin_menu_toggle.php b/plugins/custer/admin_menu_toggle.php
new file mode 100644
index 0000000..bbf5e07
--- /dev/null
+++ b/plugins/custer/admin_menu_toggle.php
@@ -0,0 +1,108 @@
+show menu';
+ }
+ else if ($toggle === $toggle_menu['show']) {
+ $links[] = 'hide menu';
+ }
+ 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');
+
+
+
+
+
+?>
diff --git a/plugins/custer/custer.php b/plugins/custer/custer.php
index a18c2fc..0e51081 100644
--- a/plugins/custer/custer.php
+++ b/plugins/custer/custer.php
@@ -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__) . '/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');
diff --git a/plugins/custer/custer_class.php b/plugins/custer/custer_class.php
index eb77032..8323e31 100644
--- a/plugins/custer/custer_class.php
+++ b/plugins/custer/custer_class.php
@@ -18,6 +18,9 @@ if (!defined('ABSPATH')) {
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 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;
@@ -40,6 +43,7 @@ class Custer {
}
+
}