Skip to content

Docs say "before_wp_load" but everything is loaded already? #78

@kkmuffme

Description

@kkmuffme

Bug Report

Describe the current, buggy behavior

https://developer.wordpress.org/cli/commands/eval-file/

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)

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 after before_wp_load however wp-config.php has long been loaded already when the "eval-file" is run

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?

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions