WordPress.org

Make WordPress Core

Ticket #38741: 38741.10.diff

File 38741.10.diff, 16.2 KB (added by macbookandrew, 3 years ago)

Adds another fix for bulk-editing of posts

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

     
    133133        protected function get_views() {
    134134                global $role;
    135135
    136                 $total_users  = get_user_count();
     136                $total_users  = wp_get_user_count();
    137137                $super_admins = get_super_admins();
    138138                $total_admins = count( $super_admins );
    139139
  • src/wp-admin/includes/class-wp-posts-list-table.php

     
    14751475        <?php
    14761476        endif; // $bulk
    14771477
    1478 if ( post_type_supports( $screen->post_type, 'author' ) ) :
     1478if ( post_type_supports( $screen->post_type, 'author' ) && ! wp_is_large_user_count() ) :
    14791479        $authors_dropdown = '';
    14801480
    14811481        if ( current_user_can( $post_type_object->cap->edit_others_posts ) ) :
  • src/wp-admin/includes/class-wp-users-list-table.php

     
    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                        }
    193197
     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                }
     206
    194207                $current_link_attributes = empty( $role ) ? ' class="current" aria-current="page"' : '';
    195 
    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>';
    198208                foreach ( $wp_roles->get_names() as $this_role => $name ) {
    199                         if ( ! isset( $avail_roles[ $this_role ] ) ) {
     209                        if ( $count_users && ! isset( $avail_roles[ $this_role ] ) ) {
    200210                                continue;
    201211                        }
    202212
     
    208218
    209219                        $name = translate_user_role( $name );
    210220                        /* 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                                $name = sprintf( __( '%1$s <span class="count">(%2$s)</span>' ), $name, number_format_i18n( $avail_roles[ $this_role ] ) );
     223                        }
    212224                        $role_links[ $this_role ] = "<a href='" . esc_url( add_query_arg( 'role', $this_role, $url ) ) . "'$current_link_attributes>$name</a>";
    213225                }
    214226
  • src/wp-admin/includes/dashboard.php

     
    408408                $actions['create-user'] = '<a href="' . network_admin_url( 'user-new.php' ) . '">' . __( 'Create a New User' ) . '</a>';
    409409        }
    410410
    411         $c_users = get_user_count();
     411        $c_users = wp_get_user_count();
    412412        $c_blogs = get_blog_count();
    413413
    414414        /* translators: %s: number of users on the network */
  • src/wp-admin/includes/schema.php

     
    11361136                'subdomain_install'           => intval( $subdomain_install ),
    11371137                'global_terms_enabled'        => global_terms_enabled() ? '1' : '0',
    11381138                'ms_files_rewriting'          => is_multisite() ? get_site_option( 'ms_files_rewriting' ) : '0',
     1139                'user_count'                  => get_site_option( 'user_count' ),
    11391140                'initial_db_version'          => get_option( 'initial_db_version' ),
    11401141                'active_sitewide_plugins'     => array(),
    11411142                'WPLANG'                      => get_locale(),
  • src/wp-includes/default-filters.php

     
    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// Places to balance tags on input
    102109foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content' ) as $filter ) {
    103110        add_filter( $filter, 'convert_invalid_entities' );
  • src/wp-includes/functions.php

     
    64136413                }
    64146414        }
    64156415}
     6416
     6417/**
     6418 * The number of active users in your installation.
     6419 *
     6420 * The count is cached and updated twice daily. This is not a live count.
     6421 *
     6422 * @since 5.0.0
     6423 *
     6424 * @return int Number of active users on the network.
     6425 */
     6426function wp_get_user_count() {
     6427        return get_site_option( 'user_count', -1 );
     6428}
     6429
     6430/**
     6431 * Update the network-wide users count.
     6432 *
     6433 * If enabled through the {@see 'enable_live_network_counts'} filter, update the users count
     6434 * on a network when a user is created or its status is updated.
     6435 *
     6436 * @since 3.7.0
     6437 * @since 4.8.0 The `$network_id` parameter has been added.
     6438 * @since 5.0.0 Moved to functions.php
     6439 *
     6440 * @param int|null $network_id ID of the network. Default is the current network.
     6441 *
     6442 * @return bool
     6443 */
     6444function wp_maybe_update_network_user_counts( $network_id = null ) {
     6445        $is_small_network = ! wp_is_large_user_count();
     6446
     6447        if ( ! is_multisite() && $network_id ) {
     6448                _doing_it_wrong( __FUNCTION__, __( 'Unable to pass $nework_id if not using multisite.' ), '5.0.0' );
     6449        }
     6450
     6451        /** This filter is documented in wp-includes/ms-functions.php */
     6452        if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) ) {
     6453                return;
     6454        }
     6455
     6456        return wp_update_network_user_counts( $network_id );
     6457}
     6458
     6459/**
     6460 * Update the network-wide user count.
     6461 *
     6462 * @since 3.7.0
     6463 * @since 4.8.0 The `$network_id` parameter has been added.
     6464 * @since 5.0.0 Moved to functions.php
     6465 *
     6466 * @global wpdb $wpdb WordPress database abstraction object.
     6467 *
     6468 * @param int|null $network_id ID of the network. Default is the current network.
     6469 *
     6470 * @return bool
     6471 */
     6472function wp_update_network_user_counts( $network_id = null ) {
     6473        global $wpdb;
     6474
     6475        if ( ! is_multisite() && $network_id ) {
     6476                _doing_it_wrong( __FUNCTION__, __( 'Unable to pass $nework_id if not using multisite.' ), '5.0.0' );
     6477        }
     6478
     6479        if ( is_multisite() ) {
     6480                $query = "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'";
     6481        } else {
     6482                $query = "SELECT COUNT(ID) as c FROM $wpdb->users";
     6483        }
     6484
     6485        $count = $wpdb->get_var( $query );
     6486
     6487        return update_network_option( $network_id, 'user_count', $count );
     6488}
     6489
     6490/**
     6491 * Schedule update of the network-wide counts for the current network.
     6492 *
     6493 * @since 3.1.0
     6494 * @since 5.0.0 Moved to functions.php
     6495 */
     6496function wp_schedule_update_network_counts() {
     6497        if ( ! is_main_site() ) {
     6498                return;
     6499        }
     6500
     6501        if ( ! wp_next_scheduled( 'update_network_counts' ) && ! wp_installing() ) {
     6502                wp_schedule_event( time(), 'twicedaily', 'update_network_counts' );
     6503        }
     6504}
     6505
     6506/**
     6507 * @since 5.0.0
     6508 *
     6509 * @return boolean
     6510 */
     6511function wp_is_large_user_count() {
     6512        $count = wp_get_user_count();
     6513
     6514        /**
     6515         * Filters whether the site is considered large, based on its number of users.
     6516         *
     6517         * @since x.x.x
     6518         *
     6519         * @param bool   $is_large_user_count Whether the site has more than 10000 users.
     6520         * @param int    $count         The count of items for the component.
     6521         */
     6522        return apply_filters( 'wp_is_large_user_count', $count > 10000, $count );
     6523}
     6524 No newline at end of file
  • src/wp-includes/ms-default-filters.php

     
    6666add_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10, 3 );
    6767
    6868// Counts
    69 add_action( 'admin_init', 'wp_schedule_update_network_counts' );
    70 add_action( 'update_network_counts', 'wp_update_network_counts', 10, 0 );
    71 foreach ( array( 'user_register', 'deleted_user', 'wpmu_new_user', 'make_spam_user', 'make_ham_user' ) as $action ) {
    72         add_action( $action, 'wp_maybe_update_network_user_counts', 10, 0 );
    73 }
     69add_action( 'update_network_counts', 'wp_update_network_site_counts', 10, 0 );
    7470foreach ( array( 'make_spam_blog', 'make_ham_blog', 'archive_blog', 'unarchive_blog', 'make_delete_blog', 'make_undelete_blog' ) as $action ) {
    7571        add_action( $action, 'wp_maybe_update_network_site_counts', 10, 0 );
    7672}
  • src/wp-includes/ms-deprecated.php

     
    547547        return isset( $current_user->$local_key );
    548548}
    549549
     550
    550551/**
     552 * The number of active users in your installation.
     553 *
     554 * The count is cached and updated twice daily. This is not a live count.
     555 *
     556 * @since MU (3.0.0)
     557 * @since 4.8.0 The `$network_id` parameter has been added.
     558 * @deprecated 4.9.0
     559 *
     560 * @param int|null $network_id ID of the network. Default is the current network.
     561 * @return int Number of active users on the network.
     562 */
     563function get_user_count( $network_id = null ) {
     564        _deprecated_function( __FUNCTION__, '5.0.0', 'wp_get_user_count()' );
     565
     566        return get_network_option( $network_id, 'user_count' );
     567}
     568/**
    551569 * Store basic site info in the blogs table.
    552570 *
    553571 * This function creates a row in the wp_blogs table and returns
  • src/wp-includes/ms-functions.php

     
    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;
     
    9696}
    9797
    9898/**
    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 
    113 /**
    11499 * The number of active sites on your installation.
    115100 *
    116101 * The count is cached and updated twice daily. This is not a live count.
     
    24142399        return $url;
    24152400}
    24162401
    2417 /**
    2418  * Schedule update of the network-wide counts for the current network.
    2419  *
    2420  * @since 3.1.0
    2421  */
    2422 function wp_schedule_update_network_counts() {
    2423         if ( ! is_main_site() ) {
    2424                 return;
    2425         }
    24262402
    2427         if ( ! wp_next_scheduled( 'update_network_counts' ) && ! wp_installing() ) {
    2428                 wp_schedule_event( time(), 'twicedaily', 'update_network_counts' );
    2429         }
    2430 }
    2431 
    24322403/**
    24332404 * Update the network-wide counts for the current network.
    24342405 *
     
    24742445}
    24752446
    24762447/**
    2477  * Update the network-wide users count.
    2478  *
    2479  * If enabled through the {@see 'enable_live_network_counts'} filter, update the users count
    2480  * on a network when a user is created or its status is updated.
    2481  *
    2482  * @since 3.7.0
    2483  * @since 4.8.0 The `$network_id` parameter has been added.
    2484  *
    2485  * @param int|null $network_id ID of the network. Default is the current network.
    2486  */
    2487 function wp_maybe_update_network_user_counts( $network_id = null ) {
    2488         $is_small_network = ! wp_is_large_network( 'users', $network_id );
    2489 
    2490         /** This filter is documented in wp-includes/ms-functions.php */
    2491         if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) ) {
    2492                 return;
    2493         }
    2494 
    2495         wp_update_network_user_counts( $network_id );
    2496 }
    2497 
    2498 /**
    24992448 * Update the network-wide site count.
    25002449 *
    25012450 * @since 3.7.0
     
    25232472}
    25242473
    25252474/**
    2526  * Update the network-wide user count.
    2527  *
    2528  * @since 3.7.0
    2529  * @since 4.8.0 The `$network_id` parameter has been added.
    2530  *
    2531  * @global wpdb $wpdb WordPress database abstraction object.
    2532  *
    2533  * @param int|null $network_id ID of the network. Default is the current network.
    2534  */
    2535 function wp_update_network_user_counts( $network_id = null ) {
    2536         global $wpdb;
    2537 
    2538         $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" );
    2539         update_network_option( $network_id, 'user_count', $count );
    2540 }
    2541 
    2542 /**
    25432475 * Returns the space used by the current blog.
    25442476 *
    25452477 * @since 3.5.0
     
    26562588 *
    26572589 * @since 3.3.0
    26582590 * @since 4.8.0 The `$network_id` parameter has been added.
     2591 * @since 5.0.0 Deprecated $network_id
    26592592 *
    26602593 * @param string   $using      'sites or 'users'. Default is 'sites'.
    26612594 * @param int|null $network_id ID of the network. Default is the current network.
    26622595 * @return bool True if the network meets the criteria for large. False otherwise.
    26632596 */
    2664 function wp_is_large_network( $using = 'sites', $network_id = null ) {
    2665         $network_id = (int) $network_id;
     2597function wp_is_large_network( $using = 'sites', $deprecated = null ) {
     2598
     2599        if ( null !== $deprecated ) {
     2600                _deprecated_argument( __FUNCTION__, __( 'Unable to pass $network_id. ' ), '5.0.0' );
     2601        }
     2602
     2603        $network_id = (int) $deprecated;
    26662604        if ( ! $network_id ) {
    26672605                $network_id = get_current_network_id();
    26682606        }
    26692607
    26702608        if ( 'users' == $using ) {
    2671                 $count = get_user_count( $network_id );
     2609
     2610                $count = wp_get_user_count();
     2611
     2612                /** This filter is documented in wp-includes/functions.php */
     2613                $is_large_network = apply_filters( 'wp_is_large_user_count', $count > 10000, $count );
     2614
    26722615                /**
    26732616                 * Filters whether the network is considered large.
    26742617                 *
     
    26802623                 * @param int    $count            The count of items for the component.
    26812624                 * @param int    $network_id       The ID of the network being checked.
    26822625                 */
    2683                 return apply_filters( 'wp_is_large_network', $count > 10000, 'users', $count, $network_id );
     2626                return apply_filters( 'wp_is_large_network', $is_large_network, 'users', $count, $network_id );
    26842627        }
    26852628
    2686         $count = get_blog_count( $network_id );
     2629        $count = get_blog_count();
    26872630        /** This filter is documented in wp-includes/ms-functions.php */
    26882631        return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count, $network_id );
    26892632}
  • src/wp-includes/update.php

     
    7575                $mysql_version = 'N/A';
    7676        }
    7777
     78        $user_count = wp_get_user_count();
    7879        if ( is_multisite() ) {
    79                 $user_count        = get_user_count();
    8080                $num_blogs         = get_blog_count();
    8181                $wp_install        = network_site_url();
    8282                $multisite_enabled = 1;
    8383        } else {
    84                 $user_count        = count_users();
    85                 $user_count        = $user_count['total_users'];
    8684                $multisite_enabled = 0;
    8785                $num_blogs         = 1;
    8886                $wp_install        = home_url( '/' );