-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Add WP AI Client #10881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Add WP AI Client #10881
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| <exclude-pattern>/src/wp-includes/js/*</exclude-pattern> | ||
| <exclude-pattern>/src/wp-includes/PHPMailer/*</exclude-pattern> | ||
| <exclude-pattern>/src/wp-includes/Requests/*</exclude-pattern> | ||
| <exclude-pattern>/src/wp-includes/php-ai-client/*</exclude-pattern> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just wanted to confirm. Is this entire directory "external library" code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, correct.
| <directory suffix=".php">src/wp-includes/PHPMailer</directory> | ||
| <directory suffix=".php">src/wp-includes/Requests</directory> | ||
| <directory suffix=".php">src/wp-includes/php-ai-client</directory> | ||
| <directory suffix=".php">src/wp-includes/ai-client-utils</directory> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there no tests for the src/wp-includes/ai-client-utils directory? At a quick glance, it seems like tests/phpunit/tests/ai-client/wpAiClientAbilityFunctionResolver.php may test the class within the wp-includes/ai-client-utils/class-wp-ai-client-ability-function-resolver.php file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I agree. This should not be excluded, it needs test because this will be Core code.
Trac ticket: https://core.trac.wordpress.org/ticket/64591
Merge Proposal: https://make.wordpress.org/core/2026/02/03/proposal-for-merging-wp-ai-client-into-wordpress-7-0
Summary
Adds a provider-agnostic AI Client, enabling developers to interact with generative AI services through a single, fluent API — without needing to know which provider is configured.
This PR includes three layers:
PHP AI Client SDK (
php-ai-client): The upstream SDK fromWordPress/php-ai-client, bundled intowp-includes/php-ai-client/with all third-party dependencies (PSR interfaces, HTTPlug) scoped toWordPress\AiClientDependencies\*to avoid conflicts with plugins shipping their own versions.Import tooling (
tools/php-ai-client/): An installer script and PHP-Scoper configuration that fetches, scopes, and reorganizes the SDK for bundling. Runningbash tools/php-ai-client/installer.shreproduces the bundled output deterministically.WP AI Client (
ai-client-utils/,ai-client.php): The WordPress integration layer. This provides minimal PSR-7/PSR-17 implementations backed by string buffers andwp_parse_url(), an HTTP client adapter that routes requests throughwp_remote_request(), a discovery strategy so the SDK automatically finds these implementations, and an event dispatcher that bridges PSR-14 events to WordPress hooks.The public API is a single function:
WP_AI_Client_Prompt_Builderwraps the SDK's fluent builder with WordPress conventions — snake_case methods,WP_Errorreturns instead of exceptions, andusing_abilities()for connecting the Abilities API to AI function calling.The
wp_ai_client_prevent_promptfilter gives site owners and plugins centralized control over AI availability. When a prompt is prevented, generating methods returnWP_Errorwhileis_supported_*methods returnfalse— giving plugin developers a graceful way to hide AI features entirely when AI is not available.This gives plugin and theme developers a stable, provider-neutral way to add AI features without bundling their own HTTP clients or managing provider-specific SDKs.
Follow up PRs
There will be a couple more PRs. I broke up the WP AI Client, introducing only the main core files in this one. Following PRs will be:
Use of AI Tools
This is a compilation of work from the PHP AI Client and WP AI Client repositories, with some changes made in porting to core. Claude Code was used in both the original development of those packages as well as the porting over and creation of the tooling. All code was generated by Claude Code and reviewed by myself and @felixarntz.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.