Skip to content

Commit 2a6f897

Browse files
Copilotswissspidy
andcommitted
Fix: strip HTML tags from multisite user signup validation errors
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent fafabad commit 2a6f897

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

features/user.feature

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,23 @@ Feature: Manage WordPress users
267267
Bob Jones
268268
"""
269269
270+
Scenario: Creating a user with an existing email in multisite shows a clean error message
271+
Given a WP multisite install
272+
273+
When I run `wp user create bobjones bobjones@example.com`
274+
Then STDOUT should not be empty
275+
276+
When I try `wp user create bobjones2 bobjones@example.com`
277+
Then STDERR should contain:
278+
"""
279+
This email address is already registered.
280+
"""
281+
And STDERR should not contain:
282+
"""
283+
<
284+
"""
285+
And the return code should be 1
286+
270287
Scenario: Managing user roles
271288
Given a WP install
272289

src/User_Command.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,8 @@ public function create( $args, $assoc_args ) {
460460
if ( is_multisite() ) {
461461
$result = wpmu_validate_user_signup( $user->user_login, $user->user_email );
462462
if ( ! empty( $result['errors']->errors ) ) {
463-
WP_CLI::error( $result['errors'] );
463+
$error_message = implode( ' ', array_map( 'wp_strip_all_tags', $result['errors']->get_error_messages() ) );
464+
WP_CLI::error( $error_message );
464465
}
465466
$user_id = wpmu_create_user( $user->user_login, $user->user_pass, $user->user_email );
466467
if ( ! $user_id ) {
@@ -1228,7 +1229,7 @@ public function import_csv( $args, $assoc_args ) {
12281229
if ( is_multisite() ) {
12291230
$result = wpmu_validate_user_signup( $new_user['user_login'], $new_user['user_email'] );
12301231
if ( ! empty( $result['errors']->errors ) ) {
1231-
WP_CLI::warning( $result['errors'] );
1232+
WP_CLI::warning( implode( ' ', array_map( 'wp_strip_all_tags', $result['errors']->get_error_messages() ) ) );
12321233
continue;
12331234
}
12341235
$user_id = wpmu_create_user( $new_user['user_login'], $new_user['user_pass'], $new_user['user_email'] );

0 commit comments

Comments
 (0)