You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This command runs on the before_wp_load hook, just before the WP load process begins
In my layman understanding I'd assumed that this means that hooks like "init", "plugins_loaded",... haven't run yet when the code in the "eval-file" is executed.
Turns out this is wrong. All plugins and the theme have been loaded already, "plugins_loaded" hook is done,...
Basically everything except any CLI things hooked to after_wp_load are done (to also have that available, one would have to pipe to wp shell)
Is this expected or a bug?
If this is expected - would it be possible to change the description to make clear what exactly is meant with "just before the WP load process begins"?
Describe how other contributors can replicate this bug
wp eval-file /foo.php --use-include
where foo.php contains:
<?php
var_dump( did_action( 'plugins_loaded' ) );
// WooCommerce is installed in the environment and active
var_dump( function_exists( 'WC' ) );
Describe what you would expect as the correct outcome
The current behavior is ok and changing it would probably break tons of people's scripts/code. A clarification in the docs is needed though?
While the eval-file command is indeed hooked to before_wp_load, it manually loads WordPress before your own file, unless --skip-wordpress is provided. See:
Bug Report
Describe the current, buggy behavior
https://developer.wordpress.org/cli/commands/eval-file/
In my layman understanding I'd assumed that this means that hooks like "init", "plugins_loaded",... haven't run yet when the code in the "eval-file" is executed.
Turns out this is wrong. All plugins and the theme have been loaded already, "plugins_loaded" hook is done,...
Basically everything except any CLI things hooked to
after_wp_load
are done (to also have that available, one would have to pipe towp shell
)This is especially confusing since https://make.wordpress.org/cli/handbook/references/internal-api/wp-cli-add-hook/#notes shows e.g.
before_wp_config_load
afterbefore_wp_load
however wp-config.php has long been loaded already when the "eval-file" is runIs this expected or a bug?
If this is expected - would it be possible to change the description to make clear what exactly is meant with "just before the WP load process begins"?
Describe how other contributors can replicate this bug
wp eval-file /foo.php --use-include
where foo.php contains:
Describe what you would expect as the correct outcome
The current behavior is ok and changing it would probably break tons of people's scripts/code. A clarification in the docs is needed though?
I also wanted to ask:
https://make.wordpress.org/cli/handbook/references/config/
--require=
When using that, I assume that code runs actually on
before_wp_load
- so no WP code is loaded at all, when that file is executed?The text was updated successfully, but these errors were encountered: