PHP Class Plugin_Command, wp-cli

Inheritance: extends WP_CLI_Command_With_Upgrade
Show file Open project: wp-cli/wp-cli

Protected Properties

Property Type Description
$item_type
$obj_fields
$upgrade_refresh
$upgrade_transient

Public Methods

Method Description
__construct ( )
activate ( $args, $assoc_args = [] ) Activate a plugin.
deactivate ( $args, $assoc_args = [] ) Deactivate a plugin.
delete ( $args, $assoc_args = [] ) Delete plugin files without deactivating or uninstalling.
get ( $args, $assoc_args ) Get details about an installed plugin.
install ( $args, $assoc_args ) Install a plugin.
is_installed ( $args, $assoc_args = [] ) Check if the plugin is installed.
list_ ( $_, $assoc_args ) Get a list of plugins.
path ( $args, $assoc_args ) Get the path to a plugin or to the plugin directory.
search ( $args, $assoc_args ) Search the WordPress.org plugin directory.
status ( $args ) See the status of one or all plugins.
toggle ( $args, $assoc_args = [] ) Toggle a plugin's activation state.
uninstall ( $args, $assoc_args = [] ) Uninstall a plugin.
update ( $args, $assoc_args ) Update one or more plugins.

Protected Methods

Method Description
filter_item_list ( $items, $args )
get_all_items ( )
get_item_list ( )
get_status ( $file )
get_upgrader_class ( $force )
install_from_repo ( $slug, $assoc_args )
status_single ( $args )

Private Methods

Method Description
_delete ( $plugin )
active_output ( $name, $file, $network_wide, $action )
check_active ( $file, $network_wide ) * PRIVATES
get_details ( $file ) : array Get the details of a plugin.

Method Details

__construct() public method

public __construct ( )

activate() public method

## OPTIONS [...] : One or more plugins to activate. [--all] : If set, all plugins will be activated. [--network] : If set, the plugin will be activated for the entire multisite network. ## EXAMPLES # Activate plugin $ wp plugin activate hello-dolly Plugin 'hello-dolly' activated. Success: Activated 1 of 1 plugins. # Activate plugin in entire multisite network $ wp plugin activate hello-dolly --network Plugin 'hello-dolly' network activated. Success: Network activated 1 of 1 plugins.
public activate ( $args, $assoc_args = [] )

deactivate() public method

## OPTIONS [...] : One or more plugins to deactivate. [--uninstall] : Uninstall the plugin after deactivation. [--all] : If set, all plugins will be deactivated. [--network] : If set, the plugin will be deactivated for the entire multisite network. ## EXAMPLES # Deactivate plugin $ wp plugin deactivate hello-dolly Plugin 'hello-dolly' deactivated. Success: Deactivated 1 of 1 plugins.
public deactivate ( $args, $assoc_args = [] )

delete() public method

## OPTIONS ... : One or more plugins to delete. ## EXAMPLES # Delete plugin $ wp plugin delete hello Deleted 'hello' plugin. Success: Deleted 1 of 1 plugins. # Delete inactive plugins $ wp plugin delete $(wp plugin list --status=inactive --field=name) Deleted 'tinymce-templates' plugin. Success: Deleted 1 of 1 plugins.
public delete ( $args, $assoc_args = [] )

filter_item_list() protected method

protected filter_item_list ( $items, $args )

get() public method

## OPTIONS : The plugin to get. [--field=] : Instead of returning the whole plugin, returns the value of a single field. [--fields=] : Limit the output to specific fields. Defaults to all fields. [--format=] : Render output in a particular format. --- default: table options: - table - csv - json - yaml --- ## EXAMPLES $ wp plugin get bbpress --format=json {"name":"bbpress","title":"bbPress","author":"The bbPress Contributors","version":"2.6-alpha","description":"bbPress is forum software with a twist from the creators of WordPress.","status":"active"}
public get ( $args, $assoc_args )

get_all_items() protected method

protected get_all_items ( )

get_item_list() protected method

protected get_item_list ( )

get_status() protected method

protected get_status ( $file )

get_upgrader_class() protected method

protected get_upgrader_class ( $force )

install() public method

## OPTIONS ... : A plugin slug, the path to a local zip file, or URL to a remote zip file. [--version=] : If set, get that particular version from wordpress.org, instead of the stable version. [--force] : If set, the command will overwrite any installed version of the plugin, without prompting for confirmation. [--activate] : If set, the plugin will be activated immediately after install. [--activate-network] : If set, the plugin will be network activated immediately after install ## EXAMPLES # Install the latest version from wordpress.org and activate $ wp plugin install bbpress --activate Installing bbPress (2.5.9) Downloading install package from https://downloads.wordpress.org/plugin/bbpress.2.5.9.zip... Using cached file '/home/vagrant/.wp-cli/cache/plugin/bbpress-2.5.9.zip'... Unpacking the package... Installing the plugin... Plugin installed successfully. Activating 'bbpress'... Plugin 'bbpress' activated. Success: Installed 1 of 1 plugins. # Install the development version from wordpress.org $ wp plugin install bbpress --version=dev Installing bbPress (Development Version) Downloading install package from https://downloads.wordpress.org/plugin/bbpress.zip... Unpacking the package... Installing the plugin... Plugin installed successfully. Success: Installed 1 of 1 plugins. # Install from a local zip file $ wp plugin install ../my-plugin.zip Unpacking the package... Installing the plugin... Plugin installed successfully. Success: Installed 1 of 1 plugins. # Install from a remote zip file $ wp plugin install http://s3.amazonaws.com/bucketname/my-plugin.zip?AWSAccessKeyId=123&Expires=456&Signature=abcdef Downloading install package from http://s3.amazonaws.com/bucketname/my-plugin.zip?AWSAccessKeyId=123&Expires=456&Signature=abcdef Unpacking the package... Installing the plugin... Plugin installed successfully. Success: Installed 1 of 1 plugins. # Forcefully re-install all installed plugins $ wp plugin install $(wp plugin list --field=name) --force Installing Akismet (3.1.11) Downloading install package from https://downloads.wordpress.org/plugin/akismet.3.1.11.zip... Unpacking the package... Installing the plugin... Removing the old version of the plugin... Plugin updated successfully Success: Installed 1 of 1 plugins.
public install ( $args, $assoc_args )

install_from_repo() protected method

protected install_from_repo ( $slug, $assoc_args )

is_installed() public method

Returns exit code 0 when installed, 1 when uninstalled. ## OPTIONS : The plugin to check. ## EXAMPLES # Check whether plugin is installed; exit status 0 if installed, otherwise 1 $ wp plugin is-installed hello-dolly $ echo $? 1
public is_installed ( $args, $assoc_args = [] )

list_() public method

## OPTIONS [--=] : Filter results based on the value of a field. [--field=] : Prints the value of a single field for each plugin. [--fields=] : Limit the output to specific object fields. [--format=] : Render output in a particular format. --- default: table options: - table - csv - count - json - yaml --- ## AVAILABLE FIELDS These fields will be displayed by default for each plugin: * name * status * update * version These fields are optionally available: * update_version * update_package * update_id * title * description ## EXAMPLES # List active plugins on the site. $ wp plugin list --status=active --format=json [{"name":"dynamic-hostname","status":"active","update":"none","version":"0.4.2"},{"name":"tinymce-templates","status":"active","update":"none","version":"4.4.3"},{"name":"wp-multibyte-patch","status":"active","update":"none","version":"2.4"},{"name":"wp-total-hacks","status":"active","update":"none","version":"2.0.1"}] # List plugins on each site in a network. $ wp site list --field=url | xargs -I % wp plugin list --url=% +---------+----------------+--------+---------+ | name | status | update | version | +---------+----------------+--------+---------+ | akismet | active-network | none | 3.1.11 | | hello | inactive | none | 1.6 | +---------+----------------+--------+---------+ +---------+----------------+--------+---------+ | name | status | update | version | +---------+----------------+--------+---------+ | akismet | active-network | none | 3.1.11 | | hello | inactive | none | 1.6 | +---------+----------------+--------+---------+
public list_ ( $_, $assoc_args )

path() public method

## OPTIONS [] : The plugin to get the path to. If not set, will return the path to the plugins directory. [--dir] : If set, get the path to the closest parent directory, instead of the plugin file. ## EXAMPLES $ cd $(wp plugin path) && pwd var/www/wordpress/wp-content/plugins
public path ( $args, $assoc_args )

status() public method

## OPTIONS [] : A particular plugin to show the status for. ## EXAMPLES # Displays status of all plugins $ wp plugin status 5 installed plugins: I akismet 3.1.11 I easy-digital-downloads 2.5.16 A theme-check 20160523.1 I wen-logo-slider 2.0.3 M ns-pack 1.0.0 Legend: I = Inactive, A = Active, M = Must Use # Displays status of a plugin $ wp plugin status theme-check Plugin theme-check details: Name: Theme Check Status: Active Version: 20160523.1 Author: Otto42, pross Description: A simple and easy way to test your theme for all the latest WordPress standards and practices. A great theme development tool!
public status ( $args )

status_single() protected method

protected status_single ( $args )

toggle() public method

If the plugin is active, then it will be deactivated. If the plugin is inactive, then it will be activated. ## OPTIONS ... : One or more plugins to toggle. [--network] : If set, the plugin will be toggled for the entire multisite network. ## EXAMPLES # Akismet is currently activated $ wp plugin toggle akismet Plugin 'akismet' deactivated. Success: Toggled 1 of 1 plugins. # Akismet is currently deactivated $ wp plugin toggle akismet Plugin 'akismet' activated. Success: Toggled 1 of 1 plugins.
public toggle ( $args, $assoc_args = [] )

uninstall() public method

## OPTIONS ... : One or more plugins to uninstall. [--deactivate] : Deactivate the plugin before uninstalling. Default behavior is to warn and skip if the plugin is active. [--skip-delete] : If set, the plugin files will not be deleted. Only the uninstall procedure will be run. ## EXAMPLES $ wp plugin uninstall hello Uninstalled and deleted 'hello' plugin. Success: Installed 1 of 1 plugins.
public uninstall ( $args, $assoc_args = [] )

update() public method

## OPTIONS [...] : One or more plugins to update. [--all] : If set, all plugins that have updates will be updated. [--format=] : Output summary as table or summary. Defaults to table. [--version=] : If set, the plugin will be updated to the specified version. [--dry-run] : Preview which plugins would be updated. ## EXAMPLES $ wp plugin update bbpress --version=dev Installing bbPress (Development Version) Downloading install package from https://downloads.wordpress.org/plugin/bbpress.zip... Unpacking the package... Installing the plugin... Removing the old version of the plugin... Plugin updated successfully. Success: Updated 1 of 2 plugins. $ wp plugin update --all Enabling Maintenance mode... Downloading update from https://downloads.wordpress.org/plugin/akismet.3.1.11.zip... Unpacking the update... Installing the latest version... Removing the old version of the plugin... Plugin updated successfully. Downloading update from https://downloads.wordpress.org/plugin/nginx-champuru.3.2.0.zip... Unpacking the update... Installing the latest version... Removing the old version of the plugin... Plugin updated successfully. Disabling Maintenance mode... +------------------------+-------------+-------------+---------+ | name | old_version | new_version | status | +------------------------+-------------+-------------+---------+ | akismet | 3.1.3 | 3.1.11 | Updated | | nginx-cache-controller | 3.1.1 | 3.2.0 | Updated | +------------------------+-------------+-------------+---------+ Success: Updated 2 of 2 plugins.
public update ( $args, $assoc_args )

Property Details

$item_type protected property

protected $item_type

$obj_fields protected property

protected $obj_fields

$upgrade_refresh protected property

protected $upgrade_refresh

$upgrade_transient protected property

protected $upgrade_transient