Skip to content

Commit

Permalink
Merge pull request #155 from JanVoracek/skip-email
Browse files Browse the repository at this point in the history
Optional --skip-email flag for 'wp user update'
  • Loading branch information
schlessera authored Jul 13, 2018
2 parents 9d3d891 + 7ef0ca7 commit 7b00064
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
38 changes: 38 additions & 0 deletions features/user.feature
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,41 @@ Feature: Manage WordPress users
Error: Only spammed 1 of 2 users.
"""
And the return code should be 1

@require-wp-4.3
Scenario: Sending emails on update
Given a WP install

When I run `wp user get 1 --field=user_email`
Then save STDOUT as {ORIGINAL_EMAIL}

When I run `wp user update 1 --user_email=different.mail@example.com`
Then STDOUT should contain:
"""
Success: Updated user 1.
"""
And an email should be sent

When I run `wp user update 1 --user_email={ORIGINAL_EMAIL} --skip-email`
Then STDOUT should contain:
"""
Success: Updated user 1.
"""
And an email should not be sent

When I run `wp user get 1 --field=user_pass`
Then save STDOUT as {ORIGINAL_PASSWORD}

When I run `wp user update 1 --user_pass=different_password`
Then STDOUT should contain:
"""
Success: Updated user 1.
"""
And an email should be sent

When I run `wp user update 1 --user_pass={ORIGINAL_PASSWORD} --skip-email`
Then STDOUT should contain:
"""
Success: Updated user 1.
"""
And an email should not be sent
14 changes: 14 additions & 0 deletions src/User_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@ public function create( $args, $assoc_args ) {
* --<field>=<value>
* : One or more fields to update. For accepted fields, see wp_update_user().
*
* [--skip-email]
* : Don't send an email notification to the user.
*
* ## EXAMPLES
*
* # Update user
Expand All @@ -495,8 +498,19 @@ public function update( $args, $assoc_args ) {
$user_ids[] = $user->ID;
}

$skip_email = Utils\get_flag_value( $assoc_args, 'skip-email' );
if ( $skip_email ) {
add_filter( 'send_email_change_email', '__return_false' );
add_filter( 'send_password_change_email', '__return_false' );
}

$assoc_args = wp_slash( $assoc_args );
parent::_update( $user_ids, $assoc_args, 'wp_update_user' );

if ( $skip_email ) {
remove_filter( 'send_email_change_email', '__return_false' );
remove_filter( 'send_password_change_email', '__return_false' );
}
}

/**
Expand Down

0 comments on commit 7b00064

Please sign in to comment.