Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions features/config.feature
Original file line number Diff line number Diff line change
Expand Up @@ -574,3 +574,27 @@ Feature: Have a config file
"""
Warning: UTF-8 byte-order mark (BOM) detected in wp-config.php file, stripping it for parsing.
"""

Scenario: Customize config-spec with WP_CLI_CONFIG_SPEC_FILTER_CALLBACK
Given a WP installation
And a wp-cli-early-require.php file:
"""
<?php
function wp_cli_remove_user_arg( $spec ) {
unset( $spec['user'] );
return $spec;
}
define( 'WP_CLI_CONFIG_SPEC_FILTER_CALLBACK', 'wp_cli_remove_user_arg' );
"""

When I run `WP_CLI_EARLY_REQUIRE=wp-cli-early-require.php wp help`
Then STDOUT should not contain:
"""
--user=<id|login|email>
"""

When I run `wp help`
Then STDOUT should contain:
"""
--user=<id|login|email>
"""
18 changes: 17 additions & 1 deletion php/WP_CLI/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Configurator {
* @param string $path Path to config spec file.
*/
public function __construct( $path ) {
$this->spec = include $path;
$this->load_config_spec( $path );

$defaults = [
'runtime' => false,
Expand All @@ -80,6 +80,22 @@ public function __construct( $path ) {
}
}

/**
* Loads the config spec file.
*
* @param string $path Path to the config spec file.
*/
private function load_config_spec( $path ) {
$config_spec = include $path;
// A way for platforms to modify $config_spec.
// Use with caution!
$config_spec_filter_callback = defined( 'WP_CLI_CONFIG_SPEC_FILTER_CALLBACK' ) ? constant( 'WP_CLI_CONFIG_SPEC_FILTER_CALLBACK' ) : false;
if ( $config_spec_filter_callback && is_callable( $config_spec_filter_callback ) ) {
$config_spec = $config_spec_filter_callback( $config_spec );
}
$this->spec = $config_spec;
}

/**
* Get declared configuration values as an array.
*
Expand Down
5 changes: 5 additions & 0 deletions php/wp-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';

require_once WP_CLI_ROOT . '/php/bootstrap.php';

if ( getenv( 'WP_CLI_EARLY_REQUIRE' ) ) {
require_once getenv( 'WP_CLI_EARLY_REQUIRE' );
}

WP_CLI\bootstrap();