Make WordPress Core


Ignore:
Timestamp:
08/03/2017 09:40:02 PM (8 years ago)
Author:
flixos90
Message:

Multisite: Introduce a can_add_user_to_blog filter to prevent adding a user to a site.

Under certain circumstances, it can be necessary that a user should not be added to a site, beyond the restrictions that WordPress core applies. With the new can_add_user_to_blog filter, plugin developers can run custom checks and return an error in case of a failure, that will prevent the user from being added.

The user-facing parts and the REST API route that interact with add_user_to_blog() have been adjusted accordingly to provide appropriate error feedback when a user could not be added to a site. Furthermore, two existing error feedback messages in the site admin's "New User" screen have been adjusted to properly show inside an error notice instead of a success notice.

Props jmdodd.
Fixes #41101.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php

    r41162 r41225  
    493493            }
    494494
    495             add_user_to_blog( get_site()->id, $user_id, '' );
     495            $result= add_user_to_blog( get_site()->id, $user_id, '' );
     496            if ( is_wp_error( $result ) ) {
     497                return $result;
     498            }
    496499        } else {
    497500            $user_id = wp_insert_user( wp_slash( (array) $user ) );
Note: See TracChangeset for help on using the changeset viewer.