/** * init module */ public static final function init() { $class = get_called_class(); if ($class) { $inst = new $class(); if (!$inst instanceof HW_Module) { return; } //get file name where a Class was Defined $reflector = new ReflectionClass($class); //path variables $inst->option('module_path', dirname($reflector->getFileName())); $module_slug = basename($inst->option('module_path')); $inst->option('module_name', $module_slug); $modules = HW_TGM_Module_Activation::get_register_modules(); if (isset($modules[$module_slug])) { $info = array_filter(HW_Plugins_Manager::get_module_info($reflector->getFileName())); //migrate module information if (!empty($info)) { $modules[$module_slug] = array_merge($modules[$module_slug], $info); } HW_Plugins_Manager::register_module($modules[$module_slug]); //update module data $inst->option('module_info', $modules[$module_slug]); } $inst->option('module_url', HW_HOANGWEB_PLUGINS_URL . '/' . $module_slug); HW_Module_Settings_page::add_module($module_slug, $inst); //setup actions belong to current module instance self::setup_actions($inst); //occur after all modules loaded add_action('hw_modules_loaded', array($inst, 'modules_loaded')); //after the module loaded if (method_exists($inst, 'module_loaded')) { $inst->module_loaded(); } //load cli class for the module $command = $inst->get_module_cli_path(); if (!empty($command) && defined('WP_CLI') && WP_CLI) { include_once $command; $cli_class = 'HW_CLI_' . HW_Validation::valid_objname($module_slug); //command line class WP_CLI::add_command($module_slug, strtoupper($cli_class)); //WP_CLI::get_command(); #wrong //add module commands to manager HW_CLI_Command_Utilities::get_instance()->register_cli_cmds($module_slug, HW_Core::get_child_class_methods($cli_class, ReflectionMethod::IS_PUBLIC)); } //load oher cli class for module $cli_files = $inst->get_commands(); if (is_array($cli_files)) { foreach ($cli_files as $cli) { //not found file to process command line, if (!$cli) { continue; } //!isset($cli['file']) purpose for module->register_cli that more cli class write in one file if (isset($cli['file'])) { include_once $cli['file']; } if (class_exists($cli['class'], false)) { WP_CLI::add_command($cli['command'], $cli['class']); //add module commands to manager HW_CLI_Command_Utilities::get_instance()->register_cli_cmds($cli['command'], HW_Core::get_child_class_methods($cli['class'], ReflectionMethod::IS_PUBLIC)); } } } } }