Opens an interactive PHP console for running and testing PHP code.

Overview

wp-cli/shell-command

Opens an interactive PHP console for running and testing PHP code.

Testing

Quick links: Using | Installing | Contributing | Support

Using

wp shell [--basic]

wp shell allows you to evaluate PHP statements and expressions interactively, from within a WordPress environment. Type a bit of code, hit enter, and see the code execute right before you. Because WordPress is loaded, you have access to all the functions, classes and globals that you can use within a WordPress plugin, for example.

OPTIONS

[--basic]
	Force the use of WP-CLI's built-in PHP REPL, even if the Boris or
	PsySH PHP REPLs are available.

EXAMPLES

# Call get_bloginfo() to get the name of the site.
$ wp shell
wp> get_bloginfo( 'name' );
=> string(6) "WP-CLI"

Installing

This package is included with WP-CLI itself, no additional installation necessary.

To install the latest version of this package over what's included in WP-CLI, run:

wp package install [email protected]:wp-cli/shell-command.git

Contributing

We appreciate you taking the initiative to contribute to this project.

Contributing isn’t limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.

For a more thorough introduction, check out WP-CLI's guide to contributing. This package follows those policy and guidelines.

Reporting a bug

Think you’ve found a bug? We’d love for you to help us get it fixed.

Before you create a new issue, you should search existing issues to see if there’s an existing resolution to it, or if it’s already been fixed in a newer version.

Once you’ve done a bit of searching and discovered there isn’t an open or fixed issue for your bug, please create a new issue. Include as much detail as you can, and clear steps to reproduce if possible. For more guidance, review our bug report documentation.

Creating a pull request

Want to contribute a new feature? Please first open a new issue to discuss whether the feature is a good fit for the project.

Once you've decided to commit the time to seeing your pull request through, please follow our guidelines for creating a pull request to make sure it's a pleasant experience. See "Setting up" for details specific to working on this package locally.

Support

GitHub issues aren't for general support questions, but there are other venues you can try: https://wp-cli.org/#support

This README.md is generated dynamically from the project's codebase using wp scaffold package-readme (doc). To suggest changes, please submit a pull request against the corresponding part of the codebase.

Comments
  • Path to REPL.php is displayed for any wp shell command

    Path to REPL.php is displayed for any wp shell command

    Bug Report

    Describe the current, buggy behavior

    When doing any command in wp shell when SSH'd into a remote server, I get a path to the WP-CLI REPL file returned to me before the correct output.

    Describe how other contributors can replicate this bug

    wp> wp_revisions_to_keep( get_post( 3451690 ) );
    => phar:///root/roles/docker-container-web/usr/local/bin/wp/vendor/wp-cli/shell-command/src/WP_CLI/Shell/REPL.php:52:
    int(50)
    

    Describe what you would expect as the correct outcome

    That this path should not appear when using the simplistic REPL.

    wp> wp_revisions_to_keep( get_post( 3451690 ) );
    int(50)
    

    Let us know what environment you are running this on

    OS:	Linux 4.9.0-11-amd64 #1 SMP Debian 4.9.189-3+deb9u1 (2019-09-20) x86_64
    Shell:	/bin/bash
    PHP binary:	/root/roles/nginx-php/usr/local/php7.3/bin.stretch/php
    PHP version:	7.3.16
    php.ini used:	/usr/local/php7.3/conf/php.ini
    WP-CLI root dir:	phar://wp-cli.phar/vendor/wp-cli/wp-cli
    WP-CLI vendor dir:	phar://wp-cli.phar/vendor
    WP_CLI phar path:	/home/vipdev
    WP-CLI packages dir:	/home/{redacted}/.wp-cli/packages/
    WP-CLI global config:
    WP-CLI project config:
    WP-CLI version:	2.4.0
    

    Provide a possible solution

    Maybe remove or fix this var_dump()?

    command:shell 
    opened by GaryJones 5
  • Add possibility to change the shell binary

    Add possibility to change the shell binary

    Basically I have a shared hosting site, that has well,

    [vhost68584ssh@procyon ~]$ which bash
    /usr/local/bin/bash
    [vhost68584ssh@procyon ~]$ /bin/bash
    -bash: /bin/bash: No such file or directory
    

    which means no shell-cookie-sugar-coated-sweetness for me :(

    But as I am not actually a PHP person, I need some tips and pointers on how to get started with this functional testing point "3. Please make sure to include functional tests for your changes." Examples maybe :)

    command:shell 
    opened by villuorav 5
  • Improve `wp shell` command description

    Improve `wp shell` command description

    Related: /wp-cli/issues/4302

    Improve wp shell command description in: https://github.com/wp-cli/shell-command/blob/master/src/Shell_Command.php https://github.com/wp-cli/shell-command/blob/master/README.md

    Current description: Interactive PHP console.

    New description: Opens an interactive PHP console for running and testing PHP code.

    command:shell scope:documentation 
    opened by hearvox 3
  • PHP Parse Error on namespace

    PHP Parse Error on namespace

    wp> namespace dustinpaluch { }
    PHP Parse error:  syntax error, unexpected 'dustinpaluch' (T_STRING), expecting \\ (T_NS_SEPARATOR) in phar:///usr/local/bin/wp/vendor/wp-cli/shell-command/src/WP_CLI/REPL.php(37) : eval()'d code on line 1
    

    I'm trying to reproduce a bug involving namespaces, wp actions, and anonymous functions, and was hoping I'd be able to use the wp shell to make a minimal test case.

    state:unconfirmed 
    opened by dustinpaluch 2
  • What is Boris?

    What is Boris?

    In the documentation on WordPress.org, the flag --basic is described as follows:

    [--basic] Start in fail-safe mode, even if Boris is available.

    What is Boris?

    scope:documentation good-first-issue 
    opened by benlk 2
  • New data is not available when updated from another session

    New data is not available when updated from another session

    Steps to reproduce:

    1. Execute these commands:
    wp> get_post_meta( 139, '_price', true )
    => phar:///Users/boro/bin/wp/php/WP_CLI/REPL.php:43:
    string(3) "100"
    wp> update_post_meta( 139, '_price', 200 )
    => phar:///Users/boro/bin/wp/php/WP_CLI/REPL.php:43:
    bool(true)
    wp> get_post_meta( 139, '_price', true )
    => phar:///Users/boro/bin/wp/php/WP_CLI/REPL.php:43:
    string(3) "200"
    
    1. Leave the wp shell running in background, and in a different session run this DB query:
    mysql> update wp_postmeta set meta_value = '123' where post_id = 139 and meta_key = '_price';
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    1. Go back to the wp shell, and run this:
    wp> get_post_meta( 139, '_price', true )
    => phar:///Users/boro/bin/wp/php/WP_CLI/REPL.php:43:
    string(3) "200"
    wp> 
    

    If you close and open wp shell again, it will return the correct value:

    boro@bor0:~/dev/www/wordpress$ wp shell
    wp> get_post_meta( 139, '_price', true )
    => phar:///Users/boro/bin/wp/php/WP_CLI/REPL.php:43:
    string(3) "123"
    wp> 
    
    opened by bor0 2
  • Provide an installable package for the optional PsySH enhancement

    Provide an installable package for the optional PsySH enhancement

    Right now, using PsySH as the alternative shell implementation requires a rather technical change to the internals of WP-CLI:

    • Either completely install WP-CLI through Composer, instead of using the Phar
    • Or directly edit the ~/.wp-cli/packages/composer.json file

    I'd like to create a new package wp-cli/shell-psysh that you can just install through the WP-CLI package manager to replace the default shell instead (naming of the package up for discussion of course).

    command:shell 
    opened by schlessera 2
  • Bump andstor/file-existence-action from 1 to 2

    Bump andstor/file-existence-action from 1 to 2

    Bumps andstor/file-existence-action from 1 to 2.

    Release notes

    Sourced from andstor/file-existence-action's releases.

    v2.0.0

    Changed

    • Updated to the node16 runtime by default
    • Deprecates the allow_failure variable in favor of fail

    Fixed

    v1.1.0

    Added

    • Support for glob patterns.

    v1.0.1

    Added

    • Checks for existence of files and directories specified in input variables.
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    scope:distribution 
    opened by dependabot[bot] 1
  • Update wp-cli/wp-cli-tests requirement from ^2.1 to ^3.0

    Update wp-cli/wp-cli-tests requirement from ^2.1 to ^3.0

    Updates the requirements on wp-cli/wp-cli-tests to permit the latest version.

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    opened by dependabot[bot] 1
  • Fixed PsySH initialization

    Fixed PsySH initialization

    Hello! Thanks for this amazing project!

    I found a small bug while trying to integrate with PsySH, seems like an incorrect command is used to initialize PsySH:

    Screenshot from 2020-10-14 23-06-59

    This happens because Psy\Shell::debug() is used to introduce breakpoints.

    Note that Psy\Shell->run() is also used by all other integrations: https://github.com/bobthecow/psysh/wiki/Integrations

    command:shell 
    opened by claudiosanches 1
  • Missing `pclose()` in build-in REPL

    Missing `pclose()` in build-in REPL

    Originally reported by @hiobama in #34:

    If exit wp-shell by ctrl + c, some processes will always running there, never give up, slow down your computer.

    bug command:shell 
    opened by schlessera 1
  • Catch exceptions to avoid restarting sesson

    Catch exceptions to avoid restarting sesson

    Feature Request

    Describe your use case and the problem you are facing

    Making typos/etc often results in a fatal error, and the session crashes and has to be restarted. After restarting, I have to recreate any variables, includes, etc from scratch, without making any fatal errors. That often makes it just too frustrating to use.

    > wp shell
    wp> require 'foo.txt';
    Warning: require(foo.txt): Failed to open stream: No such file or directory in phar:///usr/local/bin/wp/vendor/wp-cli/shell-command/src/WP_CLI/Shell/REPL.php(32) : eval()'d code on line 1
    Fatal error: Uncaught Error: Failed opening required 'foo.txt' (include_path='.:/usr/local/Cellar/php/8.0.0_1/share/php/pear') in phar:///usr/local/bin/wp/vendor/wp-cli/shell-command/src/WP_CLI/Shell/REPL.php(32) : eval()'d code:1
    Stack trace:
    #0 phar:///usr/local/bin/wp/vendor/wp-cli/shell-command/src/WP_CLI/Shell/REPL.php(32): eval()
    #1 phar:///usr/local/bin/wp/vendor/wp-cli/shell-command/src/Shell_Command.php(51): WP_CLI\Shell\REPL->start()
    #2 [internal function]: Shell_Command->__invoke(Array, Array)
    #3 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(98): call_user_func(Array, Array, Array)
    #4 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}(Array, Array)
    #5 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php(451): call_user_func(Object(Closure), Array, Array)
    #6 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(371): WP_CLI\Dispatcher\Subcommand->invoke(Array, Array, Array)
    #7 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(394): WP_CLI\Runner->run_command(Array, Array)
    #8 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1160): WP_CLI\Runner->run_command_and_exit()
    #9 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(23): WP_CLI\Runner->start()
    #10 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php(74): WP_CLI\Bootstrap\LaunchRunner->process(Object(WP_CLI\Bootstrap\BootstrapState))
    #11 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php(27): WP_CLI\bootstrap()
    #12 phar:///usr/local/bin/wp/php/boot-phar.php(11): include('phar:///usr/loc...')
    #13 /usr/local/bin/wp(4): include('phar:///usr/loc...')
    #14 {main}
      thrown in phar:///usr/local/bin/wp/vendor/wp-cli/shell-command/src/WP_CLI/Shell/REPL.php(32) : eval()'d code on line 1
    Error: There has been a critical error on this website.Learn more about debugging in WordPress. There has been a critical error on this website.
    

    Describe the solution you'd like

    PHP's REPL is able to catch fatals and continue running:

    php > $foo = 'stuff';
    php > echo $foo;
    stuff
    php > require 'foo.txt';
    
    Warning: require(foo.txt): Failed to open stream: No such file or directory in php shell code on line 1
    
    Warning: Uncaught Error: Failed opening required 'foo.txt' (include_path='.:/usr/local/Cellar/php/8.0.0_1/share/php/pear') in php shell code:1
    Stack trace:
    #0 {main}
      thrown in php shell code on line 1
    php > echo $foo;
    stuff
    

    Is that possible for wp shell ?

    command:shell 
    opened by iandunn 3
  • Feature request: support ksh under OpenBSD

    Feature request: support ksh under OpenBSD

    Feature Request

    Add support for default shell on OpenBSD (ksh).

    Describe your use case and the problem you are facing

    Trying to use wp shell cmd under OpenBSD results in errors and exits prematurely.

    $ wp shell
    /bin/ksh: fc: history functions not available
    /bin/ksh: read: -e: unknown option
    $ echo $?
    0
    
    
    $ wp cli info
    OS:     OpenBSD 6.6 GENERIC.MP#584 amd64
    Shell:  /bin/ksh
    PHP binary:     /usr/local/bin/php-7.3
    PHP version:    7.3.13
    php.ini used:   /etc/php-7.3.ini
    WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
    WP-CLI vendor dir:      phar://wp-cli.phar/vendor
    WP_CLI phar path:       /var/www/htdocs
    WP-CLI packages dir:
    WP-CLI global config:
    WP-CLI project config:
    WP-CLI version: 2.4.0
    $ env | grep WP_CLI_CUSTOM_SHELL
    WP_CLI_CUSTOM_SHELL=/bin/ksh
    

    Describe the solution you'd like

    Quick win:

    Add some more detection at shell instantiation to detect shell and platform to enable running in ksh on OpenBSD.

    Nice to have:

    Test in a few different shell/OS environments and modify to run across more - else, fail gracefully when unsupported.

    Happy to work on this

    command:shell 
    opened by leonstafford 1
  • Internal variables bleed over and cause conflicts

    Internal variables bleed over and cause conflicts

    I haven't had the chance to dig into this further, but just wanted to log this somewhere to prevent forgetting about it.

    Assigning a value to $line in wp shell gives very unexpected results, causing some pretty confusing behavior and bugs.

    Behavior:

    wp shell
    
    wp> $line = 'this wont work';
    => string(14) 'this wont work'
    wp> $line;
    => string(13) "return $line;"
    
    wp> $linetest = 'this will';
    => string(9) "this will"
    wp> $linetest;
    => string(9) "this will"
    
    command:shell 
    opened by WPprodigy 2
Releases(v2.0.11)
Owner
WP-CLI
The command line interface for WordPress
WP-CLI
A webshell plugin and interactive shell for pentesting a Moodle instance.

Moodle webshell plugin for RCE A webshell plugin and interactive shell for pentesting a Moodle instance. Features Webshell plugin for Moodle. Execute

Podalirius 11 Oct 10, 2022
Kirby 3 Plugin for running jobs like cleaning the cache from within the Panel, PHP code, CLI or a cronjob

Kirby 3 Janitor Kirby 3 Plugin for running jobs. It is a Panel Button! It has jobs build-in for cleaning the cache, sessions, create zip-backup, pre-g

Bruno Meilick 68 Dec 21, 2022
Testing your OpenApi documentation and your code easily.

Raven - How to test your API documentation and behavior. This library was written to allow testing OpenAPI documentation easily. It also allows verify

CH Studio 30 Dec 6, 2022
A console noughts and crosses game written in php

Tic-tac-toe A console noughts and crosses game written in php To play, simply clone the file Navigate to the file directory on your terminal and run t

Etorojah Okon 1 Oct 13, 2021
Running Laravel and React stacks together using Vite and InertiaJS on Docker.

Laravel-Vite-Docker Running Laravel and React stacks together using Vite and InertiaJS on Docker. Explore project's blog » Report Bug · Request Featur

Elvin Lari 6 Dec 22, 2022
This tools helps you with Collectors in DependecyInjection, Console shortcuts, ParameterProvider as service and many more.

Package Builder This tools helps you with Collectors in DependecyInjection, Console shortcuts, ParameterProvider as service and many more. Install com

null 168 Dec 22, 2022
This is a plugin written in PHP programming language and running on the PocketMine platform that works stably on the API 3.25.0 platform

This is a plugin written in PHP programming language and running on the PocketMine platform that works stably on the API 3.25.0 platform. It allows you to hear the sound

Thành Nhân 10 Sep 27, 2022
A PHP framework for console artisans

This is a community project and not an official Laravel one Laravel Zero was created by, and is maintained by Nuno Maduro, and is a micro-framework th

Laravel Zero 3.2k Jan 8, 2023
A complete stack for running Symfony 5 into Docker containers using docker-compose tool and with Certbot for the HTTPS certificate.

?? Docker + PHP 7.4 + MySQL8.0 + Nginx + Certbot(HTTPS) + Symfony 5 Boilerplate ?? Edited from https://github.com/ger86/symfony-docker version -> http

null 6 Nov 9, 2022
Scotch Box is a preconfigured Vagrant Box with a full array of LAMP Stack features to get you up and running with Vagrant in no time.

Scotch Box is a preconfigured Vagrant Box with a full array of LAMP Stack features to get you up and running with Vagrant in no time.

scotch 2.7k Jan 8, 2023
ATVController for android devices running with RDM > POGO > ATLAS. Quick, simple and dirty add controls with a GUI view

ATVController - WIP - Much to add and fix. ATVController for android devices running with RDM > POGO > ATLAS. Quick, simple and dirty adb controls wit

null 7 Nov 21, 2022
Demo of symfony/console features to build rich command line utilities

Symfony Console Demo This project is a demonstration of symfony/console features. To run the project with Docker. With bash: docker build -t myconsole

Jérôme Tamarelle 3 Jun 16, 2022
The plugin allows to execute math operations in the server or console.

General The plugin allows to execute math operations in the server or console with /calculator command Arithmetic Operators List of supported arithmet

NhanAZ's PocketMine-MP Plugins 3 Oct 20, 2022
A sampling profiler for PHP written in PHP, which reads information about running PHP VM from outside of the process.

Reli Reli is a sampling profiler (or a VM state inspector) written in PHP. It can read information about running PHP script from outside of the proces

null 272 Dec 22, 2022
A sampling profiler for PHP written in PHP, which reads information about running PHP VM from outside of the process.

Reli Reli is a sampling profiler (or a VM state inspector) written in PHP. It can read information about running PHP script from outside of the proces

null 258 Sep 15, 2022
MageVagrant - Vagrant/Chef base box for running Magento

MageVagrant MageVagrant is a complete LAMP development environment for Magento. Specially created for the Magento Developer's Guide book. Features Aut

null 59 Sep 28, 2021
A multi-purpose web-shell that simplifies running shell commands on webserver

This webshell can be used for multi-purposed especially most if you want to manage your web server but you are in an emergency , so why not use a webshell:)

urchinsec 5 Oct 13, 2022
A Laravel 9 package that allows you enforce security of your artisan commands by authenticating users before running.

Introduction This package allows you as a developer to restrict who can and cannot run artisan commands, especially in a production environment. For e

YOo Slim 2 Sep 15, 2022
PSpec is a testing framework for PHP, influenced by RSpec and jest. 🧪 This repo is a MIRROR of the GitLab source repository.

PSpec PSpec is a testing framework for PHP, influenced by RSpec and jest. This project is experimental and still needs a lot of work. Example // src/C

CodingPaws 0 Mar 31, 2022