From 59b9acc55e58b52d84a69410e853830f6c44e95c Mon Sep 17 00:00:00 2001 From: asus Date: Wed, 3 Apr 2024 12:37:04 +0200 Subject: [PATCH] fixed small errors in plugin tools for options and menu --- plugins/cipf_plugin/plgntls_class.php | 28 +++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/plugins/cipf_plugin/plgntls_class.php b/plugins/cipf_plugin/plgntls_class.php index a9c7672..4b5eaf3 100644 --- a/plugins/cipf_plugin/plgntls_class.php +++ b/plugins/cipf_plugin/plgntls_class.php @@ -117,6 +117,8 @@ class Plgntls { * 'add menu' init * */ + $option_admin_menu_name = self::$_option_toggle_menu['_name']; + self::$_option_toggle_menu['_name'] = $option_admin_menu_name . self::$_plugin_dir; add_filter("plugin_action_links_".self::$_plugin_dir."/".self::$_main_file, function($links) { return self::_add_link_to_plugin($links); }); @@ -126,8 +128,8 @@ class Plgntls { * 'handle options' init * */ - self::$_options_action = 'action_for_admin_post_options_'.self::$_prefix; - self::$_options_list = 'list_of_options_for_this_plugin_'.self::$_prefix; + self::$_options_action = 'action_for_admin_post_options_'.self::$_plugin_dir; + self::$_options_list = 'list_of_options_for_this_plugin_'.self::$_plugin_dir; if (false === get_option(self::$_options_list)) { add_option(self::$_options_list, '', '', 'no'); } @@ -878,10 +880,11 @@ class Plgntls { * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + '_name'=>'toggle_admin_menu_option_cipf', */ - const OPTION_TOGGLE_MENU = [ - '_name'=>'toggle_admin_menu_option_xtxpatch', + private static $_option_toggle_menu = [ + '_name'=>'toggle_admin_menu_option_', '_default'=>'hide', 'show'=>'show', 'hide'=>'hide', @@ -900,6 +903,8 @@ class Plgntls { * */ self::init_class(); +$toggle_menu = self::$_option_toggle_menu; +error_log("toggle menu: " . json_encode($toggle_menu)); if (empty($menu_options)) { return; @@ -953,7 +958,8 @@ class Plgntls { } } private static function _toggle_menu($menu_page_title, $menu_title, $menu_capability, $menu_slug, $menu_callback) { - $toggle_menu = self::OPTION_TOGGLE_MENU; + $toggle_menu = self::$_option_toggle_menu; +error_log("toggle menu: " . json_encode($toggle_menu)); $toggle = self::get_option_safe($toggle_menu); @@ -971,7 +977,8 @@ class Plgntls { * */ private static function _add_link_to_plugin($links) { - $option_toggle = self::OPTION_TOGGLE_MENU; + $option_toggle = self::$_option_toggle_menu; +error_log("toggle menu: " . json_encode($option_toggle)); $toggle = self::get_option_safe($option_toggle); if (false === $toggle) { @@ -1094,6 +1101,15 @@ class Plgntls { $ret_option = $option_unserialized; } + /* + * if option is an array and _name is not define, + * add the _name entry to the output, to facilitate the access to the name + * + */ + if (is_array($ret_option) && !isset($ret_option['_name'])) { + $ret_option['_name'] = $option_name; + } + return $ret_option; }