Make WordPress Core

Opened 43 hours ago

#65043 new feature request

Consider adding wp_doing_cli() to wrap WP_CLI constant checks

Reported by: johnjamesjacoby's profile johnjamesjacoby Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Bootstrap/Load Keywords: 2nd-opinion
Focuses: Cc:

Description

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.)

Change History (0)

Note: See TracTickets for help on using tickets.