Skip to content

Commit c806e88

Browse files
schlesseraclaude
andcommitted
Provide plugin and theme directories as built-in variables
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b533a56 commit c806e88

3 files changed

Lines changed: 63 additions & 1 deletion

File tree

‎features/behat-steps.feature‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,23 @@ Feature: Test that WP-CLI Behat steps work as expected
468468
When I launch in the background `wp eval 'sleep(2); echo "done";'`
469469
# Background process should not block, continuing immediately
470470

471+
@require-wp
472+
Scenario: Use the plugin and theme directories of a WP installation
473+
Given a WP installation
474+
When I run `wp eval 'echo WP_PLUGIN_DIR;'`
475+
Then STDOUT should be:
476+
"""
477+
{PLUGIN_DIR}
478+
"""
479+
480+
When I run `wp eval 'echo get_theme_root();'`
481+
Then STDOUT should be:
482+
"""
483+
{THEME_DIR}
484+
"""
485+
And the {PLUGIN_DIR}/akismet directory should exist
486+
And the {THEME_DIR} directory should exist
487+
471488
@require-wp
472489
Scenario: Test custom wp-content directory
473490
Given a WP installation
@@ -480,6 +497,18 @@ Feature: Test that WP-CLI Behat steps work as expected
480497
WP_CONTENT_DIR
481498
"""
482499

500+
When I run `wp eval 'echo WP_PLUGIN_DIR;'`
501+
Then STDOUT should be:
502+
"""
503+
{PLUGIN_DIR}
504+
"""
505+
506+
When I run `wp eval 'echo get_theme_root();'`
507+
Then STDOUT should be:
508+
"""
509+
{THEME_DIR}
510+
"""
511+
483512
@require-wp
484513
Scenario: Test WP multisite installation
485514
Given a WP multisite installation
@@ -525,6 +554,18 @@ Feature: Test that WP-CLI Behat steps work as expected
525554
When I run `wp core version`
526555
Then STDOUT should not be empty
527556

557+
When I run `wp eval 'echo WP_PLUGIN_DIR;'`
558+
Then STDOUT should be:
559+
"""
560+
{PLUGIN_DIR}
561+
"""
562+
563+
When I run `wp eval 'echo get_theme_root();'`
564+
Then STDOUT should be:
565+
"""
566+
{THEME_DIR}
567+
"""
568+
528569
# Skipped on Windows because of curl getaddrinfo() errors.
529570
@require-wp @require-composer @skip-windows
530571
Scenario: Test WP installation with Composer and custom vendor directory

‎src/Context/FeatureContext.php‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class FeatureContext implements Context {
165165

166166
/**
167167
* Array of variables available as {VARIABLE_NAME}. Some are always set: CORE_CONFIG_SETTINGS, DB_USER, DB_PASSWORD, DB_HOST, SRC_DIR, CACHE_DIR, WP_VERSION-version-latest.
168-
* Some are step-dependent: RUN_DIR, SUITE_CACHE_DIR, COMPOSER_LOCAL_REPOSITORY, PHAR_PATH. One is set on use: INVOKE_WP_CLI_WITH_PHP_ARGS-args.
168+
* Some are step-dependent: RUN_DIR, SUITE_CACHE_DIR, COMPOSER_LOCAL_REPOSITORY, PHAR_PATH, and PLUGIN_DIR and THEME_DIR for the WordPress files in RUN_DIR. One is set on use: INVOKE_WP_CLI_WITH_PHP_ARGS-args.
169169
* Scenarios can define their own variables using "Given save" steps. Variables are reset for each scenario.
170170
*
171171
* @var array<string, string>
@@ -1849,6 +1849,10 @@ public function download_wp( $subdir = '', $version = '' ): void {
18491849

18501850
self::copy_dir( self::$cache_dir, $dest_dir );
18511851

1852+
if ( ! $subdir ) {
1853+
$this->set_content_dir_variables( $dest_dir . '/wp-content' );
1854+
}
1855+
18521856
if ( ! is_dir( $dest_dir . '/wp-content/mu-plugins' ) ) {
18531857
mkdir( $dest_dir . '/wp-content/mu-plugins', 0777, true /*recursive*/ );
18541858
}
@@ -2048,6 +2052,21 @@ public function install_wp_with_composer( $vendor_directory = 'vendor' ): void {
20482052
}
20492053

20502054
$this->proc( 'wp core install', $install_args )->run_check();
2055+
2056+
$this->set_content_dir_variables( $this->variables['RUN_DIR'] . '/WordPress/wp-content' );
2057+
}
2058+
2059+
/**
2060+
* Expose the plugins and themes directories as {PLUGIN_DIR} and {THEME_DIR}.
2061+
*
2062+
* Matches the output of `wp plugin path` and `wp theme path`.
2063+
*
2064+
* @param string $content_dir
2065+
* @param string $plugin_dir Defaults to the plugins directory inside $content_dir.
2066+
*/
2067+
public function set_content_dir_variables( $content_dir, $plugin_dir = '' ): void {
2068+
$this->variables['PLUGIN_DIR'] = $plugin_dir ?: $content_dir . '/plugins';
2069+
$this->variables['THEME_DIR'] = $content_dir . '/themes';
20512070
}
20522071

20532072
public function composer_add_wp_cli_local_repository(): void {

‎src/Context/GivenStepDefinitions.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,8 @@ public function given_a_custom_wp_directory(): void {
470470

471471
file_put_contents( $wp_config_path, $wp_config_code );
472472

473+
$this->set_content_dir_variables( $this->variables['RUN_DIR'] . '/my-content', $this->variables['RUN_DIR'] . '/my-plugins' );
474+
473475
if ( 'sqlite' === self::$db_type ) {
474476
$db_dropin = $this->variables['RUN_DIR'] . '/my-content/db.php';
475477

0 commit comments

Comments
 (0)