Filter hook 'pre_get_blogs_of_user'

in WP Core File wp-includes/user.php at line 1040

View Source

pre_get_blogs_of_user

Filter Hook
Description
Filters the list of a user's sites before it is populated. Returning a non-null value from the filter will effectively short circuit get_blogs_of_user(), returning that value instead.

Hook Information

File Location wp-includes/user.php View on GitHub
Hook Type Filter
Line Number 1040

Hook Parameters

Type Name Description
null|object[] $sites An array of site objects of which the user is a member.
int $user_id User ID.
bool $all Whether the returned array should contain all sites, including those marked 'deleted', 'archived', or 'spam'. Default false.

Usage Examples

Basic Usage
<?php
// Hook into pre_get_blogs_of_user
add_filter('pre_get_blogs_of_user', 'my_custom_filter', 10, 3);

function my_custom_filter($sites, $user_id, $all) {
    // Your custom filtering logic here
    return $sites;
}

Source Code Context

wp-includes/user.php:1040 - How this hook is used in WordPress core
<?php
1035  	 * @param null|object[] $sites   An array of site objects of which the user is a member.
1036  	 * @param int           $user_id User ID.
1037  	 * @param bool          $all     Whether the returned array should contain all sites, including
1038  	 *                               those marked 'deleted', 'archived', or 'spam'. Default false.
1039  	 */
1040  	$sites = apply_filters( 'pre_get_blogs_of_user', null, $user_id, $all );
1041  
1042  	if ( null !== $sites ) {
1043  		return $sites;
1044  	}
1045  

PHP Documentation

<?php
/**
	 * Filters the list of a user's sites before it is populated.
	 *
	 * Returning a non-null value from the filter will effectively short circuit
	 * get_blogs_of_user(), returning that value instead.
	 *
	 * @since 4.6.0
	 *
	 * @param null|object[] $sites   An array of 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.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 3
  • File: wp-includes/user.php
Related Hooks

Related hooks will be displayed here in future updates.