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