| @@ -7,72 +7,75 @@ | ||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | namespace MainWP\Dashboard\Module\Log; |
| 10 | 10 | |
| 11 | -use MainWP\Dashboard\MainWP_Includes; | |
| 12 | - | |
| 13 | 11 | defined( 'ABSPATH' ) || exit; |
| 14 | 12 | |
| 15 | 13 | /** |
| 16 | 14 | * Logs class. |
| 17 | 15 | */ |
| 18 | -class MainWP_Module_Log { | |
| 19 | - /** | |
| 20 | - * Load required files and hooks to make the CLI work. | |
| 21 | - */ | |
| 22 | - public function __construct() { | |
| 23 | - $this->includes(); | |
| 24 | - add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) ); | |
| 25 | - add_filter( 'mainwp_init_load_all_options', array( $this, 'hook_load_options' ) ); | |
| 26 | - add_action( 'mainwp_system_init', array( $this, 'hook_mainwp_system_init' ) ); | |
| 27 | - } | |
| 16 | +class MainWP_Module_Log { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. | |
| 28 | 17 | |
| 29 | - /** | |
| 30 | - * Init method. | |
| 31 | - */ | |
| 32 | - public function plugins_loaded() { | |
| 33 | - if ( class_exists( '\MainWP\Dashboard\Module\Log\Log_Install' ) ) { | |
| 34 | - Log_Install::instance()->install(); | |
| 35 | - } | |
| 36 | - } | |
| 18 | + /** | |
| 19 | + * Load required files and hooks to make the CLI work. | |
| 20 | + */ | |
| 21 | + public function __construct() { | |
| 22 | + $this->includes(); | |
| 23 | + add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) ); | |
| 24 | + add_filter( 'mainwp_init_load_all_options', array( $this, 'hook_load_options' ) ); | |
| 25 | + add_action( 'mainwp_system_init', array( $this, 'hook_mainwp_system_init' ) ); | |
| 26 | + } | |
| 27 | + /** | |
| 28 | + * Method get_instance(). | |
| 29 | + */ | |
| 30 | + public static function get_instance() { | |
| 31 | + return new self(); | |
| 32 | + } | |
| 37 | 33 | |
| 38 | - /** | |
| 39 | - * Load files. | |
| 40 | - */ | |
| 41 | - private function includes() { | |
| 42 | - $dir = MAINWP_MODULES_DIR; | |
| 43 | - // need to load log db install. | |
| 44 | - if ( file_exists( $dir . 'logs/classes/class-log-install.php' ) ) { | |
| 45 | - require_once $dir . 'logs/classes/class-log-install.php'; | |
| 46 | - } | |
| 47 | - if ( mainwp_modules_is_enabled( 'logs' ) ) { | |
| 48 | - if ( file_exists( $dir . 'logs/classes/class-log-manager.php' ) ) { | |
| 49 | - require_once $dir . 'logs/classes/class-log-manager.php'; | |
| 50 | - } | |
| 51 | - } | |
| 52 | - } | |
| 34 | + /** | |
| 35 | + * Init method. | |
| 36 | + */ | |
| 37 | + public function plugins_loaded() { | |
| 38 | + if ( mainwp_modules_is_enabled( 'logs' ) && class_exists( '\MainWP\Dashboard\Module\Log\Log_Install' ) ) { | |
| 39 | + Log_Install::instance()->install(); | |
| 40 | + } | |
| 41 | + } | |
| 53 | 42 | |
| 54 | - /** | |
| 55 | - * Handle mainwp system init load options. | |
| 56 | - * | |
| 57 | - * @param array $all_opts All loading mainwp options. | |
| 58 | - * @return array $all_opts All loading mainwp options. | |
| 59 | - */ | |
| 60 | - public function hook_load_options( $all_opts ) { | |
| 61 | - if ( is_array( $all_opts ) ) { | |
| 62 | - $all_opts[] = 'mainwp_module_log_last_time_auto_purge_logs'; | |
| 63 | - $all_opts[] = 'mainwp_module_log_next_time_auto_purge_logs'; | |
| 64 | - } | |
| 65 | - return $all_opts; | |
| 66 | - } | |
| 43 | + /** | |
| 44 | + * Load files. | |
| 45 | + */ | |
| 46 | + private function includes() { | |
| 47 | + $dir = MAINWP_MODULES_DIR; | |
| 48 | + // need to load log db install. | |
| 49 | + if ( file_exists( $dir . 'logs/classes/class-log-install.php' ) ) { | |
| 50 | + require_once $dir . 'logs/classes/class-log-install.php'; // NOSONAR - WP compatible. | |
| 51 | + } | |
| 52 | + if ( mainwp_modules_is_enabled( 'logs' ) && file_exists( $dir . 'logs/classes/class-log-manager.php' ) ) { | |
| 53 | + require_once $dir . 'logs/classes/class-log-manager.php'; // NOSONAR - WP compatible. | |
| 54 | + } | |
| 55 | + } | |
| 67 | 56 | |
| 68 | - /** | |
| 69 | - * Handle mainwp system init. | |
| 70 | - */ | |
| 71 | - public function hook_mainwp_system_init() { | |
| 72 | - if ( mainwp_modules_is_enabled( 'logs' ) && class_exists( '\MainWP\Dashboard\Module\Log\Log_Manager' ) ) { | |
| 73 | - Log_Manager::instance(); | |
| 74 | - } | |
| 75 | - } | |
| 57 | + /** | |
| 58 | + * Handle mainwp system init load options. | |
| 59 | + * | |
| 60 | + * @param array $all_opts All loading mainwp options. | |
| 61 | + * @return array $all_opts All loading mainwp options. | |
| 62 | + */ | |
| 63 | + public function hook_load_options( $all_opts ) { | |
| 64 | + if ( is_array( $all_opts ) ) { | |
| 65 | + $all_opts[] = 'mainwp_module_log_last_time_auto_purge_logs'; | |
| 66 | + $all_opts[] = 'mainwp_module_log_next_time_auto_purge_logs'; | |
| 67 | + } | |
| 68 | + return $all_opts; | |
| 69 | + } | |
| 70 | + | |
| 71 | + /** | |
| 72 | + * Handle mainwp system init. | |
| 73 | + */ | |
| 74 | + public function hook_mainwp_system_init() { | |
| 75 | + if ( mainwp_modules_is_enabled( 'logs' ) && class_exists( '\MainWP\Dashboard\Module\Log\Log_Manager' ) ) { | |
| 76 | + Log_Manager::instance(); | |
| 77 | + } | |
| 78 | + } | |
| 76 | 79 | } |
| 77 | 80 | |
| 78 | -new MainWP_Module_Log(); | |
| 81 | +MainWP_Module_Log::get_instance(); | |