Skip to content

Commit 2b7531a

Browse files
CopilotswissspidyCopilot
authored
Strip HTML tags from multisite user signup validation errors (#596)
* Initial plan * Fix: strip HTML tags from multisite user signup validation errors Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * Fix test * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 7c8d6d3 commit 2b7531a

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

features/user.feature

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,43 @@ Feature: Manage WordPress users
267267
Bob Jones
268268
"""
269269
270+
# The error message changed in WP 5.9.
271+
@less-than-wp-5.9
272+
Scenario: Creating a user with an existing email in multisite shows a clean error message
273+
Given a WP multisite install
274+
275+
When I run `wp user create bobjones bobjones@example.com`
276+
Then STDOUT should not be empty
277+
278+
When I try `wp user create bobjones2 bobjones@example.com`
279+
Then STDERR should contain:
280+
"""
281+
Sorry, that email address is already used!
282+
"""
283+
And STDERR should not contain:
284+
"""
285+
<
286+
"""
287+
And the return code should be 1
288+
289+
@require-wp-5.9
290+
Scenario: Creating a user with an existing email in multisite shows a clean error message
291+
Given a WP multisite install
292+
293+
When I run `wp user create bobjones bobjones@example.com`
294+
Then STDOUT should not be empty
295+
296+
When I try `wp user create bobjones2 bobjones@example.com`
297+
Then STDERR should contain:
298+
"""
299+
This email address is already registered.
300+
"""
301+
And STDERR should not contain:
302+
"""
303+
<
304+
"""
305+
And the return code should be 1
306+
270307
Scenario: Managing user roles
271308
Given a WP install
272309

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)