Skip to content

Commit 1e4138d

Browse files
obenlandclaude
andcommitted
Address review feedback: remove filter after dispatch, use empty caps
- Remove the get_user_metadata filter via rest_post_dispatch so it doesn't persist beyond the request. - Return an empty capabilities array instead of subscriber role — is_array() passes without granting any real capabilities. - Assert the application password is actually deleted in the test. - Fix closure spacing per WordPress coding standards. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8eafbd6 commit 1e4138d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

settings/rest-api.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,10 @@ function allow_application_password_management( $result, $server, $request ) {
496496
}
497497

498498
add_filter( 'get_user_metadata', __NAMESPACE__ . '\treat_as_member_of_blog', 10, 3 );
499+
add_filter( 'rest_post_dispatch', function( $response ) {
500+
remove_filter( 'get_user_metadata', __NAMESPACE__ . '\treat_as_member_of_blog', 10 );
501+
return $response;
502+
} );
499503

500504
return $result;
501505
}
@@ -526,7 +530,8 @@ function treat_as_member_of_blog( $check, $user_id, $meta_key ) {
526530
}
527531

528532
// Return a nested array: get_metadata() unwraps one level when $single is true.
529-
return array( array( 'subscriber' => true ) );
533+
// An empty capabilities array satisfies is_array() without granting any role.
534+
return array( array() );
530535
}
531536

532537
/**

tests/settings/test-application-passwords.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function test_non_member_can_revoke_application_password() : void {
170170
);
171171

172172
// Remove the user from the current blog to simulate profiles.wordpress.org.
173-
$remove_user_callback = function ( $check, $user_id, $meta_key ) {
173+
$remove_user_callback = function( $check, $user_id, $meta_key ) {
174174
global $wpdb;
175175

176176
if ( $user_id !== self::$regular_user->ID ) {
@@ -206,6 +206,15 @@ public function test_non_member_can_revoke_application_password() : void {
206206
remove_filter( 'get_user_metadata', $remove_user_callback, 9 );
207207

208208
$this->assertSame( 200, $response->get_status(), 'Non-member should be able to revoke their own application password.' );
209+
210+
$remaining_passwords = WP_Application_Passwords::get_user_application_passwords( self::$regular_user->ID );
211+
$remaining_uuids = wp_list_pluck( $remaining_passwords, 'uuid' );
212+
213+
$this->assertNotContains(
214+
$item['uuid'],
215+
$remaining_uuids,
216+
'Application password should be removed after revocation.'
217+
);
209218
}
210219

211220
/**

0 commit comments

Comments
 (0)