WordPress.org

Make WordPress Core

Changeset 37326


Ignore:
Timestamp:
04/29/2016 03:52:34 PM (4 years ago)
Author:
jeremyfelt
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/user.php

    r37317 r37326  
    578578    if ( empty( $user_id ) )
    579579        return array();
     580
     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    }
    580599
    581600    $keys = get_user_meta( $user_id );
Note: See TracChangeset for help on using the changeset viewer.