From 004fbf2589bcb4b072510e367f3b8ae5f7e5438d Mon Sep 17 00:00:00 2001
From: Kevin Ullyott <ullyott.kevin@gmail.com>
Date: Mon, 30 Dec 2019 17:22:06 -0800
Subject: [PATCH] Add removed_user_from_blog action hook

Adds an action hook to remove_user_from_blog for after the succesful removal of a user from a blog

Signed-off-by: Kevin Ullyott <ullyott.kevin@gmail.com>

added_user_to_blog action hook to add_user_to_blog

Signed-off-by: Kevin Ullyott <ullyott.kevin@gmail.com>

Update removed_user_from_blog @since

Signed-off-by: Kevin Ullyott <ullyott.kevin@gmail.com>

added_new_user action hook to add_new_user_to_blog

Signed-off-by: Kevin Ullyott <ullyott.kevin@gmail.com>
---
 src/wp-includes/ms-functions.php | 37 +++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git src/wp-includes/ms-functions.php src/wp-includes/ms-functions.php
index 43325c0cac..d53a53980c 100644
--- src/wp-includes/ms-functions.php
+++ src/wp-includes/ms-functions.php
@@ -213,7 +213,18 @@ function add_user_to_blog( $blog_id, $user_id, $role ) {
 	do_action( 'add_user_to_blog', $user_id, $role, $blog_id );
 
 	clean_user_cache( $user_id );
-	wp_cache_delete( $blog_id . '_user_count', 'blog-details' );
+    wp_cache_delete( $blog_id . '_user_count', 'blog-details' );
+    
+    /**
+	 * Fires immediately after a user is added to a site, and after the user cache has been cleaned.
+	 *
+	 * @since MU (5.4.0)
+	 *
+	 * @param int    $user_id User ID.
+	 * @param string $role    User role.
+	 * @param int    $blog_id Blog ID.
+	 */
+	do_action( 'added_user_to_blog', $user_id, $role, $blog_id );
 
 	restore_current_blog();
 
@@ -303,7 +314,17 @@ function remove_user_from_blog( $user_id, $blog_id = '', $reassign = '' ) {
 		}
 	}
 
-	restore_current_blog();
+    /**
+	 * Fires after a user is removed from a site.
+	 *
+	 * @since MU (5.4.0)
+	 *
+	 * @param int $user_id User ID.
+	 * @param int $blog_id Blog ID.
+	 */
+    do_action( 'removed_user_from_blog', $user_id, $blog_id );
+
+    restore_current_blog();
 
 	return true;
 }
@@ -2185,7 +2206,17 @@ function add_new_user_to_blog( $user_id, $password, $meta ) {
 		$result = add_user_to_blog( $blog_id, $user_id, $role );
 
 		if ( ! is_wp_error( $result ) ) {
-			update_user_meta( $user_id, 'primary_blog', $blog_id );
+            update_user_meta( $user_id, 'primary_blog', $blog_id );
+
+            /**
+		     * Fires immediately after a new user is added to a site.
+		     *
+		     * @since MU (5.4.0)
+		     *
+		     * @param int $user_id User ID.
+	         * @param int $blog_id Blog ID.
+		     */
+            do_action( 'added_new_user', $user_id, $blog_id );
 		}
 	}
 }
-- 
2.21.0 (Apple Git-122.2)

