Make WordPress Core

Ticket #45747: 45747.2.diff

File 45747.2.diff, 8.5 KB (added by SergeyBiryukov, 6 years ago)
  • src/wp-admin/includes/ms.php

     
    304304}
    305305
    306306/**
    307  * Update the status of a user in the database.
    308  *
    309  * Used in core to mark a user as spam or "ham" (not spam) in Multisite.
    310  *
    311  * @since 3.0.0
    312  *
    313  * @global wpdb $wpdb WordPress database abstraction object.
    314  *
    315  * @param int    $id         The user ID.
    316  * @param string $pref       The column in the wp_users table to update the user's status
    317  *                           in (presumably user_status, spam, or deleted).
    318  * @param int    $value      The new status for the user.
    319  * @param null   $deprecated Deprecated as of 3.0.2 and should not be used.
    320  * @return int   The initially passed $value.
    321  */
    322 function update_user_status( $id, $pref, $value, $deprecated = null ) {
    323         global $wpdb;
    324 
    325         if ( null !== $deprecated ) {
    326                 _deprecated_argument( __FUNCTION__, '3.0.2' );
    327         }
    328 
    329         $wpdb->update( $wpdb->users, array( sanitize_key( $pref ) => $value ), array( 'ID' => $id ) );
    330 
    331         $user = new WP_User( $id );
    332         clean_user_cache( $user );
    333 
    334         if ( $pref == 'spam' ) {
    335                 if ( $value == 1 ) {
    336                         /**
    337                          * Fires after the user is marked as a SPAM user.
    338                          *
    339                          * @since 3.0.0
    340                          *
    341                          * @param int $id ID of the user marked as SPAM.
    342                          */
    343                         do_action( 'make_spam_user', $id );
    344                 } else {
    345                         /**
    346                          * Fires after the user is marked as a HAM user. Opposite of SPAM.
    347                          *
    348                          * @since 3.0.0
    349                          *
    350                          * @param int $id ID of the user marked as HAM.
    351                          */
    352                         do_action( 'make_ham_user', $id );
    353                 }
    354         }
    355 
    356         return $value;
    357 }
    358 
    359 /**
    360307 * Cleans the user cache for a specific user.
    361308 *
    362309 * @since 3.0.0
  • src/wp-admin/network/users.php

     
    7676
    7777                                                                $userfunction = 'all_spam';
    7878                                                                $blogs        = get_blogs_of_user( $user_id, true );
     79
    7980                                                                foreach ( (array) $blogs as $details ) {
    8081                                                                        if ( $details->userblog_id != get_network()->site_id ) { // main blog not a spam !
    8182                                                                                update_blog_status( $details->userblog_id, 'spam', '1' );
    8283                                                                        }
    8384                                                                }
    84                                                                 update_user_status( $user_id, 'spam', '1' );
     85
     86                                                                $user_data         = $user->to_array();
     87                                                                $user_data['spam'] = '1';
     88
     89                                                                wp_update_user( $user_data );
    8590                                                                break;
    8691
    8792                                                        case 'notspam':
     93                                                                $user = get_userdata( $user_id );
     94
    8895                                                                $userfunction = 'all_notspam';
    8996                                                                $blogs        = get_blogs_of_user( $user_id, true );
     97
    9098                                                                foreach ( (array) $blogs as $details ) {
    9199                                                                        update_blog_status( $details->userblog_id, 'spam', '0' );
    92100                                                                }
    93101
    94                                                                 update_user_status( $user_id, 'spam', '0' );
     102                                                                $user_data         = $user->to_array();
     103                                                                $user_data['spam'] = '0';
     104
     105                                                                wp_update_user( $user_data );
    95106                                                                break;
    96107                                                }
    97108                                        }
  • src/wp-includes/ms-deprecated.php

     
    685685
    686686        $wpdb->suppress_errors( $suppress );
    687687}
     688
     689/**
     690 * Update the status of a user in the database.
     691 *
     692 * Used in core to mark a user as spam or "ham" (not spam) in Multisite.
     693 *
     694 * @since 3.0.0
     695 * @deprecated 5.3.0
     696 *
     697 * @global wpdb $wpdb WordPress database abstraction object.
     698 *
     699 * @param int    $id         The user ID.
     700 * @param string $pref       The column in the wp_users table to update the user's status
     701 *                           in (presumably user_status, spam, or deleted).
     702 * @param int    $value      The new status for the user.
     703 * @param null   $deprecated Deprecated as of 3.0.2 and should not be used.
     704 * @return int   The initially passed $value.
     705 */
     706function update_user_status( $id, $pref, $value, $deprecated = null ) {
     707        global $wpdb;
     708
     709
     710        _deprecated_function( __FUNCTION__, '5.3.0', 'wp_update_user()' );
     711
     712        if ( null !== $deprecated ) {
     713                _deprecated_argument( __FUNCTION__, '3.0.2' );
     714        }
     715
     716        $wpdb->update( $wpdb->users, array( sanitize_key( $pref ) => $value ), array( 'ID' => $id ) );
     717
     718        $user = new WP_User( $id );
     719        clean_user_cache( $user );
     720
     721        if ( $pref == 'spam' ) {
     722                if ( $value == 1 ) {
     723                        /** This filter is documented in wp-includes/user.php */
     724                        do_action( 'make_spam_user', $id );
     725                } else {
     726                        /** This filter is documented in wp-includes/user.php */
     727                        do_action( 'make_ham_user', $id );
     728                }
     729        }
     730
     731        return $value;
     732}
  • src/wp-includes/user.php

     
    14681468 *
    14691469 * Most of the `$userdata` array fields have filters associated with the values. Exceptions are
    14701470 * 'ID', 'rich_editing', 'syntax_highlighting', 'comment_shortcuts', 'admin_color', 'use_ssl',
    1471  * 'user_registered', and 'role'. The filters have the prefix 'pre_user_' followed by the field
    1472  * name. An example using 'description' would have the filter called, 'pre_user_description' that
    1473  * can be hooked into.
     1471 * 'user_registered', 'spam', and 'role'. The filters have the prefix 'pre_user_' followed by the
     1472 * field name. An example using 'description' would have the filter called, 'pre_user_description'
     1473 * that can be hooked into.
    14741474 *
    14751475 * @since 2.0.0
    14761476 * @since 3.6.0 The `aim`, `jabber`, and `yim` fields were removed as default user contact
    14771477 *              methods for new installations. See wp_get_user_contact_methods().
    14781478 * @since 4.7.0 The user's locale can be passed to `$userdata`.
     1479 * @since 5.3.0 The `spam` field can be passed to `$userdata` (Multisite only).
    14791480 *
    14801481 * @global wpdb $wpdb WordPress database abstraction object.
    14811482 *
     
    15091510 *     @type bool        $use_ssl              Whether the user should always access the admin over
    15101511 *                                             https. Default false.
    15111512 *     @type string      $user_registered      Date the user registered. Format is 'Y-m-d H:i:s'.
     1513 *     @type bool        $spam                 Multisite only. Whether the user is marked as spam.
     1514 *                                             Default false.
    15121515 *     @type string|bool $show_admin_bar_front Whether to display the Admin Bar for the user on the
    15131516 *                                             site's front end. Default true.
    15141517 *     @type string      $role                 User's role.
     
    16441647        ) {
    16451648                return new WP_Error( 'existing_user_email', __( 'Sorry, that email address is already used!' ) );
    16461649        }
     1650
     1651        if ( isset( $userdata['spam'] ) && ! is_multisite() ) {
     1652                return new WP_Error( 'no_spam', __( 'Sorry, marking a user as spam is only supported on Multisite.' ) );
     1653        }
     1654
     1655        $spam = empty( $userdata['spam'] ) ? 0 : (bool) $userdata['spam'];
     1656
    16471657        $nickname = empty( $userdata['nickname'] ) ? $user_login : $userdata['nickname'];
    16481658
    16491659        /**
     
    17231733        $admin_color         = empty( $userdata['admin_color'] ) ? 'fresh' : $userdata['admin_color'];
    17241734        $meta['admin_color'] = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $admin_color );
    17251735
    1726         $meta['use_ssl'] = empty( $userdata['use_ssl'] ) ? 0 : $userdata['use_ssl'];
     1736        $meta['use_ssl'] = empty( $userdata['use_ssl'] ) ? 0 : (bool) $userdata['use_ssl'];
    17271737
    17281738        $user_registered = empty( $userdata['user_registered'] ) ? gmdate( 'Y-m-d H:i:s' ) : $userdata['user_registered'];
    17291739
     
    17521762                $data = $data + compact( 'user_login' );
    17531763        }
    17541764
     1765        if ( is_multisite() ) {
     1766                $data = $data + compact( 'spam' );
     1767        }
     1768
    17551769        /**
    17561770         * Filters user data before the record is created or updated.
    17571771         *
     
    18481862                 * @param WP_User $old_user_data Object containing user's data prior to update.
    18491863                 */
    18501864                do_action( 'profile_update', $user_id, $old_user_data );
     1865
     1866                if ( isset( $userdata['spam'] ) && $userdata['spam'] != $old_user_data->spam ) {
     1867                        if ( $userdata['spam'] == 1 ) {
     1868                                /**
     1869                                 * Fires after the user is marked as a SPAM user.
     1870                                 *
     1871                                 * @since 3.0.0
     1872                                 *
     1873                                 * @param int $user_id ID of the user marked as SPAM.
     1874                                 */
     1875                                do_action( 'make_spam_user', $user_id );
     1876                        } else {
     1877                                /**
     1878                                 * Fires after the user is marked as a HAM user. Opposite of SPAM.
     1879                                 *
     1880                                 * @since 3.0.0
     1881                                 *
     1882                                 * @param int $user_id ID of the user marked as HAM.
     1883                                 */
     1884                                do_action( 'make_ham_user', $user_id );
     1885                        }
     1886                }
    18511887        } else {
    18521888                /**
    18531889                 * Fires immediately after a new user is registered.