diff --git a/src/doc/user-meta-set.txt b/src/doc/user-meta-set.txt new file mode 100644 index 0000000000..b40cc0cc4b --- /dev/null +++ b/src/doc/user-meta-set.txt @@ -0,0 +1,24 @@ +wp-user-meta-set(1) -- Update a meta field for a WordPress user. +==== + +## SYNOPSIS + +`wp user-meta set` + +## OPTIONS + +* ``: + + The ID of the user to update. + +* meta_key: + + The meta_key to be updated + +* meta_value: + + The new desired value of the meta_key + +## EXAMPLES + + wp user-meta set 123 description "Mary is a WordPress developer" diff --git a/src/php/wp-cli/commands/internals/user-meta.php b/src/php/wp-cli/commands/internals/user-meta.php new file mode 100644 index 0000000000..7636eff275 --- /dev/null +++ b/src/php/wp-cli/commands/internals/user-meta.php @@ -0,0 +1,51 @@ + NULL ); @@ -90,7 +86,7 @@ public function create( $args, $assoc_args ) { $user_email = $args[1]; if ( ! $user_login || ! $user_email ) { - WP_CLI::error("Login and email required (see 'wp user help')."); + self::error_see_help( "Login and email required" ); } $defaults = array( @@ -136,11 +132,7 @@ public function create( $args, $assoc_args ) { * @param array $assoc_args **/ public function update( $args, $assoc_args ) { - $user_id = $args[0]; - - if ( ! is_numeric($user_id) ) { - WP_CLI::error( "User ID required (see 'wp user help')." ); - } + $user_id = self::get_numeric_arg_or_error($args, 0, "User ID"); if ( empty( $assoc_args ) ) { WP_CLI::error( "Need some fields to update." ); @@ -156,4 +148,23 @@ public function update( $args, $assoc_args ) { WP_CLI::success( "Updated user $updated_id." ); } } + + private function get_numeric_arg_or_error( $args, $index, $name ) { + $value = self::get_arg_or_error( $args, $index, $name ); + if ( ! is_numeric( $value ) ) { + self::error_see_help( "$name must be numeric" ); + } + return $value; + } + + private function get_arg_or_error( $args, $index, $name ) { + if ( ! isset( $args[$index] ) ) { + self::error_see_help( "$name required" ); + } + return $args[$index]; + } + + private function error_see_help( $message ) { + WP_CLI::error( "$message (see 'wp user help')."); + } } diff --git a/src/php/wp-cli/wp-cli.php b/src/php/wp-cli/wp-cli.php index ed2a2da563..a34d4a9d3b 100755 --- a/src/php/wp-cli/wp-cli.php +++ b/src/php/wp-cli/wp-cli.php @@ -52,9 +52,6 @@ define( 'WP_ROOT', $_SERVER['PWD'] . '/' ); } -// Handle --url and --blog parameters -WP_CLI::_set_url( $assoc_args ); - if ( array( 'core', 'download' ) == $arguments ) { WP_CLI::run_command( $arguments, $assoc_args ); exit; @@ -88,6 +85,9 @@ define( 'WP_INSTALLING', true ); } +// Handle --url and --blog parameters +WP_CLI::_set_url( $assoc_args ); + // Load WordPress require WP_ROOT . 'wp-load.php'; require ABSPATH . 'wp-admin/includes/admin.php';