-
Notifications
You must be signed in to change notification settings - Fork 980
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
WP-CLI can fail cryptically when parsing custom wp-config.php #1631
Comments
|
Does this if prevent this behaviour? |
|
I am on webfaction if that matters. And I use Q2A WP intergration, so i have the following added to my wp-config.php (start and end) |
|
Try moving add_filter () to a MU plugin. It can be used after WP core is loaded. |
|
@szepeviktor Awesome thanks, I somehow guessed this but did ask b4 thinking of mu-plugins. |
|
As a quick and simple fix then the following mod at the end of wp-config.php should always work I think? Change: To This way if using wp-cli's internal version of wp-settings.php we don't load the site's version, and the regex that wp-cli requires to work is preserved. If just running the site as normal it'll still load too. I don't see this as a permanent answer to the issue but it works for me. |
|
@EndemolUK that actually worked for me as well. Thank you! |
Only include definitions and variable declarations in the wp-config $lines_to_run. This should resolve problems seen with wp-cli#1631
|
Note: if you need to load WP afterwards, this can break, since WP needs to know the right ABSPATH to load itself, and plugins will also depend on that. I don't think that matters in some places wp-cli loads it, but potentially some it does. To help with that, you can use a hybrid solution: fork/exec off an instance just to load the config, have it output as JSON, then use that in your main process. The overhead of doing that is reasonably minimal (since you're only loading |
|
Ah... I think WP-CLI already uses the fake ABSPATH trick when it doesn't need to load the rest of WP.
Yeah, I guess you could detect (in a generic way) all the constants and globals that wp-config sets and send them via JSON. |
You can basically just use |
|
Related #2278 |
|
if you are using Pantheon and are having this issue (i.e. getting a seemingly random fatal error - à la I simply commented out |
|
If it's any use diagnosing this bug, the described behavior does not occur when run with the and then I pressed Running without System information: |
|
@benlk I think in time you did your before and after, VVV ran |
|
That's not quite what happened, but you're right that that install was using the (https://github.com/INN/deploy-tools has a command |
|
At this point, I think we're going to stick with what we have. The approach of spawning a separate process to read |
|
For those that got here because of the |
|
It also fails if you have |
|
Any chance that add_filter could be defined as a no-op fuction in this context, so that WP CLI can be used without requiring modifications? (EDIT: apparently, no. I'd forgotten that you can't redefine functions in PHP.) |
|
I hit this because the last two lines in my wp-config weren't the expected: |
|
@decadence your comment led me to my fix. I had The cryptic error message in my case was: Which, of course, implies some PHP file has a syntax error. |
|
@nickbreen glad you solved it |
Starting a new issue as the definitive place to point users who've run into this.
WP-CLI uses a custom version of WordPress's
wp-settings.phpfile. Here's a narrative version of the backstory. Before WP-CLI can loadwp-settings-cli.php, it needs to know all of the constants defined inwp-config.php(database connection details and so on).In a typical WordPress install,
wp-config.phphas the following at the end of the file:This is the code that loads WordPress. Because WP-CLI doesn't want WordPress to load yet when it's pulling the constants out of
wp-config.php, it uses regex to strip therequire_once(ABSPATH . 'wp-settings.php');statement.But, if the regex fails for whatever reason, WordPress gets loaded via the normal
wp-settings.phpstatement whenwp-config.phpis evaluated, and WP-CLI can fail in a variety of cryptic ways.The text was updated successfully, but these errors were encountered: