Skip to content

Commit 737cc6e

Browse files
introduce a get_allowed_settings
1 parent 4b11cab commit 737cc6e

1 file changed

Lines changed: 24 additions & 22 deletions

File tree

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

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,25 @@ private static function init(): void {
7272
self::$output_schema = self::build_output_schema();
7373
}
7474

75+
/**
76+
* Gets registered settings that have show_in_abilities enabled.
77+
*
78+
* @since 7.0.0
79+
*
80+
* @return array Associative array of option_name => args for allowed settings.
81+
*/
82+
private static function get_allowed_settings(): array {
83+
$settings = array();
84+
85+
foreach ( get_registered_settings() as $option_name => $args ) {
86+
if ( ! empty( $args['show_in_abilities'] ) ) {
87+
$settings[ $option_name ] = $args;
88+
}
89+
}
90+
91+
return $settings;
92+
}
93+
7594
/**
7695
* Gets unique setting groups that have show_in_abilities enabled.
7796
*
@@ -82,11 +101,7 @@ private static function init(): void {
82101
private static function get_available_groups(): array {
83102
$groups = array();
84103

85-
foreach ( get_registered_settings() as $args ) {
86-
if ( empty( $args['show_in_abilities'] ) ) {
87-
continue;
88-
}
89-
104+
foreach ( self::get_allowed_settings() as $args ) {
90105
$group = $args['group'] ?? 'general';
91106
if ( ! in_array( $group, $groups, true ) ) {
92107
$groups[] = $group;
@@ -108,11 +123,7 @@ private static function get_available_groups(): array {
108123
private static function get_available_slugs(): array {
109124
$slugs = array();
110125

111-
foreach ( get_registered_settings() as $option_name => $args ) {
112-
if ( empty( $args['show_in_abilities'] ) ) {
113-
continue;
114-
}
115-
126+
foreach ( self::get_allowed_settings() as $option_name => $args ) {
116127
$slugs[] = $option_name;
117128
}
118129

@@ -135,11 +146,7 @@ private static function get_available_slugs(): array {
135146
private static function build_output_schema(): array {
136147
$group_properties = array();
137148

138-
foreach ( get_registered_settings() as $option_name => $args ) {
139-
if ( empty( $args['show_in_abilities'] ) ) {
140-
continue;
141-
}
142-
149+
foreach ( self::get_allowed_settings() as $option_name => $args ) {
143150
$group = $args['group'] ?? 'general';
144151

145152
$setting_schema = array(
@@ -278,14 +285,9 @@ public static function execute_get_settings( $input = array() ): array {
278285
$filter_group = ! empty( $input['group'] ) ? $input['group'] : null;
279286
$filter_slugs = ! empty( $input['slugs'] ) ? $input['slugs'] : null;
280287

281-
$registered_settings = get_registered_settings();
282-
$settings_by_group = array();
283-
284-
foreach ( $registered_settings as $option_name => $args ) {
285-
if ( empty( $args['show_in_abilities'] ) ) {
286-
continue;
287-
}
288+
$settings_by_group = array();
288289

290+
foreach ( self::get_allowed_settings() as $option_name => $args ) {
289291
$group = $args['group'] ?? 'general';
290292

291293
if ( $filter_group && $group !== $filter_group ) {

0 commit comments

Comments
 (0)