Skip to content

Commit 7522d44

Browse files
Copilotswissspidy
andauthored
Normalize user update/create editor preference flags
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent a503fbe commit 7522d44

2 files changed

Lines changed: 71 additions & 5 deletions

File tree

‎features/user.feature‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,3 +919,56 @@ Feature: Manage WordPress users
919919
"""
920920
false
921921
"""
922+
923+
Scenario: The rich editing preference is normalized when updating a user
924+
Given a WP install
925+
926+
When I run `wp user create frank frank@example.com --porcelain`
927+
Then STDOUT should be a number
928+
And save STDOUT as {USER_ID}
929+
930+
When I run `wp user update {USER_ID} --rich_editing=0`
931+
Then STDOUT should contain:
932+
"""
933+
Success: Updated user {USER_ID}.
934+
"""
935+
936+
When I run `wp user meta get {USER_ID} rich_editing`
937+
Then STDOUT should be:
938+
"""
939+
false
940+
"""
941+
942+
Scenario: The syntax highlighting preference is stored as the value core checks for
943+
Given a WP install
944+
945+
# wp_get_user_editor() compares the stored meta against the string 'false',
946+
# so other spellings of a boolean have to be normalised.
947+
When I run `wp user create sasha sasha@example.com --syntax_highlighting=0 --porcelain`
948+
Then STDOUT should be a number
949+
And save STDOUT as {USER_ID}
950+
951+
When I run `wp user meta get {USER_ID} syntax_highlighting`
952+
Then STDOUT should be:
953+
"""
954+
false
955+
"""
956+
957+
Scenario: The syntax highlighting preference is normalized when updating a user
958+
Given a WP install
959+
960+
When I run `wp user create steve steve@example.com --porcelain`
961+
Then STDOUT should be a number
962+
And save STDOUT as {USER_ID}
963+
964+
When I run `wp user update {USER_ID} --syntax_highlighting=0`
965+
Then STDOUT should contain:
966+
"""
967+
Success: Updated user {USER_ID}.
968+
"""
969+
970+
When I run `wp user meta get {USER_ID} syntax_highlighting`
971+
Then STDOUT should be:
972+
"""
973+
false
974+
"""

‎src/User_Command.php‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,11 @@ function ( $user ) use ( $network, $reassign ) {
385385
* or their numeric forms 1 and 0.
386386
* Default: true
387387
*
388+
* [--syntax_highlighting=<syntax_highlighting>]
389+
* : Whether to enable the rich code editor for the user. Accepts 'true' or 'false',
390+
* or their numeric forms 1 and 0.
391+
* Default: true
392+
*
388393
* [--send-email]
389394
* : Send an email to the user with their new account details.
390395
*
@@ -403,7 +408,7 @@ function ( $user ) use ( $network, $reassign ) {
403408
* 4
404409
*
405410
* @param array{0: string, 1: string} $args Positional arguments.
406-
* @param array{role?: string, user_pass?: string, user_registered?: string, display_name?: string, user_nicename?: string, user_url?: string, nickname?: string, first_name?: string, last_name?: string, description?: string, rich_editing?: string, send_email?: bool, porcelain?: bool} $assoc_args Associative arguments.
411+
* @param array{role?: string, user_pass?: string, user_registered?: string, display_name?: string, user_nicename?: string, user_url?: string, nickname?: string, first_name?: string, last_name?: string, description?: string, rich_editing?: string, syntax_highlighting?: string, send_email?: bool, porcelain?: bool} $assoc_args Associative arguments.
407412
*/
408413
public function create( $args, $assoc_args ) {
409414
$user = new stdClass();
@@ -445,6 +450,9 @@ public function create( $args, $assoc_args ) {
445450
$rich_editing = Utils\get_flag_value( $assoc_args, 'rich_editing', true );
446451
$user->rich_editing = filter_var( $rich_editing, FILTER_VALIDATE_BOOLEAN ) ? 'true' : 'false';
447452

453+
$syntax_highlighting = Utils\get_flag_value( $assoc_args, 'syntax_highlighting', true );
454+
$user->syntax_highlighting = filter_var( $syntax_highlighting, FILTER_VALIDATE_BOOLEAN ) ? 'true' : 'false';
455+
448456
if ( isset( $assoc_args['user_pass'] ) ) {
449457
$user->user_pass = $assoc_args['user_pass'];
450458
} else {
@@ -544,12 +552,12 @@ public function create( $args, $assoc_args ) {
544552
* : A string containing content about the user.
545553
*
546554
* [--rich_editing=<rich_editing>]
547-
* : Whether to enable the rich editor for the user. Accepts 'true' or
548-
* 'false' as a string literal, not boolean.
555+
* : Whether to enable the rich editor for the user. Accepts 'true' or 'false',
556+
* or their numeric forms 1 and 0.
549557
*
550558
* [--syntax_highlighting=<syntax_highlighting>]
551-
* : Whether to enable the rich code editor for the user. Accepts 'true' or
552-
* 'false' as a string literal, not boolean.
559+
* : Whether to enable the rich code editor for the user. Accepts 'true' or 'false',
560+
* or their numeric forms 1 and 0.
553561
*
554562
* [--comment_shortcuts=<comment_shortcuts>]
555563
* : Whether to enable comment moderation keyboard shortcuts for the user.
@@ -624,6 +632,11 @@ public function update( $args, $assoc_args ) {
624632
}
625633

626634
$assoc_args = Utils\parse_shell_arrays( $assoc_args, [ 'meta_input' ] );
635+
foreach ( [ 'rich_editing', 'syntax_highlighting' ] as $preference ) {
636+
if ( isset( $assoc_args[ $preference ] ) ) {
637+
$assoc_args[ $preference ] = filter_var( $assoc_args[ $preference ], FILTER_VALIDATE_BOOLEAN ) ? 'true' : 'false';
638+
}
639+
}
627640

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

0 commit comments

Comments
 (0)