PluginProbe
Hostinger Tools / 3.0.5
Hostinger Tools v3.0.5
3.0.77 3.0.76 3.0.75 3.0.74 3.0.73 3.0.72 3.0.71 3.0.70 3.0.69 3.0.68 3.0.67 3.0.66 1.8.1 1.8.2 1.8.3 1.9.1 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.4 All 108 releases
hostinger / includes / Cli / Commands / Maintenance.php

Maintenance.php in Hostinger Tools 3.0.5, at includes/Cli/Commands/Maintenance.php

73 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Hostinger\Cli\Commands;
4
5 use Hostinger\Admin\PluginSettings;
6 use WP_CLI;
7 use Hostinger\Settings;
8
9 defined( 'ABSPATH' ) || exit;
10
11 class Maintenance {
12
13 public static function define_command(): void {
14 if ( class_exists( '\WP_CLI' ) ) {
15 WP_CLI::add_command( 'hostinger maintenance', self::class );
16 }
17 }
18
19 /**
20 * Command allows enable/disable maintenance mode.
21 *
22 * @param array $args
23 *
24 * @return void
25 * @throws \Exception
26 */
27 public function mode( array $args ): void {
28 if ( empty( $args ) ) {
29 WP_CLI::error( 'Arguments cannot be empty. Use 0 or 1' );
30 }
31
32 if ( has_action( 'litespeed_purge_all' ) ) {
33 do_action( 'litespeed_purge_all' );
34 }
35
36 $plugin_settings = new PluginSettings();
37 $plugin_options = $plugin_settings->get_plugin_settings();
38
39 switch ( $args[0] ) {
40 case '1':
41 $plugin_options->set_maintenance_mode( true );
42 WP_CLI::success( 'Maintenance mode ENABLED' );
43 break;
44 case '0':
45 $plugin_options->set_maintenance_mode( false );
46 WP_CLI::success( 'Maintenance mode DISABLED' );
47 break;
48 default:
49 throw new \Exception( 'Invalid maintenance mode value' );
50 }
51
52 $plugin_settings->save_plugin_settings( $plugin_options );
53 }
54
55 /**
56 * Command return maintenance mode status.
57 *
58 * @return bool
59 */
60 public function status(): bool {
61 $plugin_settings = new PluginSettings();
62 $plugin_options = $plugin_settings->get_plugin_settings();
63
64 if ( $plugin_options->get_maintenance_mode() ) {
65 WP_CLI::success( 'Maintenance mode ENABLED' );
66 } else {
67 WP_CLI::success( 'Maintenance mode DISABLED' );
68 }
69
70 return (bool) $plugin_options->get_maintenance_mode();
71 }
72 }
73