|
42 | 42 | setup_id();
|
43 | 43 | ensure_wordpress_ready();
|
44 | 44 |
|
45 |
| -$ensure_airplane_mode_plugin = static function () { |
46 |
| - $plugin_dir = slic_plugins_dir( 'airplane-mode' ); |
| 45 | +$ensure_airplane_mode_plugin_present = static function () { |
| 46 | + $mu_plugins_dir = slic_mu_plugins_dir(); |
| 47 | + $plugin_dir = $mu_plugins_dir . DIRECTORY_SEPARATOR . 'airplane-mode'; |
| 48 | + |
| 49 | + if ( |
| 50 | + ! is_dir( dirname( $mu_plugins_dir ) ) |
| 51 | + && ! mkdir( $concurrentDirectory = dirname( $mu_plugins_dir ), 0755, true ) |
| 52 | + && ! is_dir( $concurrentDirectory ) |
| 53 | + ) { |
| 54 | + echo magenta( "Failed to create mu-plugins directory {$mu_plugins_dir}." ); |
| 55 | + exit( 1 ); |
| 56 | + } |
| 57 | + |
47 | 58 | if ( ! is_dir( $plugin_dir ) ) {
|
48 | 59 | $cloned = process_realtime( 'git clone https://github.com/norcross/airplane-mode ' . $plugin_dir );
|
49 | 60 | if ( $cloned !== 0 ) {
|
50 | 61 | echo magenta( "Failed to clone the airplane-mode plugin." );
|
51 | 62 | exit( 1 );
|
52 | 63 | }
|
53 | 64 | }
|
| 65 | + |
| 66 | + if ( |
| 67 | + is_file( $mu_plugins_dir . DIRECTORY_SEPARATOR . 'airplane-mode.php' ) |
| 68 | + && ! unlink( $mu_plugins_dir . DIRECTORY_SEPARATOR . 'airplane-mode.php' ) |
| 69 | + ) { |
| 70 | + echo magenta( "Failed to remove the airplane-mode plugin." ); |
| 71 | + exit( 1 ); |
| 72 | + } |
| 73 | + |
| 74 | + $loader_code = <<< PHP |
| 75 | +<?php |
| 76 | +
|
| 77 | +add_filter( 'pre_site_option_airplane-mode', function () { |
| 78 | + return 'on'; |
| 79 | +} ); |
| 80 | +require_once __DIR__ . '/airplane-mode/airplane-mode.php'; |
| 81 | +PHP; |
| 82 | + |
| 83 | + if ( ! file_put_contents( $mu_plugins_dir . DIRECTORY_SEPARATOR . 'airplane-mode.php', $loader_code, LOCK_EX ) ) { |
| 84 | + echo magenta( "Failed to write the airplane-mode plugin." ); |
| 85 | + exit( 1 ); |
| 86 | + } |
54 | 87 | };
|
55 | 88 |
|
56 |
| -check_status_or( |
57 |
| - slic_process()( cli_command( [ 'plugin', 'is-installed', 'airplane-mode' ] ) ), |
58 |
| - $ensure_airplane_mode_plugin |
59 |
| -); |
| 89 | +$ensure_airplane_mode_plugin_removed = static function(){ |
| 90 | + $mu_plugins_dir = slic_mu_plugins_dir(); |
| 91 | + $plugin_dir = $mu_plugins_dir . DIRECTORY_SEPARATOR . 'airplane-mode'; |
| 92 | + |
| 93 | + if ( is_dir( $plugin_dir ) && ! rrmdir( $plugin_dir ) ) { |
| 94 | + echo magenta( "Failed to remove the airplane-mode plugin." ); |
| 95 | + exit( 1 ); |
| 96 | + } |
| 97 | + |
| 98 | + if ( |
| 99 | + is_file( $mu_plugins_dir . DIRECTORY_SEPARATOR . 'airplane-mode.php' ) |
| 100 | + && ! unlink( $mu_plugins_dir . DIRECTORY_SEPARATOR . 'airplane-mode.php' ) |
| 101 | + ) { |
| 102 | + echo magenta( "Failed to remove the airplane-mode plugin." ); |
| 103 | + exit( 1 ); |
| 104 | + } |
| 105 | +}; |
60 | 106 |
|
61 | 107 | if ( $activate ) {
|
62 |
| - echo "Activating the airplane-mode plugin..." . PHP_EOL; |
63 |
| - check_status_or_exit( slic_process()( cli_command( [ 'plugin', 'activate', 'airplane-mode' ] ) ) ); |
64 |
| - echo light_cyan( 'Airplane mode plugin activated: all external data calls are now disabled.' ); |
| 108 | + echo "Installing airplane-mode plugin in the must-use plugins directory..." . PHP_EOL; |
| 109 | + $ensure_airplane_mode_plugin_present(); |
| 110 | + echo light_cyan( 'Airplane mode plugin installed: all external data calls are now disabled.' ); |
65 | 111 | } else {
|
66 |
| - echo "Deactivating the airplane-mode plugin..." . PHP_EOL; |
67 |
| - check_status_or_exit( slic_process()( cli_command( [ 'plugin', 'deactivate', 'airplane-mode' ] ) ) ); |
68 |
| - echo light_cyan( 'Airplane mode plugin deactivated: external data calls are now enabled.' ); |
| 112 | + echo "Removing the airplane-mode plugin from the must-use plugins directory..." . PHP_EOL; |
| 113 | + $ensure_airplane_mode_plugin_removed(); |
| 114 | + echo light_cyan( 'Airplane mode plugin removed: external data calls are now enabled.' ); |
69 | 115 | }
|
0 commit comments