wp-cctinker
v1.0.18
Published
Execute PHP code within WordPress context from the command line
Maintainers
Readme
wp-cctinker
Execute PHP code within WordPress context from the command line.
Installation
npm install -g wp-cctinkerUsage
Execute Inline PHP Code
# Simple examples
cctinker "echo get_option('siteurl');"
cctinker "echo 'WordPress version: ' . get_bloginfo('version');"
# More complex examples
cctinker "print_r(get_users(['number' => 5]));"
cctinker "\$user = wp_get_current_user(); echo 'Current user: ' . \$user->display_name;"Execute PHP Files
cctinker -f script.php
cctinker --file /path/to/your/script.php🆕 Multiline Code Input
Execute multiline PHP code without escaping using heredoc, pipes, or file redirect:
# Heredoc (clean multiline syntax)
cctinker << 'PHP'
$users = get_users(['number' => 5]);
foreach($users as $user) {
echo $user->user_login . ' - ' . $user->user_email . PHP_EOL;
}
PHP
# Pipe input
echo '$posts = get_posts(); echo count($posts) . " posts found";' | cctinker
# File redirect
cctinker < script.phpInteractive Mode
Launch an interactive PHP shell with WordPress loaded:
cctinker -i
# or
cctinker --interactiveExample interactive session:
wp> $post = get_post(1);
wp> echo $post->post_title;
Hello world!
wp> exit🆕 AI-Powered Natural Language Interface
Generate WordPress/WooCommerce code using plain English:
# Single command mode
cctinker --ai "get the latest five woocommerce order ids"
cctinker --ai "show me all users who registered last week"
# Interactive AI chat mode
cctinker --ai-chatSetup required: Set your Claude API key
export WP_CCTINKER_ANTHROPIC_API_KEY='your-api-key-here'See CLAUDE.md for detailed setup and examples.
Get Help
cctinker -h
cctinker --helpFeatures
- WordPress Context: All WordPress functions, hooks, and data are available
- Auto-detection: Automatically finds WordPress installation from current directory
- Error Handling: Clear error messages with file and line information
- Colorized Output: Easy to read output with color coding
- Interactive Shell: Full PHP REPL with WordPress loaded
- File Execution: Run PHP scripts in WordPress context
- Return Value Display: Shows the return value of expressions
- 🆕 AI Code Generation: Generate WordPress/WooCommerce code from natural language using Claude AI
- 🆕 Smart Context Awareness: Automatically detects WooCommerce, plugins, and WordPress environment
- 🆕 Safety Validation: Code validation and security checks before execution
- 🆕 Multiline Input Support: Heredoc, pipe, and file redirect support for clean multiline code
Requirements
- Node.js >= 14.0.0
- PHP >= 7.0
- WordPress installation
How It Works
The tool automatically searches for WordPress by looking for wp-load.php in the current directory and parent directories (up to 10 levels). Once found, it loads WordPress and executes your PHP code with full access to WordPress functions and data.
Examples
Working with Posts
# Get recent posts
cctinker "\$posts = get_posts(['numberposts' => 5]); foreach(\$posts as \$p) echo \$p->post_title . PHP_EOL;"
# Create a new post
cctinker "wp_insert_post(['post_title' => 'Test Post', 'post_content' => 'Content', 'post_status' => 'draft']);"Working with Users
# List users
cctinker "\$users = get_users(); foreach(\$users as \$u) echo \$u->user_login . ' - ' . \$u->user_email . PHP_EOL;"
# Get user meta
cctinker "print_r(get_user_meta(1));"Working with Options
# Get option
cctinker "echo get_option('blogname');"
# Update option
cctinker "update_option('my_custom_option', 'value');"Working with WooCommerce
# Get products
cctinker "\$products = wc_get_products(['limit' => 5]); foreach(\$products as \$p) echo \$p->get_name() . PHP_EOL;"
# Get orders
cctinker "\$orders = wc_get_orders(['limit' => 5]); foreach(\$orders as \$o) echo 'Order #' . \$o->get_id() . ' - ' . \$o->get_total() . PHP_EOL;"Troubleshooting
WordPress Not Found
If you get an error about WordPress not being found, make sure you're running the command from within a WordPress installation directory or one of its subdirectories.
PHP Not Found
Make sure PHP is installed and available in your system PATH.
Translation Notices
If you see notices about translations being loaded too early, this is normal and doesn't affect functionality. These come from plugins that load translations before the init action.
License
MIT
Contributing
Issues and pull requests are welcome at GitHub.
