Skip to content

Add wp ai is-supported #12

@swissspidy

Description

@swissspidy

In WordPress 7.0 there is this new function for hosts and plugins to completely disable any AI features:

/**
 * Returns whether AI features are supported in the current environment.
 *
 * @since 7.0.0
 *
 * @return bool Whether AI features are supported.
 */
function wp_supports_ai(): bool {
	$is_enabled = defined( 'WP_AI_SUPPORT' ) ? WP_AI_SUPPORT : true;

	/**
	 * Filters whether the current request should use AI.
	 *
	 * This allows plugins and 3rd-party code to disable AI features on a per-request basis, or to even override explicit
	 * preferences defined by the site owner.
	 *
	 * @since 7.0.0
	 *
	 * @param bool $is_enabled Whether the current request should use AI. Default to WP_AI_SUPPORT constant, or true if
	 *                         the constant is not defined.
	 */
	return (bool) apply_filters( 'wp_supports_ai', $is_enabled );
}

Default connectors will only be registered if that function returns true.

It also has an effect on wp ai generate, as the prompt builder will return a WP_Error with code prompt_prevented and message AI features are not supported in this environment..

We should add some coverage for that in the existing tests.

wp ai is-supported is a new command that simply checks this function and returns an error code (0 or 1).

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions