wp-cli/eval-command
Run arbitrary PHP code or files from the command line with WP-CLI. wp eval executes a code string, while wp eval-file loads a PHP file with positional arguments. Both support --skip-wordpress to run without WordPress and --hook to run after a specific WordPress hook fires.
wp eval / wp eval-file let you ship operational capability (data backfills, content migrations, one-off reporting, smoke checks) without allocating engineering time to a UI or a bespoke plugin. That frees roadmap capacity for customer-facing work.init to reproduce the bug?" are all one-liners here. Each one you don't turn into a ticket is a measurable roadmap saving.wp eval gives support and on-call engineers read/write access to a bootstrapped WordPress runtime — WP_CONTENT_DIR, wp_get_current_user(), options, hooks — without deploying code. This shortens time-to-diagnosis and reduces "we need a hotfix release to print a variable" cycles.--hook=<hook> defers execution until a specific WordPress lifecycle event fires. That's the difference between "we can't reproduce it" and "we reproduced it deterministically," and it should inform how you staff and tool WordPress plugin/theme debugging.wp eval-file <file> [<arg>...] with $args, plus - for STDIN, turns ad-hoc ops into parameterized scripts you can commit, review, and run in CI. This supports a decision to treat ops runbooks as code rather than wiki pages.--skip-wordpress gives you a plain PHP execution context on the same binary, useful for quick environment assertions and pipeline glue without booting a full stack.artisan tinker / PsySH / custom Artisan commands remain the right answer. This package is for the WordPress half of a hybrid stack. Making that boundary explicit in your architecture docs prevents teams from reaching for wp eval to poke at Laravel services (and vice versa).Adopt / standardize on it when:
eval-file with positional args committed to the repo.--hook would give you deterministic reproduction.--skip-wordpress).Look elsewhere when:
artisan tinker, PsySH, custom Artisan commands. This package adds nothing.eval'd code has no test harness, no autoloading guarantees, and global-variable gotchas (code runs inside a method, so globals must be explicitly global'd).--hook mechanism is WordPress-specific; synchronizing with Laravel's event system requires custom adapters you'd own.Signal caveat worth noting: 10 GitHub stars and 0 listed dependents look weak, but that's a distribution artifact — the package is bundled with WP-CLI, so usage doesn't register as a Composer dependency. Don't let the vanity metric drive the decision; the relevant question is "do we run WP-CLI?"
To executives (30 seconds): This is a free, MIT-licensed command that's already included in WP-CLI — the standard command-line tool for WordPress. It lets our engineers run PHP against a live WordPress environment in one line, which means faster incident diagnosis, ops scripts we can commit and review instead of run by hand, and fewer throwaway plugins built just to flip a flag or fix some data. There's no license cost, no integration project, and no new vendor — the only decision is whether we standardize our WordPress ops on it and set guardrails.
To engineering: It's essentially artisan tinker for WordPress. wp eval '<code>' runs inline PHP; wp eval-file <file> [<arg>...] runs a file with arguments exposed as $args, and - reads from STDIN. --skip-wordpress executes without bootstrapping WordPress; --hook=<hook> defers execution to a WordPress lifecycle event, which is how we get deterministic repro for lifecycle bugs. Two things to internalize: executed code runs inside a method, so globals must be explicitly globalized, and this is arbitrary code execution with no sandbox — treat it with the same care as php -r on a production box.
The ask, concretely: (1) Adopt it as the default for WordPress-adjacent ops rather than approving new one-off plugins. (2) Write the guardrails down — staging first, production requires approval and a logged command, recurring scripts live in the repo as eval-file targets, not in a wiki. (3) Keep the boundary explicit in our docs: wp eval for the WordPress side of the stack, Artisan/tinker for the Laravel side. (4) Track success with three numbers: mean time to diagnose WordPress incidents, count of one-off plugins avoided, and count of ops procedures under version control instead of documentation.
How can I help you explore Laravel packages today?