From 2e94a24e25c1c1da70eb219204e99b86014d5178 Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Fri, 29 Apr 2016 15:53:28 +0000 Subject: [PATCH] Multisite: Add the `pre_get_blogs_of_user` filter This allows a plugin to short circuit `get_blogs_of_user()` in cases where the default behavior of the function is unnecessary or slow. (e.g. A user is a member of thousands of sites.) Props jsternberg. See #31746, Fixes #36707. Built from https://develop.svn.wordpress.org/trunk@37326 git-svn-id: http://core.svn.wordpress.org/trunk@37292 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/user.php | 19 +++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/wp-includes/user.php b/wp-includes/user.php index 4ac9fe93b9..ff7cd49090 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -578,6 +578,25 @@ function get_blogs_of_user( $user_id, $all = false ) { if ( empty( $user_id ) ) return array(); + /** + * Filter the list of a user's sites before it is populated. + * + * Passing a non-null value to the filter will effectively short circuit + * get_blogs_of_user(), returning that value instead. + * + * @since 4.6.0 + * + * @param null|array $blogs An array of WP_Site objects of which the user is a member. + * @param int $user_id User ID. + * @param bool $all Whether the returned array should contain all sites, including + * those marked 'deleted', 'archived', or 'spam'. Default false. + */ + $blogs = apply_filters( 'pre_get_blogs_of_user', null, $user_id, $all ); + + if ( null !== $blogs ) { + return $blogs; + } + $keys = get_user_meta( $user_id ); if ( empty( $keys ) ) return array(); diff --git a/wp-includes/version.php b/wp-includes/version.php index 5c9dcec5be..665651c0c5 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.6-alpha-37325'; +$wp_version = '4.6-alpha-37326'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.