Skip to content

Commit 51e8a79

Browse files
swissspidyclaude
andcommitted
Normalise --rich_editing to the strings core compares against
wp_insert_user() stores the raw value and user_can_richedit() checks it with `=== 'true'`, so `--rich_editing=1` disabled the editor. Map the flag to 'true' or 'false' and document the accepted values for both `user create` and `user update`. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QWUCg3yvcZ4uDBf2cwQ7X1
1 parent b022cfa commit 51e8a79

3 files changed

Lines changed: 37 additions & 5 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8422,7 +8422,8 @@ wp user create <user-login> <user-email> [--role=<role>] [--user_pass=<password>
84228422
A string containing content about the user.
84238423

84248424
[--rich_editing=<rich_editing>]
8425-
A string for whether to enable the rich editor or not. False if not empty.
8425+
Whether to enable the rich editor for the user. Accepts 'true' or 'false'.
8426+
Default: true
84268427

84278428
[--send-email]
84288429
Send an email to the user with their new account details.
@@ -10089,7 +10090,8 @@ wp user update <user>... [--user_pass=<password>] [--user_nicename=<nice_name>]
1008910090
A string containing content about the user.
1009010091

1009110092
[--rich_editing=<rich_editing>]
10092-
A string for whether to enable the rich editor or not. False if not empty.
10093+
Whether to enable the rich editor for the user. Accepts 'true' or
10094+
'false' as a string literal, not boolean.
1009310095

1009410096
[--syntax_highlighting=<syntax_highlighting>]
1009510097
Whether to enable the rich code editor for the user. Accepts 'true' or

‎features/user.feature‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,3 +894,28 @@ Feature: Manage WordPress users
894894
"""
895895
true
896896
"""
897+
898+
Scenario: The rich editing preference is stored as the value core checks for
899+
Given a WP install
900+
901+
# user_can_richedit() compares the stored meta against the string 'true',
902+
# so other spellings of a boolean have to be normalised.
903+
When I run `wp user create dave dave@example.com --rich_editing=1 --porcelain`
904+
Then STDOUT should be a number
905+
And save STDOUT as {USER_ID}
906+
907+
When I run `wp user meta get {USER_ID} rich_editing`
908+
Then STDOUT should be:
909+
"""
910+
true
911+
"""
912+
913+
When I run `wp user create erin erin@example.com --rich_editing=0 --porcelain`
914+
Then STDOUT should be a number
915+
And save STDOUT as {USER_ID}
916+
917+
When I run `wp user meta get {USER_ID} rich_editing`
918+
Then STDOUT should be:
919+
"""
920+
false
921+
"""

‎src/User_Command.php‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ function ( $user ) use ( $network, $reassign ) {
381381
* : A string containing content about the user.
382382
*
383383
* [--rich_editing=<rich_editing>]
384-
* : A string for whether to enable the rich editor or not. False if not empty.
384+
* : Whether to enable the rich editor for the user. Accepts 'true' or 'false'.
385+
* Default: true
385386
*
386387
* [--send-email]
387388
* : Send an email to the user with their new account details.
@@ -438,7 +439,10 @@ public function create( $args, $assoc_args ) {
438439

439440
$user->user_nicename = Utils\get_flag_value( $assoc_args, 'user_nicename', false );
440441

441-
$user->rich_editing = Utils\get_flag_value( $assoc_args, 'rich_editing', false );
442+
// Core compares the stored value against the string 'true', so any other
443+
// truthy spelling would disable the editor.
444+
$rich_editing = Utils\get_flag_value( $assoc_args, 'rich_editing', true );
445+
$user->rich_editing = filter_var( $rich_editing, FILTER_VALIDATE_BOOLEAN ) ? 'true' : 'false';
442446

443447
if ( isset( $assoc_args['user_pass'] ) ) {
444448
$user->user_pass = $assoc_args['user_pass'];
@@ -539,7 +543,8 @@ public function create( $args, $assoc_args ) {
539543
* : A string containing content about the user.
540544
*
541545
* [--rich_editing=<rich_editing>]
542-
* : A string for whether to enable the rich editor or not. False if not empty.
546+
* : Whether to enable the rich editor for the user. Accepts 'true' or
547+
* 'false' as a string literal, not boolean.
543548
*
544549
* [--syntax_highlighting=<syntax_highlighting>]
545550
* : Whether to enable the rich code editor for the user. Accepts 'true' or

0 commit comments

Comments
 (0)