Make WordPress Core

Ticket #39697: 39697-concept.patch

File 39697-concept.patch, 2.1 KB (added by keraweb, 6 years ago)

Concept addition to wp_update_user() to allow disabling emails through parameters

  • wp-includes/user.php

     
    18701870 * cleared.
    18711871 *
    18721872 * @since 2.0.0
     1873 * @since 5.x.x Added $args parameter.
    18731874 *
    18741875 * @see wp_insert_user() For what fields can be set in $userdata.
    18751876 *
    18761877 * @param array|object|WP_User $userdata An array of user data or a user object of type stdClass or WP_User.
     1878 * @param array $args {
     1879 *     An array of arguments.
     1880 *
     1881 *     @type bool $send_password_change_email Send email if password is changed?
     1882 *     @type bool $send_email_change_email    Send email if email is changed?
     1883 * }
    18771884 * @return int|WP_Error The updated user's ID or a WP_Error object if the user could not be updated.
    18781885 */
    18791886function wp_update_user( $userdata ) {
     
    18831890                $userdata = $userdata->to_array();
    18841891        }
    18851892
     1893        $defaults = array(
     1894                'send_password_change_email' => true,
     1895                'send_email_change_email'    => true,
     1896        );
     1897
     1898        $args = wp_parse_args( $args, $defaults );
     1899
    18861900        $ID = isset( $userdata['ID'] ) ? (int) $userdata['ID'] : 0;
    18871901        if ( ! $ID ) {
    18881902                return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) );
     
    19201934                 * @param array $user     The original user array.
    19211935                 * @param array $userdata The updated user array.
    19221936                 */
    1923                 $send_password_change_email = apply_filters( 'send_password_change_email', true, $user, $userdata );
     1937                $send_password_change_email = apply_filters( 'send_password_change_email', (bool) $args['send_password_change_email'], $user, $userdata );
    19241938        }
    19251939
    19261940        if ( isset( $userdata['user_email'] ) && $user['user_email'] !== $userdata['user_email'] ) {
     
    19351949                 * @param array $user     The original user array.
    19361950                 * @param array $userdata The updated user array.
    19371951                 */
    1938                 $send_email_change_email = apply_filters( 'send_email_change_email', true, $user, $userdata );
     1952                $send_email_change_email = apply_filters( 'send_email_change_email', (bool) $args['send_email_change_email'], $user, $userdata );
    19391953        }
    19401954
    19411955        wp_cache_delete( $user['user_email'], 'useremail' );