Skip to content
Open
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
62 changes: 62 additions & 0 deletions src/User_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,47 @@
*/
class User_Command extends CommandWithDBObject {

/**
* Known user fields accepted by wp_update_user().
*
* @var array
*/
const KNOWN_USER_FIELDS = [
'user_pass',
'user_nicename',
'user_url',
'user_email',
'display_name',
'nickname',
'first_name',
'last_name',
'description',
'rich_editing',
'syntax_highlighting',
'comment_shortcuts',
'admin_color',
'use_ssl',
'show_admin_bar_front',
'user_registered',
'locale',
'role',
'meta_input',
];
Comment on lines +45 to +65

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

rg -n "'(user_activation_key|spam)'" src/User_Command.php
curl -fsSL https://developer.wordpress.org/reference/functions/wp_insert_user/ | grep -E "user_activation_key|spam"

Repository: wp-cli/entity-command

Length of output: 4577


🏁 Script executed:

sed -n '1,140p' src/User_Command.php

Repository: wp-cli/entity-command

Length of output: 3220


🏁 Script executed:

rg -n "KNOWN_USER_FIELDS|KNOWN_USER_FLAGS|suggest|close-match|user_activation_key|spam" src/User_Command.php

Repository: wp-cli/entity-command

Length of output: 1593


🏁 Script executed:

sed -n '620,650p' src/User_Command.php

Repository: wp-cli/entity-command

Length of output: 1060


Keep KNOWN_USER_FIELDS aligned with WordPress.

user_activation_key and spam are valid wp_update_user() fields, but they’re missing from this whitelist. That means --user_activation_key and --spam can be treated as unknown instead of passing through cleanly.

Suggested fix
 		'user_registered',
+		'user_activation_key',
+		'spam',
 		'locale',
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const KNOWN_USER_FIELDS = [
'user_pass',
'user_nicename',
'user_url',
'user_email',
'display_name',
'nickname',
'first_name',
'last_name',
'description',
'rich_editing',
'syntax_highlighting',
'comment_shortcuts',
'admin_color',
'use_ssl',
'show_admin_bar_front',
'user_registered',
'locale',
'role',
'meta_input',
];
const KNOWN_USER_FIELDS = [
'user_pass',
'user_nicename',
'user_url',
'user_email',
'display_name',
'nickname',
'first_name',
'last_name',
'description',
'rich_editing',
'syntax_highlighting',
'comment_shortcuts',
'admin_color',
'use_ssl',
'show_admin_bar_front',
'user_registered',
'user_activation_key',
'spam',
'locale',
'role',
'meta_input',
];
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/User_Command.php` around lines 45 - 65, Update the KNOWN_USER_FIELDS
whitelist to include the valid WordPress user fields user_activation_key and
spam, preserving the existing field entries and ordering style.


/**
* Command flags that are not user fields.
*
* @var array
*/
const COMMAND_FLAGS = [
'skip-email',
'defer-term-counting',
'porcelain',
'format',
'fields',
'user_login',
];

protected $obj_type = 'user';
protected $obj_fields = [
'ID',
Expand Down Expand Up @@ -584,6 +625,27 @@ public function update( $args, $assoc_args ) {
add_filter( 'send_password_change_email', '__return_false' );
}

// Check for potentially misspelled parameters.
foreach ( $assoc_args as $key => $value ) {
if ( in_array( $key, self::COMMAND_FLAGS, true ) ) {
continue;
}
if ( in_array( $key, self::KNOWN_USER_FIELDS, true ) ) {
continue;
}
$suggestion = Utils\get_suggestion( $key, self::KNOWN_USER_FIELDS );
if ( ! empty( $suggestion ) ) {
$assoc_args = array_diff_key( $assoc_args, [ $key => $value ] );
WP_CLI::warning(
sprintf(
"unknown --%s parameter (did you mean '--%s'?)",
$key,
$suggestion
)
);
}
}

$assoc_args = wp_slash( $assoc_args );
parent::_update( $user_ids, $assoc_args, 'wp_update_user' );

Expand Down
Loading