Skip to content

Commit 32dfe76

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@37326 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 6dcd17f commit 32dfe76

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/wp-includes/user.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,25 @@ function get_blogs_of_user( $user_id, $all = false ) {
578578
if ( empty( $user_id ) )
579579
return array();
580580

581+
/**
582+
* Filter the list of a user's sites before it is populated.
583+
*
584+
* Passing a non-null value to the filter will effectively short circuit
585+
* get_blogs_of_user(), returning that value instead.
586+
*
587+
* @since 4.6.0
588+
*
589+
* @param null|array $blogs An array of WP_Site objects of which the user is a member.
590+
* @param int $user_id User ID.
591+
* @param bool $all Whether the returned array should contain all sites, including
592+
* those marked 'deleted', 'archived', or 'spam'. Default false.
593+
*/
594+
$blogs = apply_filters( 'pre_get_blogs_of_user', null, $user_id, $all );
595+
596+
if ( null !== $blogs ) {
597+
return $blogs;
598+
}
599+
581600
$keys = get_user_meta( $user_id );
582601
if ( empty( $keys ) )
583602
return array();

0 commit comments

Comments
 (0)