Skip to content

Commit 308dfb6

Browse files
authored
Merge pull request #186 from stellarwp/1.6.1
1.6.1
2 parents 91869f7 + 098bea4 commit 308dfb6

File tree

5 files changed

+77
-14
lines changed

5 files changed

+77
-14
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
# [1.6.1] - 2024-04-19
8+
* Change - the `airplane-mode` command now installs the plugin in the must-use plugins directory instead of the plugins directory.
9+
* Fixed - `.bat` file now uses the correct path to the `slic` executable on Windows.
10+
711
# [1.6.0] - 2024-04-10
812
* Added - The `slic update-dump` command to update a dump file for the current project, with an optional WordPress version update, e.g. `slic update-dump tests/_data/dump.sql latest`.
913

slic.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ if "%PHP_PEAR_PHP_BIN%" neq "" (
44
set PHPBIN=%PHP_PEAR_PHP_BIN%
55
) else set PHPBIN=php
66

7-
"%PHPBIN%" "slic" %*
7+
"%PHPBIN%" "%~dp0\slic.php" %*

slic.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
] );
3535

3636
$cli_name = 'slic';
37-
const CLI_VERSION = '1.6.0';
37+
const CLI_VERSION = '1.6.1';
3838

3939
// If the run-time option `-q`, for "quiet", is specified, then do not print the header.
4040
if ( in_array( '-q', $argv, true ) || ( in_array( 'exec', $argv, true ) && ! in_array( 'help', $argv, true ) ) ) {

src/commands/airplane-mode.php

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,74 @@
4242
setup_id();
4343
ensure_wordpress_ready();
4444

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+
4758
if ( ! is_dir( $plugin_dir ) ) {
4859
$cloned = process_realtime( 'git clone https://github.com/norcross/airplane-mode ' . $plugin_dir );
4960
if ( $cloned !== 0 ) {
5061
echo magenta( "Failed to clone the airplane-mode plugin." );
5162
exit( 1 );
5263
}
5364
}
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+
}
5487
};
5588

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+
};
60106

61107
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.' );
65111
} 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.' );
69115
}

src/slic.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,17 @@ function slic_themes_dir( $path = '' ) {
459459
return slic_content_type_dir( 'themes', $path );
460460
}
461461

462+
/**
463+
* Returns the absolute path to the current mu-plugins directory slic is using.
464+
*
465+
* @param string $path An optional path to append to the current slic mu-plugins directory.
466+
*
467+
* @return string The absolute path to the current mu-plugins directory slic is using.
468+
*/
469+
function slic_mu_plugins_dir( $path = '' ) {
470+
return slic_content_type_dir( 'mu-plugins', $path );
471+
}
472+
462473
/**
463474
* Returns the absolute path to the current content directory slic is using.
464475
*
@@ -475,6 +486,8 @@ function slic_content_type_dir( $content_type = 'plugins', $path = '' ) {
475486
$default_path = '/_plugins';
476487
} elseif ( 'themes' === $content_type ) {
477488
$default_path = '/_wordpress/wp-content/themes';
489+
} elseif ( 'mu-plugins' === $content_type ) {
490+
$default_path = '/_wordpress/wp-content/mu-plugins';
478491
}
479492

480493
if ( empty( $content_type_dir ) ) {

0 commit comments

Comments
 (0)