Changeset 53018 for trunk/src/wp-includes/functions.php
- Timestamp:
- 03/29/2022 01:51:52 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.php
r53016 r53018 8419 8419 return abs( (float) $expected - (float) $actual ) <= $precision; 8420 8420 } 8421 8422 /**8423 * Returns the number of active users in your installation.8424 *8425 * Note that on a large site the count may be cached and only updated twice daily.8426 *8427 * @since MU (3.0.0)8428 * @since 4.8.0 The `$network_id` parameter has been added.8429 * @since 6.0.0 Move to wp-includes/functions.php.8430 *8431 * @param int|null $network_id ID of the network. Default is the current network.8432 * @return int Number of active users on the network.8433 */8434 function get_user_count( $network_id = null ) {8435 if ( ! is_multisite() && null !== $network_id ) {8436 _doing_it_wrong(8437 __FUNCTION__,8438 sprintf(8439 /* translators: %s: $network_id */8440 __( 'Unable to pass %s if not using multisite.' ),8441 '<code>$network_id</code>'8442 ),8443 '6.0.0'8444 );8445 }8446 8447 return (int) get_network_option( $network_id, 'user_count', -1 );8448 }8449 8450 /**8451 * Updates the total count of users on the site if live user counting is enabled.8452 *8453 * @since 6.0.08454 *8455 * @param int|null $network_id ID of the network. Default is the current network.8456 * @return bool Whether the update was successful.8457 */8458 function wp_maybe_update_user_counts( $network_id = null ) {8459 if ( ! is_multisite() && null !== $network_id ) {8460 _doing_it_wrong(8461 __FUNCTION__,8462 sprintf(8463 /* translators: %s: $network_id */8464 __( 'Unable to pass %s if not using multisite.' ),8465 '<code>$network_id</code>'8466 ),8467 '6.0.0'8468 );8469 }8470 8471 $is_small_network = ! wp_is_large_user_count( $network_id );8472 /** This filter is documented in wp-includes/ms-functions.php */8473 if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) ) {8474 return false;8475 }8476 8477 return wp_update_user_counts( $network_id );8478 }8479 8480 /**8481 * Updates the total count of users on the site.8482 *8483 * @global wpdb $wpdb WordPress database abstraction object.8484 * @since 6.0.08485 *8486 * @param int|null $network_id ID of the network. Default is the current network.8487 * @return bool Whether the update was successful.8488 */8489 function wp_update_user_counts( $network_id = null ) {8490 global $wpdb;8491 8492 if ( ! is_multisite() && null !== $network_id ) {8493 _doing_it_wrong(8494 __FUNCTION__,8495 sprintf(8496 /* translators: %s: $network_id */8497 __( 'Unable to pass %s if not using multisite.' ),8498 '<code>$network_id</code>'8499 ),8500 '6.0.0'8501 );8502 }8503 8504 $query = "SELECT COUNT(ID) as c FROM $wpdb->users";8505 if ( is_multisite() ) {8506 $query .= " WHERE spam = '0' AND deleted = '0'";8507 }8508 8509 $count = $wpdb->get_var( $query );8510 8511 return update_network_option( $network_id, 'user_count', $count );8512 }8513 8514 /**8515 * Schedules a recurring recalculation of the total count of users.8516 *8517 * @since 6.0.08518 */8519 function wp_schedule_update_user_counts() {8520 if ( ! is_main_site() ) {8521 return;8522 }8523 8524 if ( ! wp_next_scheduled( 'wp_update_user_counts' ) && ! wp_installing() ) {8525 wp_schedule_event( time(), 'twicedaily', 'wp_update_user_counts' );8526 }8527 }8528 8529 /**8530 * Determines whether the site has a large number of users.8531 *8532 * The default criteria for a large site is more than 10,000 users.8533 *8534 * @since 6.0.08535 *8536 * @param int|null $network_id ID of the network. Default is the current network.8537 * @return bool Whether the site has a large number of users.8538 */8539 function wp_is_large_user_count( $network_id = null ) {8540 if ( ! is_multisite() && null !== $network_id ) {8541 _doing_it_wrong(8542 __FUNCTION__,8543 sprintf(8544 /* translators: %s: $network_id */8545 __( 'Unable to pass %s if not using multisite.' ),8546 '<code>$network_id</code>'8547 ),8548 '6.0.0'8549 );8550 }8551 8552 $count = get_user_count( $network_id );8553 8554 /**8555 * Filters whether the site is considered large, based on its number of users.8556 *8557 * @since 6.0.08558 *8559 * @param bool $is_large_user_count Whether the site has a large number of users.8560 * @param int $count The total number of users.8561 * @param int|null $network_id ID of the network. `null` represents the current network.8562 */8563 return apply_filters( 'wp_is_large_user_count', $count > 10000, $count, $network_id );8564 }
Note: See TracChangeset
for help on using the changeset viewer.