Skip to content
This repository was archived by the owner on May 30, 2025. It is now read-only.

Commit 6c15872

Browse files
committed
Inline Step-related scripts into their class definitions. Sourcing them via file_get_contents() is problematic when the runner is bundled as a phar file
1 parent bf755ad commit 6c15872

File tree

12 files changed

+844
-818
lines changed

12 files changed

+844
-818
lines changed

components/Blueprints/Steps/ActivatePluginStep.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,37 @@
99
* Represents the 'activatePlugin' step.
1010
*/
1111
class ActivatePluginStep implements StepInterface {
12+
// Inline PHP script to avoid reading a static script.php file via
13+
// file_get_contents() inside the built blueprints.phar file.
14+
const ACTIVATE_PLUGIN_SCRIPT = <<<'PHP'
15+
<?php
16+
17+
define( 'WP_ADMIN', true );
18+
require_once getenv( 'DOCROOT' ) . '/wp-load.php';
19+
require_once getenv( 'DOCROOT' ) . '/wp-admin/includes/plugin.php';
20+
21+
// Set current user to admin
22+
set_current_user( get_users( array( 'role' => 'Administrator' ) )[0] );
23+
24+
$pluginPath = getenv( 'PLUGIN_PATH' );
25+
if ( ! is_dir( $pluginPath ) ) {
26+
activate_plugin( $pluginPath );
27+
die();
28+
}
29+
30+
foreach ( ( glob( $pluginPath . '/*.php' ) ?: array() ) as $file ) {
31+
$info = get_plugin_data( $file, false, false );
32+
if ( ! empty( $info['Name'] ) ) {
33+
activate_plugin( $file );
34+
die();
35+
}
36+
}
37+
38+
// If we got here, the plugin was not found.
39+
exit( 1 );
40+
PHP
41+
;
42+
1243
/**
1344
* Path to the plugin directory or entry file.
1445
* Examples: '/wordpress/wp-content/plugins/plugin-name', 'plugin-name/plugin-name.php'
@@ -29,7 +60,7 @@ public function __construct( string $pluginPath ) {
2960
public function run( Runtime $runtime, Tracker $tracker ) {
3061
$tracker->setCaption( 'Activating plugin ' . ( $this->pluginPath ?? '' ) );
3162
$runtime->evalPhpCodeInSubProcess(
32-
file_get_contents( __DIR__ . '/scripts/ActivatePlugin/wp_activate_plugin.php' ),
63+
self::ACTIVATE_PLUGIN_SCRIPT,
3364
[
3465
'PLUGIN_PATH' => $this->pluginPath,
3566
]

components/Blueprints/Steps/ActivateThemeStep.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@
99
* Represents the 'activateTheme' step.
1010
*/
1111
class ActivateThemeStep implements StepInterface {
12+
13+
// Inline PHP script to avoid reading a static script.php file via
14+
// file_get_contents() inside the built blueprints.phar file.
15+
const ACTIVATE_THEME_SCRIPT = <<<'PHP'
16+
<?php
17+
18+
define( 'WP_ADMIN', true );
19+
require_once getenv( 'DOCROOT' ) . '/wp-load.php';
20+
21+
// Set current user to admin
22+
set_current_user( get_users( array( 'role' => 'Administrator' ) )[0] );
23+
switch_theme( getenv( 'THEME_FOLDER_NAME' ) );
24+
PHP
25+
;
26+
1227
/**
1328
* The name of the theme folder inside wp-content/themes/.
1429
* @var string
@@ -28,7 +43,7 @@ public function __construct( string $themeFolderName ) {
2843
public function run( Runtime $runtime, Tracker $tracker ) {
2944
$tracker->setCaption( 'Activating theme ' . $this->themeFolderName );
3045
$runtime->evalPhpCodeInSubProcess(
31-
file_get_contents( __DIR__ . '/scripts/ActivateTheme/wp_activate_theme.php' ),
46+
self::ACTIVATE_THEME_SCRIPT,
3247
[
3348
'THEME_FOLDER_NAME' => $this->themeFolderName,
3449
]

0 commit comments

Comments
 (0)