From 2e39881ff7677d05736de6ecb8094f0854558105 Mon Sep 17 00:00:00 2001 From: karthick-murugan Date: Thu, 20 Mar 2025 20:33:46 +0530 Subject: [PATCH 1/3] User update command params checking --- src/User_Command.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/User_Command.php b/src/User_Command.php index bfc8382a..157e73a7 100644 --- a/src/User_Command.php +++ b/src/User_Command.php @@ -536,6 +536,49 @@ public function update( $args, $assoc_args ) { unset( $assoc_args['user_login'] ); } + // Define valid fields for wp_update_user(). + $valid_fields = array( + 'user_pass', + 'user_nicename', + 'user_url', + 'user_email', + 'display_name', + 'nickname', + 'first_name', + 'last_name', + 'description', + 'rich_editing', + 'user_registered', + 'role', + 'syntax_highlighting', + 'comment_shortcuts', + 'admin_color', + 'use_ssl', + 'show_admin_bar_front', + 'locale', + ); + + // Check for invalid field names. + $invalid_fields = array(); + foreach ( array_keys( $assoc_args ) as $field ) { + // Skip special flags like 'skip-email'. + if ( 'skip-email' === $field ) { + continue; + } + + if ( ! in_array( $field, $valid_fields, true ) ) { + $invalid_fields[] = $field; + } + } + + // Warn about invalid fields. + if ( ! empty( $invalid_fields ) ) { + foreach ( $invalid_fields as $field ) { + WP_CLI::warning( "Unknown --{$field} parameter." ); + unset( $assoc_args[ $field ] ); + } + } + if ( isset( $assoc_args['role'] ) ) { self::validate_role( $assoc_args['role'], true ); } From 246e6c60c903aa9ab04d1eb3b7da276c8b8053af Mon Sep 17 00:00:00 2001 From: karthick-murugan Date: Fri, 21 Mar 2025 11:29:47 +0530 Subject: [PATCH 2/3] Feedback Updates --- features/user.feature | 18 +++++++++++++++++ src/User_Command.php | 46 ------------------------------------------- 2 files changed, 18 insertions(+), 46 deletions(-) diff --git a/features/user.feature b/features/user.feature index 2d315d45..7e78c2e1 100644 --- a/features/user.feature +++ b/features/user.feature @@ -376,6 +376,24 @@ Feature: Manage WordPress users administrator """ + And a user exists with login 9999 + + When I run `wp user update 9999 --user-pass=admin` + Then STDERR should contain: + """ + Error: Parameter errors: + unknown --user-pass parameter + Did you mean '--user_pass'? + """ + + And a user exists with login 9999 + + When I run `wp user update 9999 --user_pass=admin` + Then STDOUT should contain: + """ + Success: Updated user 9999. + """ + Scenario: Managing user capabilities Given a WP install diff --git a/src/User_Command.php b/src/User_Command.php index 157e73a7..146f461e 100644 --- a/src/User_Command.php +++ b/src/User_Command.php @@ -518,9 +518,6 @@ public function create( $args, $assoc_args ) { * [--role=] * : A string used to set the user's role. * - * --= - * : One or more fields to update. For accepted fields, see wp_update_user(). - * * [--skip-email] * : Don't send an email notification to the user. * @@ -536,49 +533,6 @@ public function update( $args, $assoc_args ) { unset( $assoc_args['user_login'] ); } - // Define valid fields for wp_update_user(). - $valid_fields = array( - 'user_pass', - 'user_nicename', - 'user_url', - 'user_email', - 'display_name', - 'nickname', - 'first_name', - 'last_name', - 'description', - 'rich_editing', - 'user_registered', - 'role', - 'syntax_highlighting', - 'comment_shortcuts', - 'admin_color', - 'use_ssl', - 'show_admin_bar_front', - 'locale', - ); - - // Check for invalid field names. - $invalid_fields = array(); - foreach ( array_keys( $assoc_args ) as $field ) { - // Skip special flags like 'skip-email'. - if ( 'skip-email' === $field ) { - continue; - } - - if ( ! in_array( $field, $valid_fields, true ) ) { - $invalid_fields[] = $field; - } - } - - // Warn about invalid fields. - if ( ! empty( $invalid_fields ) ) { - foreach ( $invalid_fields as $field ) { - WP_CLI::warning( "Unknown --{$field} parameter." ); - unset( $assoc_args[ $field ] ); - } - } - if ( isset( $assoc_args['role'] ) ) { self::validate_role( $assoc_args['role'], true ); } From 30188649b3ba0c86c88068f02157bf02465baad6 Mon Sep 17 00:00:00 2001 From: karthick-murugan Date: Fri, 21 Mar 2025 16:42:46 +0530 Subject: [PATCH 3/3] Updated feedback --- features/user.feature | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/features/user.feature b/features/user.feature index 7e78c2e1..8e2897b9 100644 --- a/features/user.feature +++ b/features/user.feature @@ -376,22 +376,10 @@ Feature: Manage WordPress users administrator """ - And a user exists with login 9999 - - When I run `wp user update 9999 --user-pass=admin` - Then STDERR should contain: - """ - Error: Parameter errors: - unknown --user-pass parameter - Did you mean '--user_pass'? - """ - - And a user exists with login 9999 - - When I run `wp user update 9999 --user_pass=admin` + When I run `wp user update 1 --user_pass=new_password` Then STDOUT should contain: """ - Success: Updated user 9999. + Success: Updated user 1. """ Scenario: Managing user capabilities