Skip to content

Commit 7ee7255

Browse files
authored
Update index.md
Elaborating on failures from calls to WordPress built-in functions
1 parent e83a0da commit 7ee7255

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

docs/common-issues/index.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,22 @@ require_once(ABSPATH . 'wp-settings.php');
3535

3636
remains in the `wp-config.php` file, so if you've modified or moved it, put it back there. It gets matched by a regex when WP-CLI runs.
3737

38-
See also: [#1631](https://github.com/wp-cli/wp-cli/issues/1631)
38+
### PHP Fatal error: Call to undefined function \<WordPress function\>
39+
40+
WP-CLI uses a [custom version](https://github.com/wp-cli/wp-cli/blob/master/php/wp-settings-cli.php) of WordPress's `wp-settings.php` file. Before WP-CLI can load `wp-settings-cli.php`, it needs to know all of the constants defined in `wp-config.php` (database connection details and so on). Because WP-CLI doesn't want WordPress to load yet when it's [pulling the constants](https://github.com/wp-cli/wp-cli/blob/master/php/wp-cli.php#L22) out of `wp-config.php`, [it uses regex](https://github.com/wp-cli/wp-cli/blob/master/php/WP_CLI/Runner.php#L324) to strip the `require_once(ABSPATH . 'wp-settings.php');` statement.
41+
42+
If you've modified your `wp-config.php` in a way that calls WordPress functions, PHP will fail out with a fatal error, as your `wp-config.php` is calling a WordPress function before WordPress has been loaded to define it.
43+
44+
Example:
45+
46+
```Shell
47+
$ wp core check-update
48+
PHP Fatal error: Call to undefined function add_filter() in phar:///usr/local/bin/wp/php/WP_CLI/Runner.php(952) : eval()'d code on line N
49+
```
50+
51+
As a workaround, you can move your modifications to a [WordPress mu-plugin](https://codex.wordpress.org/Must_Use_Plugins), which will retain the functionality of your modifications while allowing wp-cli to parse your wp-config.php without throwing a PHP error.
52+
53+
See: [#1631](https://github.com/wp-cli/wp-cli/issues/1631)
3954
4055
### PHP Fatal error: Call to undefined function cli\posix_isatty()
4156

0 commit comments

Comments
 (0)