diff --git a/plugins/xtxpatch/php/classes/plgntls_class.php b/plugins/xtxpatch/php/classes/plgntls_class.php index 5dd03fc..fa39dd3 100644 --- a/plugins/xtxpatch/php/classes/plgntls_class.php +++ b/plugins/xtxpatch/php/classes/plgntls_class.php @@ -60,38 +60,78 @@ class Plgntls_xtx { private static $_instance_count = 0; private static $_adding_count = 0; + private static $_init_count = 0; private $_first_script = null; private $_first_style = null; - private $_prefix = 'PLGNTLS_XTX'; private $_js_dependencies = array(); private $_css_dependencies = array(); private $_scripts_attributes = array(); + private static $_prefix = null; + private static $_options_action = null; + private static $_options_list = null; + /* */ public function __construct() { ++self::$_instance_count; + self::init_class(); } - public static function debug_infos($level = null) { - self::_debug_infos($level); + + + + public static function init_class() { + if (self::$_init_count > 0) { + return; + } + ++self::$_init_count; + + self::$_prefix = strtoupper(__CLASS__); + + /* + * 'set paths and urls' init + * + */ + self::_init_root_dir(); + + + /* + * 'debug logs' init + * + */ + + + /* + * 'add to front' init + * + */ + + + /* + * 'add menu' init + * + */ + + + /* + * 'handle options' init + * + */ + self::$_options_action = 'action_for_admin_post_options_'.self::$_prefix; + self::$_options_list = 'list_of_options_for_this_plugin_'.self::$_prefix; + if (false === get_option(self::$_options_list)) { + add_option(self::$_options_list, '', '', 'no'); + } + add_action('admin_post_'.self::$_options_action, array(__CLASS__, '_handle_admin_post_option')); } - public static function add_to_front($srcs_arr = array(), $vars = array()) { - $instance = new self(); - return $instance->_add_to_front($srcs_arr, $vars); - } - - - - - @@ -102,7 +142,7 @@ class Plgntls_xtx { /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ( -* PRIVATE FUNCTIONS +* ACTIONS FUNCTIONS * * 1. set paths and urls * 2. debug logs @@ -165,6 +205,7 @@ class Plgntls_xtx { private static $_root_path; private static $_root_url; + /* * ex: * /home/www-data/cipf_plugin/php/test/test2/test3/test.php @@ -184,7 +225,7 @@ class Plgntls_xtx { * _main_file main_file,php * */ - private static function set_root_dir() { + private static function _init_root_dir() { if (isset(self::$_plugin_dir, self::$_file_name, self::$_file_dir_path, self::$_plugin_dir_path)) return ; /* @@ -211,11 +252,11 @@ class Plgntls_xtx { self::$_root_url = plugins_url(self::$_plugin_dir.'/'); } public static function root_path() { - self::set_root_dir(); + self::init_class(); return(self::$_root_path); } public static function root_url() { - self::set_root_dir(); + self::init_class(); return(self::$_root_url); } @@ -272,7 +313,7 @@ class Plgntls_xtx { * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - private static function _debug_infos($level) { + public static function debug_infos($level = null) { if (self::$_DEBUG_INFOS === 0) { return; } @@ -342,6 +383,11 @@ class Plgntls_xtx { + public static function add_to_front($srcs_arr = array(), $vars = array()) { + $instance = new self(); + return $instance->_add_to_front($srcs_arr, $vars); + } + private function _add_to_front($srcs_arr, $vars) { /* * even if the function is called with no srcs @@ -836,6 +882,7 @@ class Plgntls_xtx { const ACTION_TOOGLE_ADMIN_MENU = "toggle_admin_menu_url_xtxpatch"; const OPTION_TOGGLE_MENU = [ '_name'=>'toggle_admin_menu_option_xtxpatch', + '_callback'=>'', '_default'=>'hide', 'show'=>'show', 'hide'=>'hide', @@ -843,21 +890,21 @@ class Plgntls_xtx { - + /* + * options is the options needed to set a new menu + * see _create_menu below for more informations + * + */ public static function add_menu($options) { + self::init_class(); if (empty($options)) { return; } else if (is_string($options)) { $options = array('callback'=>$options); } - add_action('admin_menu', function() use ($options) { - return self::_create_menu($options); - }); - self::set_root_dir(); add_filter("plugin_action_links_".self::$_plugin_dir."/".self::$_main_file, array(__CLASS__, '_add_link_to_plugin')); - add_action('template_redirect', array(__CLASS__, '_toggle_plugin_menu')); - add_action('admin_post_'.self::ACTION_TOOGLE_ADMIN_MENU, array(__CLASS__, '_toggle_plugin_menu_action')); + self::_create_menu($options); } /* @@ -933,11 +980,6 @@ class Plgntls_xtx { } - public static function _toggle_plugin_menu_action() { -error_log("_POST" . json_encode($_POST)); -error_log("_GET" . json_encode($_GET)); -error_log("_REQUEST" . json_encode($_REQUEST)); - } /* @@ -945,7 +987,7 @@ error_log("_REQUEST" . json_encode($_REQUEST)); * triggered by template_redirect hook * */ - public static function _toggle_plugin_menu() { + public static function toggle_plugin_menu() { $slug_toggle = self::SLUG_TOOGLE_ADMIN_MENU; $toggle_menu = self::OPTION_TOGGLE_MENU; @@ -1039,12 +1081,10 @@ error_log("_REQUEST" . json_encode($_REQUEST)); */ - private static $_options = array(); public static function get_option_safe($option) { /* * first init option, in case it was not already - * then get it * */ if (false === self::_init_option($option)) { @@ -1054,12 +1094,21 @@ error_log("_REQUEST" . json_encode($_REQUEST)); } public static function get_option_link_href($option) { - $option_data = self::_get_option_data($option); + /* + * first init option, in case it was not already + * + */ + if (false === self::_init_option($option)) { + return null; + } + $option_data = self::_get_option_data($option['_name']); if (false === $option_data) { return null; } $href = admin_url('admin-post.php'); $href .= "?action=" . $option_data['_action']; + $href .= "&" . $option_data['_nonce_name'] . "=" . wp_create_nonce($option_data['_nonce_action']); + $href .= "&option_name=" . $option_data['_name']; return $href; } @@ -1077,20 +1126,28 @@ error_log("_REQUEST" . json_encode($_REQUEST)); } $form = '