diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php index af920d21f5..b0ac65a647 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php @@ -719,7 +719,7 @@ class WP_REST_Application_Passwords_Controller extends WP_REST_Controller { return $error; } - if ( is_multisite() && ! is_user_member_of_blog( $user->ID ) ) { + if ( is_multisite() && ! user_can( $user->ID, 'manage_sites' ) && ! is_user_member_of_blog( $user->ID ) ) { return $error; } diff --git a/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php b/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php index 993dd2d7c0..d4418f62cd 100644 --- a/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php +++ b/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php @@ -409,6 +409,32 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 ); } + /** + * @ticket 53224 + * @group ms-required + */ + public function test_create_item_for_super_admin_on_site_where_they_are_not_a_member() { + wp_set_current_user( self::$admin ); + + // Create a site where the Super Admin is not a member. + $blog_id = self::factory()->blog->create( + array( + 'user_id' => self::$subscriber_id, + ) + ); + + switch_to_blog( $blog_id ); + + $request = new WP_REST_Request( 'POST', '/wp/v2/users/me/application-passwords' ); + $request->set_body_params( array( 'name' => 'App' ) ); + $response = rest_do_request( $request ); + + restore_current_blog(); + + $this->assertNotWPError( $response ); + $this->assertSame( 201, $response->get_status() ); + } + /** * @ticket 51939 */