Skip to content

Commit a28c976

Browse files
Abilities API: rename the core/settings 'slugs' input to 'settings'
'settings' reads more naturally than 'slugs' for filtering an abilities-exposed settings map by name.
1 parent e8bc673 commit a28c976

2 files changed

Lines changed: 26 additions & 26 deletions

File tree

‎src/wp-includes/abilities/class-wp-settings-abilities.php‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ public static function register(): void {
5858
* @since 7.1.0
5959
*/
6060
public static function register_get_settings(): void {
61-
$settings = self::get_exposed_settings();
62-
$groups = array_values( array_unique( array_filter( wp_list_pluck( $settings, 'group' ) ) ) );
63-
$slugs = array_keys( $settings );
64-
$properties = array();
61+
$settings = self::get_exposed_settings();
62+
$groups = array_values( array_unique( array_filter( wp_list_pluck( $settings, 'group' ) ) ) );
63+
$setting_names = array_keys( $settings );
64+
$properties = array();
6565
foreach ( $settings as $exposed_name => $setting ) {
6666
$properties[ $exposed_name ] = $setting['schema'];
6767
}
@@ -72,7 +72,7 @@ public static function register_get_settings(): void {
7272
'label' => __( 'Get Settings' ),
7373
'description' => __( 'Returns WordPress settings as a flat map of setting name to value. By default returns all settings exposed to abilities, or optionally a subset filtered by settings group or by setting name.' ),
7474
'category' => self::CATEGORY,
75-
'input_schema' => self::get_settings_input_schema( $groups, $slugs ),
75+
'input_schema' => self::get_settings_input_schema( $groups, $setting_names ),
7676
'output_schema' => array(
7777
'type' => 'object',
7878
'description' => __( 'A map of setting name to its current value.' ),
@@ -106,14 +106,14 @@ public static function execute_get_settings( $input = array() ): array {
106106

107107
$settings = self::get_exposed_settings();
108108
$group = isset( $input['group'] ) ? (string) $input['group'] : '';
109-
$slugs = isset( $input['slugs'] ) && is_array( $input['slugs'] ) ? $input['slugs'] : array();
109+
$names = isset( $input['settings'] ) && is_array( $input['settings'] ) ? $input['settings'] : array();
110110

111111
$result = array();
112112
foreach ( $settings as $exposed_name => $setting ) {
113113
if ( '' !== $group && $setting['group'] !== $group ) {
114114
continue;
115115
}
116-
if ( ! empty( $slugs ) && ! in_array( $exposed_name, $slugs, true ) ) {
116+
if ( ! empty( $names ) && ! in_array( $exposed_name, $names, true ) ) {
117117
continue;
118118
}
119119

@@ -142,11 +142,11 @@ public static function has_permission(): bool {
142142
*
143143
* @since 7.1.0
144144
*
145-
* @param string[] $groups Available settings groups.
146-
* @param string[] $slugs Available exposed setting names.
145+
* @param string[] $groups Available settings groups.
146+
* @param string[] $setting_names Available exposed setting names.
147147
* @return array<string, mixed> The input JSON Schema.
148148
*/
149-
protected static function get_settings_input_schema( array $groups, array $slugs ): array {
149+
protected static function get_settings_input_schema( array $groups, array $setting_names ): array {
150150
return array(
151151
'type' => 'object',
152152
'default' => array(),
@@ -173,13 +173,13 @@ protected static function get_settings_input_schema( array $groups, array $slugs
173173
array(
174174
'title' => __( 'Filter by name' ),
175175
'type' => 'object',
176-
'required' => array( 'slugs' ),
176+
'required' => array( 'settings' ),
177177
'properties' => array(
178-
'slugs' => array(
178+
'settings' => array(
179179
'type' => 'array',
180180
'items' => array(
181181
'type' => 'string',
182-
'enum' => $slugs,
182+
'enum' => $setting_names,
183183
),
184184
'description' => __( 'Return only the settings with these names.' ),
185185
),

‎tests/phpunit/tests/abilities-api/wpRegisterCoreSettingsAbility.php‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ public function test_core_settings_ability_is_registered(): void {
7979
}
8080

8181
/**
82-
* The input schema exposes mutually exclusive `group` and `slugs` filters.
82+
* The input schema exposes mutually exclusive `group` and `settings` filters.
8383
*
8484
* @ticket 64146
8585
*/
86-
public function test_core_settings_input_schema_is_one_of_group_or_slugs(): void {
86+
public function test_core_settings_input_schema_is_one_of_group_or_settings(): void {
8787
$schema = wp_get_ability( 'core/settings' )->get_input_schema();
8888

8989
$this->assertSame( 'object', $schema['type'] );
@@ -95,10 +95,10 @@ public function test_core_settings_input_schema_is_one_of_group_or_slugs(): void
9595
$this->assertContains( 'general', $group_branch['properties']['group']['enum'] );
9696
$this->assertContains( 'reading', $group_branch['properties']['group']['enum'] );
9797

98-
$slugs_branch = $schema['oneOf'][2];
99-
$this->assertSame( array( 'slugs' ), $slugs_branch['required'] );
100-
$this->assertContains( 'blogname', $slugs_branch['properties']['slugs']['items']['enum'] );
101-
$this->assertContains( 'posts_per_page', $slugs_branch['properties']['slugs']['items']['enum'] );
98+
$settings_branch = $schema['oneOf'][2];
99+
$this->assertSame( array( 'settings' ), $settings_branch['required'] );
100+
$this->assertContains( 'blogname', $settings_branch['properties']['settings']['items']['enum'] );
101+
$this->assertContains( 'posts_per_page', $settings_branch['properties']['settings']['items']['enum'] );
102102
}
103103

104104
/**
@@ -136,30 +136,30 @@ public function test_core_settings_filters_by_group(): void {
136136
}
137137

138138
/**
139-
* The `slugs` filter narrows the response to the requested setting names.
139+
* The `settings` filter narrows the response to the requested setting names.
140140
*
141141
* @ticket 64146
142142
*/
143-
public function test_core_settings_filters_by_slugs(): void {
143+
public function test_core_settings_filters_by_settings(): void {
144144
$this->become_admin();
145145

146-
$result = wp_get_ability( 'core/settings' )->execute( array( 'slugs' => array( 'blogname', 'posts_per_page' ) ) );
146+
$result = wp_get_ability( 'core/settings' )->execute( array( 'settings' => array( 'blogname', 'posts_per_page' ) ) );
147147

148148
$this->assertSame( array( 'blogname', 'posts_per_page' ), array_keys( $result ) );
149149
}
150150

151151
/**
152-
* Supplying both `group` and `slugs` violates the `oneOf` and is rejected.
152+
* Supplying both `group` and `settings` violates the `oneOf` and is rejected.
153153
*
154154
* @ticket 64146
155155
*/
156-
public function test_core_settings_rejects_group_and_slugs_together(): void {
156+
public function test_core_settings_rejects_group_and_settings_together(): void {
157157
$this->become_admin();
158158

159159
$result = wp_get_ability( 'core/settings' )->execute(
160160
array(
161-
'group' => 'reading',
162-
'slugs' => array( 'blogname' ),
161+
'group' => 'reading',
162+
'settings' => array( 'blogname' ),
163163
)
164164
);
165165

0 commit comments

Comments
 (0)