| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * bbPress Abstractions. | |
| 4 | + * bbPress Abstractions | |
| 5 | 5 | * |
| 6 | 6 | * This file contains functions for abstracting WordPress core functionality |
| 7 | 7 | * into convenient wrappers so they can be used more reliably. |
| 8 | 8 | * |
| @@ -16,9 +16,9 @@ | ||
| 16 | 16 | // Exit if accessed directly |
| 17 | 17 | defined( 'ABSPATH' ) || exit; |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * Setup Admin. | |
| 20 | + * Setup Admin | |
| 21 | 21 | * |
| 22 | 22 | * This exists outside of "/includes/admin/" because the converter may need to |
| 23 | 23 | * be setup to convert the passwords of users that were migrated from another |
| 24 | 24 | * forum platform. |
| @@ -44,9 +44,9 @@ | ||
| 44 | 44 | return $bbp->admin; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | - * Setup Converter. | |
| 48 | + * Setup Converter | |
| 49 | 49 | * |
| 50 | 50 | * This exists outside of "/includes/admin/" because the converter may need to |
| 51 | 51 | * be setup to convert the passwords of users that were migrated from another |
| 52 | 52 | * forum platform. |
| @@ -77,17 +77,17 @@ | ||
| 77 | 77 | |
| 78 | 78 | /** Globals *******************************************************************/ |
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | - * Lookup and return a global variable. | |
| 81 | + * Lookup and return a global variable | |
| 82 | 82 | * |
| 83 | 83 | * @since 2.5.8 bbPress (r5814) |
| 84 | 84 | * |
| 85 | - * @param string $name Name of global variable. | |
| 86 | - * @param string $type Type of variable to check with `is_a()`. | |
| 87 | - * @param mixed $default Default value to return if no global found. | |
| 85 | + * @param string $name Name of global variable | |
| 86 | + * @param string $type Type of variable to check with `is_a()` | |
| 87 | + * @param mixed $default Default value to return if no global found | |
| 88 | 88 | * |
| 89 | - * @return mixed Verified object if valid, Default or null if invalid. | |
| 89 | + * @return mixed Verified object if valid, Default or null if invalid | |
| 90 | 90 | */ |
| 91 | 91 | function bbp_get_global_object( $name = '', $type = '', $default = null ) { |
| 92 | 92 | |
| 93 | 93 | // If no name passed |
| @@ -111,9 +111,9 @@ | ||
| 111 | 111 | return apply_filters( 'bbp_get_global_object', $retval, $name, $type, $default ); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
| 115 | - * Get the `$wp_query` global without needing to declare it everywhere. | |
| 115 | + * Get the `$wp_query` global without needing to declare it everywhere | |
| 116 | 116 | * |
| 117 | 117 | * @since 2.6.0 bbPress (r6582) |
| 118 | 118 | * |
| 119 | 119 | * @return WP_Roles |
| @@ -122,9 +122,9 @@ | ||
| 122 | 122 | return bbp_get_global_object( 'wp_query', 'WP_Query' ); |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
| 126 | - * Get the `$wp_roles` global without needing to declare it everywhere. | |
| 126 | + * Get the `$wp_roles` global without needing to declare it everywhere | |
| 127 | 127 | * |
| 128 | 128 | * @since 2.2.0 bbPress (r4293) |
| 129 | 129 | * |
| 130 | 130 | * @return WP_Roles |
| @@ -420,9 +420,9 @@ | ||
| 420 | 420 | ); |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /** |
| 424 | - * Get the root URL. | |
| 424 | + * Get the root URL | |
| 425 | 425 | * |
| 426 | 426 | * @since 2.5.8 bbPress (r5814) |
| 427 | 427 | * |
| 428 | 428 | * @return string |
| @@ -442,9 +442,9 @@ | ||
| 442 | 442 | return apply_filters( 'bbp_get_root_url', $retval ); |
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | /** |
| 446 | - * Get the slug used for paginated requests. | |
| 446 | + * Get the slug used for paginated requests | |
| 447 | 447 | * |
| 448 | 448 | * @since 2.4.0 bbPress (r4926) |
| 449 | 449 | * |
| 450 | 450 | * @return string |
| @@ -468,9 +468,9 @@ | ||
| 468 | 468 | * Is the environment using pretty URLs? |
| 469 | 469 | * |
| 470 | 470 | * @since 2.5.8 bbPress (r5814) |
| 471 | 471 | * |
| 472 | - * @global object $wp_rewrite The WP_Rewrite object. | |
| 472 | + * @global object $wp_rewrite The WP_Rewrite object | |
| 473 | 473 | * |
| 474 | 474 | * @return bool |
| 475 | 475 | */ |
| 476 | 476 | function bbp_use_pretty_urls() { |
| @@ -497,9 +497,9 @@ | ||
| 497 | 497 | * functions have decided for us. |
| 498 | 498 | * |
| 499 | 499 | * @since 2.6.0 bbPress (r6678) |
| 500 | 500 | * |
| 501 | - * @param string $pagination_links The HTML links used for pagination. | |
| 501 | + * @param string $pagination_links The HTML links used for pagination | |
| 502 | 502 | * |
| 503 | 503 | * @return string |
| 504 | 504 | */ |
| 505 | 505 | function bbp_make_first_page_canonical( $pagination_links = '' ) { |
| @@ -566,9 +566,9 @@ | ||
| 566 | 566 | return bbp_make_first_page_canonical( paginate_links( $r ) ); |
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | /** |
| 570 | - * Parse the WordPress core version number. | |
| 570 | + * Parse the WordPress core version number | |
| 571 | 571 | * |
| 572 | 572 | * @since 2.6.0 bbPress (r6051) |
| 573 | 573 | * |
| 574 | 574 | * @global string $wp_version |
| @@ -587,16 +587,16 @@ | ||
| 587 | 587 | * Is this a large bbPress installation? |
| 588 | 588 | * |
| 589 | 589 | * @since 2.6.0 bbPress (r6242) |
| 590 | 590 | * |
| 591 | - * @return bool True if more than 10000 users, false not. | |
| 591 | + * @return bool True if more than 10000 users, false not | |
| 592 | 592 | */ |
| 593 | 593 | function bbp_is_large_install() { |
| 594 | 594 | |
| 595 | - // Preserve the network filter on multisite and use the core user threshold | |
| 595 | + // Multisite has a function specifically for this | |
| 596 | 596 | $retval = function_exists( 'wp_is_large_network' ) |
| 597 | 597 | ? wp_is_large_network( 'users' ) |
| 598 | - : wp_is_large_user_count(); | |
| 598 | + : ( bbp_get_total_users() > 10000 ); | |
| 599 | 599 | |
| 600 | 600 | // Filter & return |
| 601 | 601 | return (bool) apply_filters( 'bbp_is_large_install', $retval ); |
| 602 | 602 | } |
| @@ -601,18 +601,17 @@ | ||
| 601 | 601 | return (bool) apply_filters( 'bbp_is_large_install', $retval ); |
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | /** |
| 605 | - * Get the cached installation-wide user count maintained by WordPress. | |
| 605 | + * Get the total number of users on the forums | |
| 606 | 606 | * |
| 607 | - * On multisite, this is the network count, not the current site forum-role count. | |
| 608 | - * | |
| 609 | 607 | * @since 2.0.0 bbPress (r2769) |
| 610 | 608 | * |
| 611 | - * @return int Total number of users. | |
| 609 | + * @return int Total number of users | |
| 612 | 610 | */ |
| 613 | 611 | function bbp_get_total_users() { |
| 614 | - $count = get_user_count(); | |
| 612 | + $bbp_db = bbp_db(); | |
| 613 | + $count = $bbp_db->get_var( "SELECT COUNT(ID) as c FROM {$bbp_db->users} WHERE user_status = '0'" ); | |
| 615 | 614 | |
| 616 | 615 | // Filter & return |
| 617 | 616 | return (int) apply_filters( 'bbp_get_total_users', (int) $count ); |
| 618 | 617 | } |
| @@ -617,60 +616,8 @@ | ||
| 617 | 616 | return (int) apply_filters( 'bbp_get_total_users', (int) $count ); |
| 618 | 617 | } |
| 619 | 618 | |
| 620 | 619 | /** |
| 621 | - * Count users with a forum role on the current site. | |
| 622 | - * | |
| 623 | - * Includes blocked users and counts users with multiple forum roles only once. | |
| 624 | - * Role membership is matched in stored capabilities, as in count_users(). | |
| 625 | - * | |
| 626 | - * @since 2.7.0 | |
| 627 | - * | |
| 628 | - * @return int Total number of forum-role holders. | |
| 629 | - */ | |
| 630 | -function bbp_get_total_forum_users() { | |
| 631 | - $bbp_db = bbp_db(); | |
| 632 | - $roles = array_keys( bbp_get_dynamic_roles() ); | |
| 633 | - $count = 0; | |
| 634 | - | |
| 635 | - if ( ! empty( $roles ) ) { | |
| 636 | - sort( $roles ); | |
| 637 | - | |
| 638 | - // Use the global users group so changes on other sites invalidate counts | |
| 639 | - $last_changed = wp_cache_get( 'bbp_forum_users_last_changed', 'users' ); | |
| 640 | - if ( false === $last_changed ) { | |
| 641 | - wp_cache_add( 'bbp_forum_users_last_changed', microtime(), 'users' ); | |
| 642 | - $last_changed = wp_cache_get( 'bbp_forum_users_last_changed', 'users' ); | |
| 643 | - } | |
| 644 | - | |
| 645 | - $meta_key = $bbp_db->get_blog_prefix() . 'capabilities'; | |
| 646 | - $cache_key = 'bbp_forum_users:' . md5( serialize( array( $bbp_db->users, $bbp_db->usermeta, $meta_key, $roles, $last_changed ) ) ); | |
| 647 | - $count = wp_cache_get( $cache_key, 'users' ); | |
| 648 | - | |
| 649 | - if ( false === $count ) { | |
| 650 | - $clauses = array(); | |
| 651 | - foreach ( $roles as $role ) { | |
| 652 | - $clauses[] = $bbp_db->prepare( 'meta_value LIKE %s', '%' . $bbp_db->esc_like( '"' . $role . '"' ) . '%' ); | |
| 653 | - } | |
| 654 | - | |
| 655 | - // Match any forum role without returning users or pagination totals | |
| 656 | - $role_sql = implode( ' OR ', $clauses ); | |
| 657 | - $key_sql = $bbp_db->prepare( 'meta_key = %s', $meta_key ); | |
| 658 | - $count = $bbp_db->get_var( "SELECT COUNT(DISTINCT user_id) FROM {$bbp_db->usermeta} INNER JOIN {$bbp_db->users} ON user_id = ID WHERE {$key_sql} AND ({$role_sql})" ); | |
| 659 | - | |
| 660 | - // Do not cache failed queries; expire superseded cache generations | |
| 661 | - if ( null !== $count ) { | |
| 662 | - $count = (int) $count; | |
| 663 | - wp_cache_set( $cache_key, $count, 'users', HOUR_IN_SECONDS ); | |
| 664 | - } | |
| 665 | - } | |
| 666 | - } | |
| 667 | - | |
| 668 | - // Filter the result after caching so request-specific overrides stay local | |
| 669 | - return (int) apply_filters( 'bbp_get_total_forum_users', (int) $count ); | |
| 670 | -} | |
| 671 | - | |
| 672 | -/** | |
| 673 | 620 | * Switch to a site in a multisite installation. |
| 674 | 621 | * |
| 675 | 622 | * If not a multisite installation, no switching will occur. |
| 676 | 623 | * |
| @@ -707,9 +654,9 @@ | ||
| 707 | 654 | * Generate a default intercept value. |
| 708 | 655 | * |
| 709 | 656 | * @since 2.6.0 |
| 710 | 657 | * |
| 711 | - * @staticvar mixed $rand Null by default, random string on first call. | |
| 658 | + * @staticvar mixed $rand Null by default, random string on first call | |
| 712 | 659 | * |
| 713 | 660 | * @return string |
| 714 | 661 | */ |
| 715 | 662 | function bbp_default_intercept() { |
| @@ -736,9 +683,9 @@ | ||
| 736 | 683 | return $rand; |
| 737 | 684 | } |
| 738 | 685 | |
| 739 | 686 | /** |
| 740 | - * Whether a value has been intercepted. | |
| 687 | + * Whether a value has been intercepted | |
| 741 | 688 | * |
| 742 | 689 | * @since 2.6.0 |
| 743 | 690 | * |
| 744 | 691 | * @param bool $value |
| @@ -751,10 +698,10 @@ | ||
| 751 | 698 | * Allow interception of a method or function call. |
| 752 | 699 | * |
| 753 | 700 | * @since 2.6.0 |
| 754 | 701 | * |
| 755 | - * @param string $action Typically the name of the caller function. | |
| 756 | - * @param array $args Typically the results of caller function func_get_args(). | |
| 702 | + * @param string $action Typically the name of the caller function | |
| 703 | + * @param array $args Typically the results of caller function func_get_args() | |
| 757 | 704 | * |
| 758 | 705 | * @return mixed Intercept results. Default bbp_default_intercept(). |
| 759 | 706 | */ |
| 760 | 707 | function bbp_maybe_intercept( $action = '', $args = array() ) { |