| 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 |
|