PHP Class User_Command, wp-cli

Inheritance: extends WP_CLI\CommandWithDBObject
Mostra file Open project: wp-cli/wp-cli Class Usage Examples

Protected Properties

Property Type Description
$obj_fields
$obj_type

Public Methods

Method Description
__construct ( )
add_cap ( $args, $assoc_args ) Add a capability to a user.
add_role ( $args, $assoc_args ) Add a role for a user.
create ( $args, $assoc_args ) Create a new user.
delete ( $args, $assoc_args ) Delete one or more users from the current site.
generate ( $args, $assoc_args ) Generate some users.
get ( $args, $assoc_args ) Get details about a user.
import_csv ( $args, $assoc_args ) Import users from a CSV file.
list_ ( $args, $assoc_args ) List users.
list_caps ( $args, $assoc_args ) List all capabilities for a user.
remove_cap ( $args, $assoc_args ) Remove a user's capability.
remove_role ( $args, $assoc_args ) Remove a user's role.
set_role ( $args, $assoc_args ) Set the user role.
update ( $args, $assoc_args ) Update an existing user.

Private Methods

Method Description
validate_role ( $role ) Check whether the role is valid
wp_new_user_notification ( string $user_id, string $password ) Acommodate three different behaviors for wp_new_user_notification() - 4.3.1 and above: expect second argument to be deprecated - 4.3: Second argument was repurposed as $notify - Below 4.3: Send the password in the notification

Method Details

__construct() public method

public __construct ( )

add_cap() public method

## OPTIONS : User ID, user email, or user login. : The capability to add. ## EXAMPLES # Add a capability for a user $ wp user add-cap john create_premium_item Success: Added 'create_premium_item' capability for john (16). # Add a capability for a user $ wp user add-cap 15 edit_product Success: Added 'edit_product' capability for johndoe (15).
public add_cap ( $args, $assoc_args )

add_role() public method

## OPTIONS : User ID, user email, or user login. : Add the specified role to the user. ## EXAMPLES $ wp user add-role 12 author Success: Added 'author' role for johndoe (12).
public add_role ( $args, $assoc_args )

create() public method

## OPTIONS : The login of the user to create. : The email address of the user to create. [--role=] : The role of the user to create. Default: default role [--user_pass=] : The user password. Default: randomly generated [--user_registered=] : The date the user registered. Default: current date [--display_name=] : The display name. [--first_name=] : The user's first name. [--last_name=] : The user's last name. [--send-email] : Send an email to the user with their new account details. [--porcelain] : Output just the new user id. ## EXAMPLES # Create user $ wp user create bob [email protected] --role=author Success: Created user 3. Password: k9**&I4vNH(&
public create ( $args, $assoc_args )

delete() public method

On multisite, wp user delete only removes the user from the current site. Include --network to also remove the user from the database, but make sure to reassign their posts prior to deleting the user. ## OPTIONS ... : The user login, user email, or user ID of the user(s) to delete. [--network] : On multisite, delete the user from the entire network. [--reassign=] : User ID to reassign the posts to. [--yes] : Answer yes to any confirmation prompts. ## EXAMPLES # Delete user 123 and reassign posts to user 567 $ wp user delete 123 --reassign=567 Success: Removed user 123 from http://example.com # Delete all contributors and reassign their posts to user 2 $ wp user delete $(wp user list --role=contributor --format=ids) --reassign=2 Success: Removed user 813 from http://example.com Success: Removed user 578 from http://example.com
public delete ( $args, $assoc_args )

generate() public method

Creates a specified number of new users with dummy data. ## OPTIONS [--count=] : How many users to generate? --- default: 100 --- [--role=] : The role of the generated users. Default: default role from WP [--format=] : Render output in a particular format. --- default: progress options: - progress - ids --- ## EXAMPLES # Add meta to every generated users. $ wp user generate --format=ids --count=3 | xargs -d ' ' -I % wp user meta add % foo bar Success: Added custom field. Success: Added custom field. Success: Added custom field.
public generate ( $args, $assoc_args )

get() public method

## OPTIONS : User ID, user email, or user login. [--field=] : Instead of returning the whole user, returns the value of a single field. [--fields=] : Get a specific subset of the user's fields. [--format=] : Render output in a particular format. --- default: table options: - table - csv - json - yaml --- ## EXAMPLES # Get user $ wp user get 12 --field=login supervisor # Get user and export to JSON file $ wp user get bob --format=json > bob.json
public get ( $args, $assoc_args )

import_csv() public method

If the user already exists (matching the email address or login), then the user is updated unless the --skip-update flag is used. ## OPTIONS : The local or remote CSV file of users to import. [--send-email] : Send an email to new users with their account details. [--skip-update] : Don't update users that already exist. ## EXAMPLES # Import users from local CSV file $ wp user import-csv /path/to/users.csv Success: bobjones created Success: newuser1 created Success: existinguser created # Import users from remote CSV file $ wp user import-csv http://example.com/users.csv Sample users.csv file: user_login,user_email,display_name,role bobjones,[email protected],Bob Jones,contributor newuser1,[email protected],New User,author existinguser,[email protected],Existing User,administrator
public import_csv ( $args, $assoc_args )

list_() public method

## OPTIONS [--role=] : Only display users with a certain role. [--=] : Control output by one or more arguments of get_users(). [--network] : List all users in the network for multisite. [--field=] : Prints the value of a single field for each user. [--fields=] : Limit the output to specific object fields. [--format=] : Render output in a particular format. --- default: table options: - table - csv - ids - json - count - yaml --- ## AVAILABLE FIELDS These fields will be displayed by default for each user: * ID * user_login * display_name * user_email * user_registered * roles These fields are optionally available: * user_pass * user_nicename * user_url * user_activation_key * user_status * spam * deleted * caps * cap_key * allcaps * filter * url ## EXAMPLES # List user IDs $ wp user list --field=ID 1 # List users with administrator role $ wp user list --role=administrator --format=csv ID,user_login,display_name,user_email,user_registered,roles 1,supervisor,supervisor,[email protected],"2016-06-03 04:37:00",administrator # List users with only given fields $ wp user list --fields=display_name,user_email --format=json [{"display_name":"supervisor","user_email":"[email protected]"}]
public list_ ( $args, $assoc_args )

list_caps() public method

## OPTIONS : User ID, user email, or login. [--format=] : Render output in a particular format. --- default: list options: - list - table - csv - json - count - yaml --- ## EXAMPLES $ wp user list-caps 21 edit_product create_premium_item
public list_caps ( $args, $assoc_args )

remove_cap() public method

## OPTIONS : User ID, user email, or user login. : The capability to be removed. ## EXAMPLES $ wp user remove-cap 11 publish_newsletters Success: Removed 'publish_newsletters' cap for supervisor (11).
public remove_cap ( $args, $assoc_args )

remove_role() public method

## OPTIONS : User ID, user email, or user login. [] : A specific role to remove. ## EXAMPLES $ wp user remove-role 12 author Success: Removed 'author' role for johndoe (12).
public remove_role ( $args, $assoc_args )

set_role() public method

## OPTIONS : User ID, user email, or user login. [] : Make the user have the specified role. If not passed, the default role is used. ## EXAMPLES $ wp user set-role 12 author Success: Added johndoe (12) to http://example.com as author.
public set_role ( $args, $assoc_args )

update() public method

## OPTIONS ... : The user login, user email or user ID of the user(s) to update. --= : One or more fields to update. For accepted fields, see wp_update_user(). ## EXAMPLES # Update user $ wp user update 123 --display_name=Mary --user_pass=marypass Success: Updated user 123.
public update ( $args, $assoc_args )

Property Details

$obj_fields protected_oe property

protected $obj_fields

$obj_type protected_oe property

protected $obj_type