PluginProbe
Hostinger Tools / 1.9.1
Hostinger Tools v1.9.1
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 / class-hostinger-maintenance-command.php

class-hostinger-maintenance-command.php in Hostinger Tools 1.9.1, at includes/cli/class-hostinger-maintenance-command.php

67 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined( 'ABSPATH' ) || exit;
3
4 class Hostinger_Maintenance_Command {
5 public static function define_command(): void {
6 WP_CLI::add_command( 'hostinger maintenance', Hostinger_Maintenance_Command::class );
7 }
8 /**
9 * Command allows enable/disable maintenance mode.
10 *
11 * ## EXAMPLES
12 *
13 * # Enable maintenance mode
14 * $ wp hostinger maintenance mode 1
15 *
16 * # Disable maintenance mode
17 * $ wp hostinger maintenance mode 0
18 *
19 * @param array $args WP-CLI positional arguments.
20 *
21 * @throws Exception If pass bad argument.
22 */
23 public function mode( array $args ): void {
24 if ( empty( $args ) ) {
25 WP_CLI::error( 'Arguments cannot be empty. Use 0 or 1' );
26 }
27
28 if ( has_action( 'litespeed_purge_all' ) ) {
29 do_action( 'litespeed_purge_all' );
30 }
31
32 switch ( $args[0] ) {
33 case '1':
34 Hostinger_Settings::update_setting( 'maintenance_mode', 1 );
35 WP_CLI::success( 'Maintenance mode ENABLED' );
36 break;
37 case '0':
38 Hostinger_Settings::update_setting( 'maintenance_mode', 0 );
39 WP_CLI::success( 'Maintenance mode DISABLED' );
40 break;
41 default:
42 throw new Exception( 'Invalid maintenance mode value' );
43 }
44 }
45
46 /**
47 * Command return maintenance mode status.
48 *
49 * ## EXAMPLES
50 *
51 * # Get maintenance mode status
52 * $ wp hostinger maintenance status
53 *
54 */
55 public function status(): bool {
56 $status = get_option( 'hostinger_maintenance_mode', 0 );
57
58 if( $status ) {
59 WP_CLI::success( 'Maintenance mode ENABLED' );
60 } else {
61 WP_CLI::success( 'Maintenance mode DISABLED' );
62 }
63
64 return (bool) $status;
65 }
66 }
67