Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion includes/Abilities/Settings/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ public function execute_get_settings( $input = array() ): array {
}

$group = isset( $input['group'] ) && is_string( $input['group'] ) ? $input['group'] : '';
$fields = isset( $input['fields'] ) && is_array( $input['fields'] ) ? $input['fields'] : array();
$fields = isset( $input['fields'] ) && ( is_array( $input['fields'] ) || is_string( $input['fields'] ) )
? array_values( array_filter( wp_parse_list( $input['fields'] ), 'is_string' ) )
: array();

$result = array();
foreach ( $settings as $exposed_name => $setting ) {
Expand Down
15 changes: 15 additions & 0 deletions tests/Integration/Includes/Abilities/Settings/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,21 @@ public function test_core_settings_get_filters_by_fields(): void {
$this->assertEqualSets( array( 'blogname', 'posts_per_page' ), array_keys( $result ) );
}

/**
* A comma-separated `fields` value passes schema validation, so it narrows the
* response like an array does.
*
* @since x.x.x
*/
public function test_core_settings_get_filters_by_comma_separated_fields(): void {
$this->become_admin();
$this->register_ability();

$result = wp_get_ability( 'core/settings-get' )->execute( array( 'fields' => 'blogname, posts_per_page' ) );

$this->assertEqualSets( array( 'blogname', 'posts_per_page' ), array_keys( $result ) );
}

/**
* Supplying both `group` and `fields` narrows the response to their intersection.
*
Expand Down
Loading