A simple demonstration plugin showcasing the integration of the PHP AI Client library with WordPress. This plugin provides a minimal example of how to use AI capabilities in WordPress using pure PHP.
PHP AI Client Demo is a lightweight example plugin that demonstrates the basics of integrating AI text generation into WordPress using the PHP AI Client library. The plugin works with any supported AI provider including Anthropic Claude, OpenAI, and local AI models.
- Simple AI Integration: Minimal setup to get AI text generation working in WordPress
- Multi-Provider Support: Works with any AI provider supported by the PHP AI Client library
- Custom Request Options: Demonstrates configuring timeouts for local and remote AI models
- Reusable Function: Easy-to-use helper function for generating text
- WP-CLI Integration: Generate text from the command line
- WordPress 6.0 or higher
- PHP 8.0 or higher
- Composer
- API key for your chosen AI provider (or access to a local AI model)
- Clone or download this plugin to your WordPress plugins directory:
cd wp-content/plugins
git clone git clone git@github.com:jonathanbossenger/php-ai-client-demo- Install PHP dependencies:
cd php-ai-client-demo
composer install- Configure your AI provider credentials in your
wp-config.phpfile. The PHP AI Client library automatically detects provider-specific constants:
For Anthropic Claude:
define( 'ANTHROPIC_API_KEY', 'your-api-key-here' );For OpenAI:
define( 'OPENAI_API_KEY', 'your-api-key-here' );For Google Gemini:
define( 'GOOGLE_API_KEY', 'your-api-key-here' );- Activate the plugin through the WordPress admin interface or via WP-CLI:
wp plugin activate php-ai-client-demoUse the provided helper function to generate text from a prompt:
$prompt = 'Write a short introduction about WordPress';
$generated_text = php_ai_sdk_demo_generate_text( $prompt );
echo $generated_text;You can also use the WP-CLI command to generate text:
wp php-ai-sdk-demo-text "Write a short introduction about WordPress"This will output generated text based on the prompt.
GPL-2.0-or-later
Jonathan Bossenger