npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

wp-cctinker

v1.0.18

Published

Execute PHP code within WordPress context from the command line

Readme

wp-cctinker

Execute PHP code within WordPress context from the command line.

Installation

npm install -g wp-cctinker

Usage

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

Interactive Mode

Launch an interactive PHP shell with WordPress loaded:

cctinker -i
# or
cctinker --interactive

Example 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-chat

Setup 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 --help

Features

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