Skip to content

Commit a8218c3

Browse files
remove optinal fields and capabilities
1 parent 58931a3 commit a8218c3

2 files changed

Lines changed: 10 additions & 101 deletions

File tree

src/wp-includes/abilities/class-wp-users-abilities.php

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,19 @@ private static function get_user_input_schema(): array {
8080
array( 'required' => array( 'email' ) ),
8181
),
8282
'properties' => array(
83-
'id' => array(
83+
'email' => array(
84+
'type' => 'string',
85+
'format' => 'email',
86+
'description' => __( 'User email address.' ),
87+
),
88+
'id' => array(
8489
'type' => 'integer',
8590
'description' => __( 'User ID.' ),
8691
),
87-
'username' => array(
92+
'username' => array(
8893
'type' => 'string',
8994
'description' => __( 'User login name.' ),
9095
),
91-
'email' => array(
92-
'type' => 'string',
93-
'format' => 'email',
94-
'description' => __( 'User email address.' ),
95-
),
96-
'include_capabilities' => array(
97-
'type' => 'boolean',
98-
'description' => __( 'Whether to include the user capabilities in the response.' ),
99-
'default' => false,
100-
),
10196
),
10297
'additionalProperties' => false,
10398
);
@@ -163,10 +158,6 @@ private static function get_user_output_schema(): array {
163158
),
164159
'properties' => array(
165160
'avatar_urls' => $avatar_urls_schema,
166-
'capabilities' => array(
167-
'type' => 'object',
168-
'description' => __( 'All capabilities assigned to the user. Only included if include_capabilities is true and the current user can view them.' ),
169-
),
170161
'description' => array(
171162
'type' => 'string',
172163
'description' => __( 'Description of the user.' ),
@@ -236,24 +227,6 @@ private static function get_user_output_schema(): array {
236227
);
237228
}
238229

239-
/**
240-
* Normalizes capabilities into an object with boolean values.
241-
*
242-
* @since 7.0.0
243-
*
244-
* @param mixed $capabilities Capabilities map.
245-
* @return object Normalized capabilities.
246-
*/
247-
private static function normalize_capabilities( $capabilities ): object {
248-
$normalized = array();
249-
250-
foreach ( (array) $capabilities as $capability => $granted ) {
251-
$normalized[ (string) $capability ] = rest_sanitize_boolean( $granted );
252-
}
253-
254-
return (object) $normalized;
255-
}
256-
257230
/**
258231
* Normalizes a list of values into an array of strings.
259232
*
@@ -337,8 +310,7 @@ public static function check_get_user_permission( array $input = array() ): bool
337310
* @return array<string, mixed>|WP_Error The user data or error.
338311
*/
339312
public static function execute_get_user( array $input = array() ) {
340-
$input = is_array( $input ) ? $input : array();
341-
$include_capabilities = array_key_exists( 'include_capabilities', $input ) ? rest_sanitize_boolean( $input['include_capabilities'] ) : false;
313+
$input = is_array( $input ) ? $input : array();
342314

343315
$user = self::find_user( $input );
344316

@@ -377,10 +349,6 @@ public static function execute_get_user( array $input = array() ) {
377349
$result['roles'] = self::normalize_string_list( $user->roles );
378350
}
379351

380-
if ( $include_capabilities && $can_view_sensitive_user_fields ) {
381-
$result['capabilities'] = self::normalize_capabilities( $user->allcaps );
382-
}
383-
384352
return $result;
385353
}
386354
}

tests/phpunit/tests/abilities-api/wpRegisterCoreAbilities.php

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -154,45 +154,6 @@ public function test_core_get_current_user_info_returns_user_data(): void {
154154
$this->assertSame( get_userdata( $user_id )->display_name, $result['display_name'] );
155155
}
156156

157-
/**
158-
* Tests boolean-like include_capabilities values for the get-user ability.
159-
* @ticket 64146
160-
*/
161-
public function test_core_get_user_include_capabilities_accepts_boolean_like_values(): void {
162-
$user_id = self::factory()->user->create( array( 'role' => 'subscriber' ) );
163-
164-
wp_set_current_user( $user_id );
165-
166-
$ability = wp_get_ability( 'core/get-user' );
167-
168-
$result = $ability->execute(
169-
array(
170-
'id' => $user_id,
171-
'include_capabilities' => '1',
172-
)
173-
);
174-
$this->assertIsArray( $result );
175-
$this->assertArrayHasKey( 'capabilities', $result );
176-
177-
$result = $ability->execute(
178-
array(
179-
'id' => $user_id,
180-
'include_capabilities' => 1,
181-
)
182-
);
183-
$this->assertIsArray( $result );
184-
$this->assertArrayHasKey( 'capabilities', $result );
185-
186-
$result = $ability->execute(
187-
array(
188-
'id' => $user_id,
189-
'include_capabilities' => '0',
190-
)
191-
);
192-
$this->assertIsArray( $result );
193-
$this->assertArrayNotHasKey( 'capabilities', $result );
194-
}
195-
196157
/**
197158
* Tests get-user output is normalized to the declared schema types.
198159
* @ticket 64146
@@ -202,23 +163,11 @@ public function test_core_get_user_output_is_normalized_to_schema_types(): void
202163

203164
wp_set_current_user( $user_id );
204165

205-
$ability = wp_get_ability( 'core/get-user' );
206-
$capability_key = $GLOBALS['wpdb']->get_blog_prefix() . 'capabilities';
207-
update_user_meta(
208-
$user_id,
209-
$capability_key,
210-
array(
211-
'subscriber' => true,
212-
'custom_capability_flag' => '1',
213-
'custom_capability_disabled' => '0',
214-
)
215-
);
216-
clean_user_cache( $user_id );
166+
$ability = wp_get_ability( 'core/get-user' );
217167

218168
$result = $ability->execute(
219169
array(
220-
'id' => $user_id,
221-
'include_capabilities' => 1,
170+
'id' => $user_id,
222171
)
223172
);
224173

@@ -247,14 +196,6 @@ public function test_core_get_user_output_is_normalized_to_schema_types(): void
247196
foreach ( $result['avatar_urls'] as $avatar_url ) {
248197
$this->assertIsString( $avatar_url );
249198
}
250-
251-
$this->assertIsObject( $result['capabilities'] );
252-
$this->assertObjectHasProperty( 'custom_capability_flag', $result['capabilities'] );
253-
$this->assertObjectHasProperty( 'custom_capability_disabled', $result['capabilities'] );
254-
$this->assertIsBool( $result['capabilities']->custom_capability_flag );
255-
$this->assertIsBool( $result['capabilities']->custom_capability_disabled );
256-
$this->assertTrue( $result['capabilities']->custom_capability_flag );
257-
$this->assertFalse( $result['capabilities']->custom_capability_disabled );
258199
}
259200

260201
/**

0 commit comments

Comments
 (0)