- v 0.3.2 : can hide or show admin menu
This commit is contained in:
@@ -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();
|
||||
|
||||
107
plugins/cipf_plugin/php/admin_menu/admin_menu_toggle.php
Normal file
107
plugins/cipf_plugin/php/admin_menu/admin_menu_toggle.php
Normal 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');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user