WordPress.org

Make WordPress Core

Ticket #38741: 38741.11.diff

File 38741.11.diff, 16.9 KB (added by macbookandrew, 2 years ago)

patch file for 5.2.1

  • wp-admin/includes/class-wp-ms-users-list-table.php

    diff --git a/wp-admin/includes/class-wp-ms-users-list-table.php b/wp-admin/includes/class-wp-ms-users-list-table.php
    index e3d619ae8..53b924f67 100644
    a b class WP_MS_Users_List_Table extends WP_List_Table { 
    131131        protected function get_views() {
    132132                global $role;
    133133
    134                 $total_users  = get_user_count();
     134                $total_users  = wp_get_user_count();
    135135                $super_admins = get_super_admins();
    136136                $total_admins = count( $super_admins );
    137137
  • wp-admin/includes/class-wp-posts-list-table.php

    diff --git a/wp-admin/includes/class-wp-posts-list-table.php b/wp-admin/includes/class-wp-posts-list-table.php
    index 717e84fb9..959e157b9 100644
    a b class WP_Posts_List_Table extends WP_List_Table { 
    15571557                                <?php
    15581558        endif; // $bulk
    15591559
    1560                         if ( post_type_supports( $screen->post_type, 'author' ) ) :
     1560                        if ( post_type_supports( $screen->post_type, 'author' ) && ! wp_is_large_user_count() ) :
    15611561                                $authors_dropdown = '';
    15621562
    15631563                                if ( current_user_can( $post_type_object->cap->edit_others_posts ) ) :
  • wp-admin/includes/class-wp-users-list-table.php

    diff --git a/wp-admin/includes/class-wp-users-list-table.php b/wp-admin/includes/class-wp-users-list-table.php
    index 28e197872..16889e8f6 100644
    a b class WP_Users_List_Table extends WP_List_Table { 
    177177
    178178                $wp_roles = wp_roles();
    179179
     180                $count_users = ! wp_is_large_user_count();
     181
    180182                if ( $this->is_site_users ) {
    181183                        $url = 'site-users.php?id=' . $this->site_id;
    182                         switch_to_blog( $this->site_id );
    183                         $users_of_blog = count_users( 'time', $this->site_id );
    184                         restore_current_blog();
    185184                } else {
    186                         $url           = 'users.php';
    187                         $users_of_blog = count_users();
     185                        $url = 'users.php';
    188186                }
    189187
    190                 $total_users = $users_of_blog['total_users'];
    191                 $avail_roles =& $users_of_blog['avail_roles'];
    192                 unset( $users_of_blog );
     188                $role_links = array();
     189                if ( $count_users ) {
     190                        if ( $this->is_site_users ) {
     191                                switch_to_blog( $this->site_id );
     192                                $users_of_blog = count_users( 'time', $this->site_id );
     193                                restore_current_blog();
     194                        } else {
     195                                $users_of_blog = count_users();
     196                        }
     197
     198                        $total_users = $users_of_blog['total_users'];
     199                        $avail_roles =& $users_of_blog['avail_roles'];
     200                        unset( $users_of_blog );
     201                        $role_links['all'] = "<a href='$url'$current_link_attributes>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>';
     202                } else {
     203                        $avail_roles       = array();
     204                        $role_links['all'] = "<a href='$url'$current_link_attributes>" . __( 'All' ) . '</a>';
     205                }
    193206
    194207                $current_link_attributes = empty( $role ) ? ' class="current" aria-current="page"' : '';
    195208
    196                 $role_links        = array();
    197                 $role_links['all'] = "<a href='$url'$current_link_attributes>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>';
    198209                foreach ( $wp_roles->get_names() as $this_role => $name ) {
    199                         if ( ! isset( $avail_roles[ $this_role ] ) ) {
     210                        if ( $count_users && ! isset( $avail_roles[ $this_role ] ) ) {
    200211                                continue;
    201212                        }
    202213
    class WP_Users_List_Table extends WP_List_Table { 
    207218                        }
    208219
    209220                        $name = translate_user_role( $name );
    210                         /* translators: User role name with count */
    211                         $name                     = sprintf( __( '%1$s <span class="count">(%2$s)</span>' ), $name, number_format_i18n( $avail_roles[ $this_role ] ) );
     221                        if ( $count_users ) {
     222                                /* translators: User role name with count */
     223                            $name = sprintf( __( '%1$s <span class="count">(%2$s)</span>' ), $name, number_format_i18n( $avail_roles[ $this_role ] ) );
     224                        }
    212225                        $role_links[ $this_role ] = "<a href='" . esc_url( add_query_arg( 'role', $this_role, $url ) ) . "'$current_link_attributes>$name</a>";
    213226                }
    214227
  • wp-admin/includes/dashboard.php

    diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php
    index e3160bb39..efefc34c9 100644
    a b function wp_network_dashboard_right_now() { 
    406406                $actions['create-user'] = '<a href="' . network_admin_url( 'user-new.php' ) . '">' . __( 'Create a New User' ) . '</a>';
    407407        }
    408408
    409         $c_users = get_user_count();
     409        $c_users = wp_get_user_count();
    410410        $c_blogs = get_blog_count();
    411411
    412412        /* translators: %s: number of users on the network */
  • wp-admin/includes/schema.php

    diff --git a/wp-admin/includes/schema.php b/wp-admin/includes/schema.php
    index 20853da3e..fc55bc846 100644
    a b We hope you enjoy your new site. Thanks! 
    12481248                'subdomain_install'           => $subdomain_install,
    12491249                'global_terms_enabled'        => global_terms_enabled() ? '1' : '0',
    12501250                'ms_files_rewriting'          => is_multisite() ? get_site_option( 'ms_files_rewriting' ) : '0',
     1251                'user_count'                  => get_site_option( 'user_count' ),
    12511252                'initial_db_version'          => get_option( 'initial_db_version' ),
    12521253                'active_sitewide_plugins'     => array(),
    12531254                'WPLANG'                      => get_locale(),
  • wp-includes/default-filters.php

    diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php
    index ecdc87cb3..afd9a6954 100644
    a b add_filter( 'post_mime_type', 'sanitize_mime_type' ); 
    9898// Meta
    9999add_filter( 'register_meta_args', '_wp_register_meta_args_whitelist', 10, 2 );
    100100
     101// Counts
     102add_action( 'admin_init', 'wp_schedule_update_network_counts' );
     103add_action( 'update_network_counts', 'wp_update_network_user_counts', 10, 0 );
     104foreach ( array( 'user_register', 'deleted_user', 'wpmu_new_user', 'make_spam_user', 'make_ham_user' ) as $action ) {
     105    add_action( $action, 'wp_maybe_update_network_user_counts', 10, 0 );
     106}
     107
    101108// Post meta
    102109add_action( 'added_post_meta', 'wp_cache_set_posts_last_changed' );
    103110add_action( 'updated_post_meta', 'wp_cache_set_posts_last_changed' );
  • wp-includes/functions.php

    diff --git a/wp-includes/functions.php b/wp-includes/functions.php
    index c6542d62d..88331f1d6 100644
    a b function is_wp_version_compatible( $required ) { 
    71657165function is_php_version_compatible( $required ) {
    71667166        return empty( $required ) || version_compare( phpversion(), $required, '>=' );
    71677167}
     7168
     7169
     7170/**
     7171 * The number of active users in your installation.
     7172 *
     7173 * The count is cached and updated twice daily. This is not a live count.
     7174 *
     7175 * @since 5.3.0
     7176 *
     7177 * @return int Number of active users on the network.
     7178 */
     7179function wp_get_user_count() {
     7180    return get_site_option( 'user_count', -1 );
     7181}
     7182
     7183/**
     7184 * Update the network-wide users count.
     7185 *
     7186 * If enabled through the {@see 'enable_live_network_counts'} filter, update the users count
     7187 * on a network when a user is created or its status is updated.
     7188 *
     7189 * @since 3.7.0
     7190 * @since 4.8.0 The `$network_id` parameter has been added.
     7191 * @since 5.3.0 Moved to functions.php
     7192 *
     7193 * @param int|null $network_id ID of the network. Default is the current network.
     7194 *
     7195 * @return bool
     7196 */
     7197function wp_maybe_update_network_user_counts( $network_id = null ) {
     7198        $is_small_network = ! wp_is_large_user_count();
     7199
     7200        if ( ! is_multisite() && $network_id ) {
     7201                _doing_it_wrong( __FUNCTION__, __( 'Unable to pass $nework_id if not using multisite.' ), '5.0.0' );
     7202        }
     7203
     7204        /** This filter is documented in wp-includes/ms-functions.php */
     7205        if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) ) {
     7206                return;
     7207        }
     7208
     7209        return wp_update_network_user_counts( $network_id );
     7210}
     7211
     7212/**
     7213 * Update the network-wide user count.
     7214 *
     7215 * @since 3.7.0
     7216 * @since 4.8.0 The `$network_id` parameter has been added.
     7217 * @since 5.3.0 Moved to functions.php
     7218 *
     7219 * @global wpdb $wpdb WordPress database abstraction object.
     7220 *
     7221 * @param int|null $network_id ID of the network. Default is the current network.
     7222 *
     7223 * @return bool
     7224 */
     7225function wp_update_network_user_counts( $network_id = null ) {
     7226        global $wpdb;
     7227
     7228        if ( ! is_multisite() && $network_id ) {
     7229                _doing_it_wrong( __FUNCTION__, __( 'Unable to pass $nework_id if not using multisite.' ), '5.0.0' );
     7230        }
     7231
     7232        if ( is_multisite() ) {
     7233                $query = "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'";
     7234        } else {
     7235                $query = "SELECT COUNT(ID) as c FROM $wpdb->users";
     7236        }
     7237
     7238        $count = $wpdb->get_var( $query );
     7239
     7240        return update_network_option( $network_id, 'user_count', $count );
     7241}
     7242
     7243/**
     7244 * Schedule update of the network-wide counts for the current network.
     7245 *
     7246 * @since 3.1.0
     7247 * @since 5.3.0 Moved to functions.php
     7248 */
     7249function wp_schedule_update_network_counts() {
     7250        if ( ! is_main_site() ) {
     7251                return;
     7252        }
     7253
     7254        if ( ! wp_next_scheduled( 'update_network_counts' ) && ! wp_installing() ) {
     7255                wp_schedule_event( time(), 'twicedaily', 'update_network_counts' );
     7256        }
     7257}
     7258
     7259/**
     7260 * @since 5.3.0
     7261 *
     7262 * @return boolean
     7263 */
     7264function wp_is_large_user_count() {
     7265        $count = wp_get_user_count();
     7266
     7267        /**
     7268         * Filters whether the site is considered large, based on its number of users.
     7269         *
     7270         * @since x.x.x
     7271         *
     7272         * @param bool   $is_large_user_count Whether the site has more than 10000 users.
     7273         * @param int    $count         The count of items for the component.
     7274         */
     7275        return apply_filters( 'wp_is_large_user_count', $count > 10000, $count );
     7276}
  • wp-includes/ms-default-filters.php

    diff --git a/wp-includes/ms-default-filters.php b/wp-includes/ms-default-filters.php
    index a9658398b..50d7524da 100644
    a b add_action( 'transition_post_status', '_update_blog_date_on_post_publish', 10, 3 
    8181add_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10, 3 );
    8282
    8383// Counts
    84 add_action( 'admin_init', 'wp_schedule_update_network_counts' );
    85 add_action( 'update_network_counts', 'wp_update_network_counts', 10, 0 );
    86 foreach ( array( 'user_register', 'deleted_user', 'wpmu_new_user', 'make_spam_user', 'make_ham_user' ) as $action ) {
    87         add_action( $action, 'wp_maybe_update_network_user_counts', 10, 0 );
    88 }
     84add_action( 'update_network_counts', 'wp_update_network_site_counts', 10, 0 );
    8985foreach ( array( 'make_spam_blog', 'make_ham_blog', 'archive_blog', 'unarchive_blog', 'make_delete_blog', 'make_undelete_blog' ) as $action ) {
    9086        add_action( $action, 'wp_maybe_update_network_site_counts', 10, 0 );
    9187}
  • wp-includes/ms-deprecated.php

    diff --git a/wp-includes/ms-deprecated.php b/wp-includes/ms-deprecated.php
    index 6763fcb38..e820cb009 100644
    a b function is_user_option_local( $key, $user_id = 0, $blog_id = 0 ) { 
    552552        return isset( $current_user->$local_key );
    553553}
    554554
     555/**
     556 * The number of active users in your installation.
     557 *
     558 * The count is cached and updated twice daily. This is not a live count.
     559 *
     560 * @since MU (3.0.0)
     561 * @since 4.8.0 The `$network_id` parameter has been added.
     562 * @deprecated 5.3.0
     563 *
     564 * @param int|null $network_id ID of the network. Default is the current network.
     565 * @return int Number of active users on the network.
     566 */
     567function get_user_count( $network_id = null ) {
     568        _deprecated_function( __FUNCTION__, '5.3.0', 'wp_get_user_count()' );
     569
     570        return get_network_option( $network_id, 'user_count' );
     571}
     572
    555573/**
    556574 * Store basic site info in the blogs table.
    557575 *
  • wp-includes/ms-functions.php

    diff --git a/wp-includes/ms-functions.php b/wp-includes/ms-functions.php
    index dc774a399..ed212ef50 100644
    a b  
    1717function get_sitestats() {
    1818        $stats = array(
    1919                'blogs' => get_blog_count(),
    20                 'users' => get_user_count(),
     20                'users' => wp_get_user_count(),
    2121        );
    2222
    2323        return $stats;
    function get_active_blog_for_user( $user_id ) { 
    9595        }
    9696}
    9797
    98 /**
    99  * The number of active users in your installation.
    100  *
    101  * The count is cached and updated twice daily. This is not a live count.
    102  *
    103  * @since MU (3.0.0)
    104  * @since 4.8.0 The `$network_id` parameter has been added.
    105  *
    106  * @param int|null $network_id ID of the network. Default is the current network.
    107  * @return int Number of active users on the network.
    108  */
    109 function get_user_count( $network_id = null ) {
    110         return get_network_option( $network_id, 'user_count' );
    111 }
    112 
    11398/**
    11499 * The number of active sites on your installation.
    115100 *
    function filter_SSL( $url ) { 
    22642249        return $url;
    22652250}
    22662251
    2267 /**
    2268  * Schedule update of the network-wide counts for the current network.
    2269  *
    2270  * @since 3.1.0
    2271  */
    2272 function wp_schedule_update_network_counts() {
    2273         if ( ! is_main_site() ) {
    2274                 return;
    2275         }
    2276 
    2277         if ( ! wp_next_scheduled( 'update_network_counts' ) && ! wp_installing() ) {
    2278                 wp_schedule_event( time(), 'twicedaily', 'update_network_counts' );
    2279         }
    2280 }
    2281 
    22822252/**
    22832253 * Update the network-wide counts for the current network.
    22842254 *
    function wp_maybe_update_network_site_counts( $network_id = null ) { 
    23232293        wp_update_network_site_counts( $network_id );
    23242294}
    23252295
    2326 /**
    2327  * Update the network-wide users count.
    2328  *
    2329  * If enabled through the {@see 'enable_live_network_counts'} filter, update the users count
    2330  * on a network when a user is created or its status is updated.
    2331  *
    2332  * @since 3.7.0
    2333  * @since 4.8.0 The `$network_id` parameter has been added.
    2334  *
    2335  * @param int|null $network_id ID of the network. Default is the current network.
    2336  */
    2337 function wp_maybe_update_network_user_counts( $network_id = null ) {
    2338         $is_small_network = ! wp_is_large_network( 'users', $network_id );
    2339 
    2340         /** This filter is documented in wp-includes/ms-functions.php */
    2341         if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) ) {
    2342                 return;
    2343         }
    2344 
    2345         wp_update_network_user_counts( $network_id );
    2346 }
    2347 
    23482296/**
    23492297 * Update the network-wide site count.
    23502298 *
    function wp_update_network_site_counts( $network_id = null ) { 
    23732321        update_network_option( $network_id, 'blog_count', $count );
    23742322}
    23752323
    2376 /**
    2377  * Update the network-wide user count.
    2378  *
    2379  * @since 3.7.0
    2380  * @since 4.8.0 The `$network_id` parameter has been added.
    2381  *
    2382  * @global wpdb $wpdb WordPress database abstraction object.
    2383  *
    2384  * @param int|null $network_id ID of the network. Default is the current network.
    2385  */
    2386 function wp_update_network_user_counts( $network_id = null ) {
    2387         global $wpdb;
    2388 
    2389         $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" );
    2390         update_network_option( $network_id, 'user_count', $count );
    2391 }
    2392 
    23932324/**
    23942325 * Returns the space used by the current blog.
    23952326 *
    function upload_size_limit_filter( $size ) { 
    25072438 *
    25082439 * @since 3.3.0
    25092440 * @since 4.8.0 The `$network_id` parameter has been added.
     2441 * @since 5.3.0 Deprecated `$network_id`.
    25102442 *
    25112443 * @param string   $using      'sites or 'users'. Default is 'sites'.
    2512  * @param int|null $network_id ID of the network. Default is the current network.
     2444 * @param null     $deprecated Deprecated; ID of the network. Default is the current network.
    25132445 * @return bool True if the network meets the criteria for large. False otherwise.
    25142446 */
    2515 function wp_is_large_network( $using = 'sites', $network_id = null ) {
    2516         $network_id = (int) $network_id;
     2447function wp_is_large_network( $using = 'sites', $deprecated = null ) {
     2448
     2449        if ( null !== $deprecated ) {
     2450                _deprecated_argument( __FUNCTION__, __( 'Unable to pass $network_id. ' ), '5.3.0' );
     2451        }
     2452
     2453        $network_id = (int) $deprecated;
    25172454        if ( ! $network_id ) {
    25182455                $network_id = get_current_network_id();
    25192456        }
    25202457
    25212458        if ( 'users' == $using ) {
    2522                 $count = get_user_count( $network_id );
     2459
     2460                $count = wp_get_user_count( $network_id );
     2461
     2462                /** This filter is documented in wp-includes/functions.php */
     2463                $is_large_network = apply_filters( 'wp_is_large_user_count', $count > 10000, $count );
     2464
    25232465                /**
    25242466                 * Filters whether the network is considered large.
    25252467                 *
    function wp_is_large_network( $using = 'sites', $network_id = null ) { 
    25312473                 * @param int    $count            The count of items for the component.
    25322474                 * @param int    $network_id       The ID of the network being checked.
    25332475                 */
    2534                 return apply_filters( 'wp_is_large_network', $count > 10000, 'users', $count, $network_id );
     2476                return apply_filters( 'wp_is_large_network', $is_large_network, 'users', $count, $network_id );
    25352477        }
    25362478
    2537         $count = get_blog_count( $network_id );
     2479        $count = get_blog_count();
    25382480        /** This filter is documented in wp-includes/ms-functions.php */
    25392481        return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count, $network_id );
    25402482}
  • wp-includes/update.php

    diff --git a/wp-includes/update.php b/wp-includes/update.php
    index 824575099..e9314b059 100644
    a b function wp_version_check( $extra_stats = array(), $force_check = false ) { 
    7676        }
    7777
    7878        if ( is_multisite() ) {
    79                 $user_count        = get_user_count();
    8079                $num_blogs         = get_blog_count();
    8180                $wp_install        = network_site_url();
    8281                $multisite_enabled = 1;
    8382        } else {
    84                 $user_count        = count_users();
    85                 $user_count        = $user_count['total_users'];
    8683                $multisite_enabled = 0;
    8784                $num_blogs         = 1;
    8885                $wp_install        = home_url( '/' );