Skip to content

Commit

Permalink
Use simpler approach to strip error message HTML tags
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Feb 21, 2024
1 parent cb745de commit 6622f87
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 2 additions & 4 deletions features/user.feature
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,8 @@ Feature: Manage WordPress users
"""

When I try `wp user create bobjones1 bobjones@example.com`
Then STDERR should contain:
"""
Error: This email address is already registered.
"""
Then STDERR should not be empty
And the return code should be 1

Scenario: Managing user roles
Given a WP install
Expand Down
6 changes: 2 additions & 4 deletions src/User_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,8 @@ public function create( $args, $assoc_args ) {
$result = wpmu_validate_user_signup( $user->user_login, $user->user_email );
if ( is_wp_error( $result['errors'] ) && ! empty( $result['errors']->errors ) ) {
$message = $result['errors']->get_error_message();
if ( false !== stripos( $message, '</strong>' ) ) {
$exploded = explode( '</strong>', $message );
$message = trim( wp_strip_all_tags( $exploded[1] ) );
}
$message = trim( wp_strip_all_tags( $message ) );
$message = str_replace( 'Error: ', '', $message );
WP_CLI::error( $message );
}
$user_id = wpmu_create_user( $user->user_login, $user->user_pass, $user->user_email );
Expand Down

0 comments on commit 6622f87

Please sign in to comment.