-
Notifications
You must be signed in to change notification settings - Fork 975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce ability to override wp-config.php path with env var WP_CONFIG_PATH #5119
Conversation
I feel like this might have unintended consequences... Can you open an issue to discuss the idea at depth before we proceed with a proposed solution? |
@danielbachhuber Sure thing. Created an issue here: #5120 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you include some functional tests for this change?
@danielbachhuber Not too familiar with Gherkins but let me know if what I came up with works. This does not seem to work locally on mac. I think I'll have to add something like: if ( false !== strpos( $str, '{WP_RUN_DIR}' ) ) {
$str = str_replace( '{WP_RUN_DIR}', preg_replace( '|^/private/var/|', '/var/', $this->variables[ 'RUN_DIR' ] ));
} to this function and use the new var instead of |
@jonathanbardo The general approach for the test is fine. I added some further observations to the change request above. |
Here's the Behat test I propose: Feature: wp-config
Scenario: Default WordPress install with WP_CONFIG_PATH specified in environment variable
Given a WP installation
And a wp-config-override.php file:
"""
<?php
define('DB_NAME', 'wp_cli_test');
define('DB_USER', 'wp_cli_test');
define('DB_PASSWORD', 'password1');
define('DB_HOST', '127.0.0.1');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
$table_prefix = 'wp_';
// Provide custom define in override only that we can test against
define('SOME_VARIABLE', 'some_value');
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
require_once(ABSPATH . 'wp-settings.php');
"""
When I try `wp eval "echo 'SOME_VARIABLE => ' . SOME_VARIABLE;"`
Then STDOUT should contain:
"""
SOME_VARIABLE => SOME_VARIABLE
"""
And STDERR should contain:
"""
Use of undefined constant SOME_VARIABLE
"""
When I run `WP_CONFIG_PATH=wp-config-override.php wp eval "echo 'SOME_VARIABLE => ' . SOME_VARIABLE;"`
Then STDERR should be empty
And STDOUT should contain:
"""
SOME_VARIABLE => some_value
""" |
@schlessera Here we go, thanks for the feedback! |
Functional test was added as requested
Hi all!
I would like to propose to add the ability to provide our own config override path based on an environment variable (WP_CONFIG_PATH). This would solve a lot of headaches for managed hosts that rely on wp-cli but can't trust the wp-config that the user can play with. (For example, when the WordPress site loads fine on the server but somehow the wp-config.php custom php code prevents wp-cli from loading correctly).
This can also provide a solution for people who want to use different configs for the WP-CLI without having to resort to conditionals inside of the config itself.
Note: I see there are no unit tests for this function already. I can introduce one if we feel like there is a need for it.
Fixes #5120