Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions features/option-list.feature
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ Feature: List WordPress options
"""
sample_test_field_one
"""
And STDOUT should not contain:
"""
_transient
"""

When I run `wp option list --exclude="sample_test_field_one"`
Then STDOUT should not contain:
Expand Down Expand Up @@ -117,3 +121,21 @@ Feature: List WordPress options
sample_test_field_one,sample_test_field_value_one
"""

Scenario: Default list option without transient
Given a WP install
And I run `wp transient set wp_transient_flag wp_transient_flag`

When I run `wp option list`
Then STDOUT should not contain:
"""
wp_transient_flag
"""
And STDOUT should not contain:
"""
_transient
"""
And STDOUT should contain:
"""
siteurl
"""

32 changes: 32 additions & 0 deletions features/user.feature
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,38 @@ Feature: Manage WordPress users
Success: Removed 'edit_vip_product' cap for admin (1).
"""

And I try the previous command again
Then the return code should be 1
And STDERR should be:
"""
Error: No such 'edit_vip_product' cap for admin (1).
"""
And STDOUT should be empty

When I run `wp user list-caps 1`
Then STDOUT should not contain:
"""
edit_vip_product
"""
And STDOUT should contain:
"""
publish_posts
"""

When I try `wp user remove-cap 1 publish_posts`
Then the return code should be 1
And STDERR should be:
"""
Error: The 'publish_posts' cap for admin (1) is inherited from a role.
"""
And STDOUT should be empty

And I run `wp user list-caps 1`
Then STDOUT should contain:
"""
publish_posts
"""

Scenario: Show password when creating a user
Given a WP install

Expand Down
8 changes: 6 additions & 2 deletions src/Option_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public function list_( $args, $assoc_args ) {
global $wpdb;
$pattern = '%';
$exclude = '';

$fields = array( 'option_name', 'option_value' );
$size_query = ",LENGTH(option_value) AS `size_bytes`";
$autoload_query = '';
Expand Down Expand Up @@ -277,11 +278,14 @@ public function list_( $args, $assoc_args ) {
}
}

// By default we don't want to display transients.
$show_transients = Utils\get_flag_value( $assoc_args, 'transients', false );

$transients_query = '';
if ( true === Utils\get_flag_value( $assoc_args, 'transients', null ) ) {
if ( $show_transients ) {
$transients_query = " AND option_name LIKE '\_transient\_%'
OR option_name LIKE '\_site\_transient\_%'";
} else if ( false === Utils\get_flag_value( $assoc_args, 'transients', null ) ) {
} else {
$transients_query = " AND option_name NOT LIKE '\_transient\_%'
AND option_name NOT LIKE '\_site\_transient\_%'";
}
Expand Down
102 changes: 51 additions & 51 deletions src/Post_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,82 +38,82 @@ public function __construct() {
* Creates a new post.
*
* ## OPTIONS
*
*
* [--post_author=<post_author>]
* : The ID of the user who added the post. Default is the current user ID.
*
*
* [--post_date=<post_date>]
* : The date of the post. Default is the current time.
*
*
* [--post_date_gmt=<post_date_gmt>]
* : The date of the post in the GMT timezone. Default is the value of $post_date.
*
* [--post_content=<post_content>]
* : The post content. Default empty.
*
*
* [--post_content_filtered=<post_content_filtered>]
* : The filtered post content. Default empty.
*
*
* [--post_title=<post_title>]
* : The post title. Default empty.
*
*
* [--post_excerpt=<post_excerpt>]
* : The post excerpt. Default empty.
*
*
* [--post_status=<post_status>]
* : The post status. Default 'draft'.
*
*
* [--post_type=<post_type>]
* : The post type. Default 'post'.
*
*
* [--comment_status=<comment_status>]
* : Whether the post can accept comments. Accepts 'open' or 'closed'. Default is the value of 'default_comment_status' option.
*
*
* [--ping_status=<ping_status>]
* : Whether the post can accept pings. Accepts 'open' or 'closed'. Default is the value of 'default_ping_status' option.
*
*
* [--post_password=<post_password>]
* : The password to access the post. Default empty.
*
*
* [--post_name=<post_name>]
* : The post name. Default is the sanitized post title when creating a new post.
*
*
* [--to_ping=<to_ping>]
* : Space or carriage return-separated list of URLs to ping. Default empty.
*
*
* [--pinged=<pinged>]
* : Space or carriage return-separated list of URLs that have been pinged. Default empty.
*
*
* [--post_modified=<post_modified>]
* : The date when the post was last modified. Default is the current time.
*
*
* [--post_modified_gmt=<post_modified_gmt>]
* : The date when the post was last modified in the GMT timezone. Default is the current time.
*
*
* [--post_parent=<post_parent>]
* : Set this for the post it belongs to, if any. Default 0.
*
*
* [--menu_order=<menu_order>]
* : The order the post should be displayed in. Default 0.
*
*
* [--post_mime_type=<post_mime_type>]
* : The mime type of the post. Default empty.
*
*
* [--guid=<guid>]
* : Global Unique ID for referencing the post. Default empty.
*
*
* [--post_category=<post_category>]
* : Array of category names, slugs, or IDs. Defaults to value of the 'default_category' option.
*
*
* [--tags_input=<tags_input>]
* : Array of tag names, slugs, or IDs. Default empty.
*
*
* [--tax_input=<tax_input>]
* : Array of taxonomy terms keyed by their taxonomy name. Default empty.
*
*
* [--meta_input=<meta_input>]
* : Array of post meta values keyed by their post meta key. Default empty.
*
*
* [<file>]
* : Read post content from <file>. If this value is present, the
* `--post_content` argument will be ignored.
Expand Down Expand Up @@ -175,79 +175,79 @@ public function create( $args, $assoc_args ) {
*
* <id>...
* : One or more IDs of posts to update.
*
*
* [--post_author=<post_author>]
* : The ID of the user who added the post. Default is the current user ID.
*
*
* [--post_date=<post_date>]
* : The date of the post. Default is the current time.
*
*
* [--post_date_gmt=<post_date_gmt>]
* : The date of the post in the GMT timezone. Default is the value of $post_date.
*
* [--post_content=<post_content>]
* : The post content. Default empty.
*
*
* [--post_content_filtered=<post_content_filtered>]
* : The filtered post content. Default empty.
*
*
* [--post_title=<post_title>]
* : The post title. Default empty.
*
*
* [--post_excerpt=<post_excerpt>]
* : The post excerpt. Default empty.
*
*
* [--post_status=<post_status>]
* : The post status. Default 'draft'.
*
*
* [--post_type=<post_type>]
* : The post type. Default 'post'.
*
*
* [--comment_status=<comment_status>]
* : Whether the post can accept comments. Accepts 'open' or 'closed'. Default is the value of 'default_comment_status' option.
*
*
* [--ping_status=<ping_status>]
* : Whether the post can accept pings. Accepts 'open' or 'closed'. Default is the value of 'default_ping_status' option.
*
*
* [--post_password=<post_password>]
* : The password to access the post. Default empty.
*
*
* [--post_name=<post_name>]
* : The post name. Default is the sanitized post title when creating a new post.
*
*
* [--to_ping=<to_ping>]
* : Space or carriage return-separated list of URLs to ping. Default empty.
*
*
* [--pinged=<pinged>]
* : Space or carriage return-separated list of URLs that have been pinged. Default empty.
*
*
* [--post_modified=<post_modified>]
* : The date when the post was last modified. Default is the current time.
*
*
* [--post_modified_gmt=<post_modified_gmt>]
* : The date when the post was last modified in the GMT timezone. Default is the current time.
*
*
* [--post_parent=<post_parent>]
* : Set this for the post it belongs to, if any. Default 0.
*
*
* [--menu_order=<menu_order>]
* : The order the post should be displayed in. Default 0.
*
*
* [--post_mime_type=<post_mime_type>]
* : The mime type of the post. Default empty.
*
*
* [--guid=<guid>]
* : Global Unique ID for referencing the post. Default empty.
*
*
* [--post_category=<post_category>]
* : Array of category names, slugs, or IDs. Defaults to value of the 'default_category' option.
*
*
* [--tags_input=<tags_input>]
* : Array of tag names, slugs, or IDs. Default empty.
*
*
* [--tax_input=<tax_input>]
* : Array of taxonomy terms keyed by their taxonomy name. Default empty.
*
*
* [--meta_input=<meta_input>]
* : Array of post meta values keyed by their post meta key. Default empty.
*
Expand Down Expand Up @@ -393,8 +393,8 @@ public function get( $args, $assoc_args ) {
*
* # Delete all posts in the trash
* $ wp post delete $(wp post list --post_status=trash --format=ids)
* Success: Trashed post 1268.
* Success: Trashed post 1294.
* Success: Deleted post 1268.
* Success: Deleted post 1294.
*/
public function delete( $args, $assoc_args ) {
$defaults = array(
Expand Down
12 changes: 12 additions & 0 deletions src/User_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -747,12 +747,24 @@ public function add_cap( $args, $assoc_args ) {
* $ wp user remove-cap 11 publish_newsletters
* Success: Removed 'publish_newsletters' cap for supervisor (11).
*
* $ wp user remove-cap 11 publish_posts
* Error: The 'publish_posts' cap for supervisor (11) is inherited from a role.
*
* $ wp user remove-cap 11 nonexistent_cap
* Error: No such 'nonexistent_cap' cap for supervisor (11).
*
* @subcommand remove-cap
*/
public function remove_cap( $args, $assoc_args ) {
$user = $this->fetcher->get_check( $args[0] );
if ( $user ) {
$cap = $args[1];
if ( ! isset( $user->caps[ $cap ] ) ) {
if ( isset( $user->allcaps[ $cap ] ) ) {
WP_CLI::error( sprintf( "The '%s' cap for %s (%d) is inherited from a role.", $cap, $user->user_login, $user->ID ) );
}
WP_CLI::error( sprintf( "No such '%s' cap for %s (%d).", $cap, $user->user_login, $user->ID ) );
}
$user->remove_cap( $cap );

WP_CLI::success( sprintf( "Removed '%s' cap for %s (%d).", $cap, $user->user_login, $user->ID ) );
Expand Down