PluginProbe
Hostinger Tools / 2.2.2
Hostinger Tools v2.2.2
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 2.2.2, at includes/Cli/Commands/Maintenance.php

76 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 WP_CLI;
6 use Hostinger\Settings;
7
8 defined( 'ABSPATH' ) || exit;
9
10 class Maintenance {
11
12 public static function define_command(): void {
13 if ( class_exists( '\WP_CLI' ) ) {
14 WP_CLI::add_command( 'hostinger maintenance', self::class );
15 }
16 }
17
18 /**
19 * Command allows enable/disable maintenance mode.
20 *
21 * ## EXAMPLES
22 *
23 * # Enable maintenance mode
24 * $ wp hostinger maintenance mode 1
25 *
26 * # Disable maintenance mode
27 * $ wp hostinger maintenance mode 0
28 *
29 * @param array $args WP-CLI positional arguments.
30 *
31 * @throws \Exception If pass bad argument.
32 */
33 public function mode( array $args ): void {
34 if ( empty( $args ) ) {
35 WP_CLI::error( 'Arguments cannot be empty. Use 0 or 1' );
36 }
37
38 if ( has_action( 'litespeed_purge_all' ) ) {
39 do_action( 'litespeed_purge_all' );
40 }
41
42 switch ( $args[0] ) {
43 case '1':
44 Settings::update_setting( 'maintenance_mode', 1 );
45 WP_CLI::success( 'Maintenance mode ENABLED' );
46 break;
47 case '0':
48 Settings::update_setting( 'maintenance_mode', 0 );
49 WP_CLI::success( 'Maintenance mode DISABLED' );
50 break;
51 default:
52 throw new \Exception( 'Invalid maintenance mode value' );
53 }
54 }
55
56 /**
57 * Command return maintenance mode status.
58 *
59 * ## EXAMPLES
60 *
61 * # Get maintenance mode status
62 * $ wp hostinger maintenance status
63 */
64 public function status(): bool {
65 $status = get_option( 'hostinger_maintenance_mode', 0 );
66
67 if ( $status ) {
68 WP_CLI::success( 'Maintenance mode ENABLED' );
69 } else {
70 WP_CLI::success( 'Maintenance mode DISABLED' );
71 }
72
73 return (bool) $status;
74 }
75 }
76