@@ -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 ();
@@ -443,7 +448,10 @@ public function create( $args, $assoc_args ) {
443448 // Core compares the stored value against the string 'true', so any other
444449 // truthy spelling would disable the editor.
445450 $ rich_editing = Utils \get_flag_value ( $ assoc_args , 'rich_editing ' , true );
446- $ user ->rich_editing = filter_var ( $ rich_editing , FILTER_VALIDATE_BOOLEAN ) ? 'true ' : 'false ' ;
451+ $ user ->rich_editing = self ::normalize_boolean_preference ( 'rich_editing ' , $ rich_editing );
452+
453+ $ syntax_highlighting = Utils \get_flag_value ( $ assoc_args , 'syntax_highlighting ' , true );
454+ $ user ->syntax_highlighting = self ::normalize_boolean_preference ( 'syntax_highlighting ' , $ syntax_highlighting );
447455
448456 if ( isset ( $ assoc_args ['user_pass ' ] ) ) {
449457 $ user ->user_pass = $ assoc_args ['user_pass ' ];
@@ -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.
@@ -608,6 +616,12 @@ public function update( $args, $assoc_args ) {
608616 self ::validate_role ( $ assoc_args ['role ' ], true );
609617 }
610618
619+ foreach ( [ 'rich_editing ' , 'syntax_highlighting ' ] as $ preference ) {
620+ if ( isset ( $ assoc_args [ $ preference ] ) ) {
621+ $ assoc_args [ $ preference ] = self ::normalize_boolean_preference ( $ preference , $ assoc_args [ $ preference ] );
622+ }
623+ }
624+
611625 $ user_ids = [];
612626 foreach ( $ this ->fetcher ->get_many ( $ args ) as $ user ) {
613627 $ user_ids [] = $ user ->ID ;
@@ -1413,6 +1427,23 @@ public function reset_password( $args, $assoc_args ) {
14131427 }
14141428 }
14151429
1430+ /**
1431+ * Normalizes a user preference to the string literal core checks for.
1432+ *
1433+ * @param string $preference Name of the preference, used for error reporting.
1434+ * @param mixed $value Value the preference was given on the command line.
1435+ * @return string Either 'true' or 'false'.
1436+ */
1437+ private static function normalize_boolean_preference ( $ preference , $ value ) {
1438+ $ normalized = filter_var ( $ value , FILTER_VALIDATE_BOOLEAN , FILTER_NULL_ON_FAILURE );
1439+
1440+ if ( null === $ normalized ) {
1441+ WP_CLI ::error ( "Invalid value for -- {$ preference }. Accepts 'true' or 'false', or their numeric forms 1 and 0. " );
1442+ }
1443+
1444+ return $ normalized ? 'true ' : 'false ' ;
1445+ }
1446+
14161447 /**
14171448 * Checks whether the role is valid
14181449 *
0 commit comments