[wp-trac] [WordPress Trac] #65043: Consider adding wp_doing_cli() to wrap WP_CLI constant checks
WordPress Trac
noreply at wordpress.org
Wed Apr 8 19:18:31 UTC 2026
#65043: Consider adding wp_doing_cli() to wrap WP_CLI constant checks
-----------------------------+-----------------------------
Reporter: johnjamesjacoby | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Bootstrap/Load | Version:
Severity: normal | Keywords: 2nd-opinion
Focuses: |
-----------------------------+-----------------------------
See #42061.
I think WordPress core should come with a `wp_doing_cli()` function to
provide a centrally supported, familiar, and filterable way for plugins
and tools to check whether or not the `WP_CLI` constant is set.
While the WP-CLI project is an external library, it is obviously part of
the WordPress Foundation, so it is the canonical command line interface
for WordPress itself.
Mostly, honestly, I get annoyed seeing `defined( 'WP_CLI' ) && WP_CLI`
everywhere. 😇
{{{
/**
* Determines whether the current request is a WordPress CLI request.
*
* @since 7.1.0
*
* @return bool True if it's a WordPress CLI request, false otherwise.
*/
function wp_doing_cli() {
/**
* Filters whether the current request is a WordPress CLI request.
*
* @since 7.1.0
*
* @param bool $wp_doing_cli Whether the current request is a
WordPress CLI request.
*/
return apply_filters( 'wp_doing_cli', defined( 'WP_CLI' ) &&
WP_CLI );
}
}}}
(I set the Component to Bootstrap/Load because that's where this function
would likely end up.)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/65043>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list