Filter hook 'can_add_user_to_blog'

in WP Core File wp-includes/ms-functions.php at line 182

View Source

can_add_user_to_blog

Filter Hook
Description
Filters whether a user should be added to a site.

Hook Information

File Location wp-includes/ms-functions.php View on GitHub
Hook Type Filter
Line Number 182

Hook Parameters

Type Name Description
true|WP_Error $retval True if the user should be added to the site, error object otherwise.
int $user_id User ID.
string $role User role.
int $blog_id Site ID.

Usage Examples

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

function my_custom_filter($retval, $user_id, $role, $blog_id) {
    // Your custom filtering logic here
    return $retval;
}

Source Code Context

wp-includes/ms-functions.php:182 - How this hook is used in WordPress core
<?php
 177  	 *                               object otherwise.
 178  	 * @param int           $user_id User ID.
 179  	 * @param string        $role    User role.
 180  	 * @param int           $blog_id Site ID.
 181  	 */
 182  	$can_add_user = apply_filters( 'can_add_user_to_blog', true, $user_id, $role, $blog_id );
 183  
 184  	if ( true !== $can_add_user ) {
 185  		restore_current_blog();
 186  
 187  		if ( is_wp_error( $can_add_user ) ) {

PHP Documentation

<?php
/**
	 * Filters whether a user should be added to a site.
	 *
	 * @since 4.9.0
	 *
	 * @param true|WP_Error $retval  True if the user should be added to the site, error
	 *                               object otherwise.
	 * @param int           $user_id User ID.
	 * @param string        $role    User role.
	 * @param int           $blog_id Site ID.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 4
  • File: wp-includes/ms-functions.php
Related Hooks

Related hooks will be displayed here in future updates.