Skip to content

Commit b20616f

Browse files
committed
Remove types from the mark_setting method as this is hooked to register_setting_args and there's a chance other plugins could hook here and return bad data, resulting in fatals
1 parent b158c7d commit b20616f

2 files changed

Lines changed: 42 additions & 3 deletions

File tree

includes/Abilities/Show_In_Abilities.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,17 @@ public function register(): void {
5353
*
5454
* @since x.x.x
5555
*
56-
* @param array<string, mixed> $args The setting registration arguments.
56+
* @param mixed $args The setting registration arguments.
5757
* @param array<string, mixed> $defaults The default registration arguments.
5858
* @param string $option_group The settings group.
5959
* @param string $option_name The option name.
60-
* @return array<string, mixed> The (possibly amended) registration arguments.
60+
* @return mixed The (possibly amended) registration arguments.
6161
*/
62-
public function mark_setting( array $args, array $defaults, string $option_group, string $option_name ): array {
62+
public function mark_setting( $args, $defaults, $option_group, $option_name ) {
63+
if ( ! is_array( $args ) ) {
64+
return $args;
65+
}
66+
6367
$settings = $this->settings_map();
6468

6569
if ( isset( $settings[ $option_name ] ) && empty( $args['show_in_abilities'] ) ) {

tests/Integration/Includes/Abilities/Show_In_AbilitiesTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,41 @@ public function test_does_not_mark_uncurated_setting(): void {
119119
$this->assertTrue( empty( $settings['wpai_not_curated_option']['show_in_abilities'] ) );
120120
}
121121

122+
/**
123+
* Non-array arguments are returned untouched rather than fataling.
124+
*
125+
* Core applies the `register_setting_args` filter before `wp_parse_args()` normalizes the
126+
* arguments, so a plugin that calls `register_setting()` with a non-array (e.g. WPBakery
127+
* Page Builder passing `null`) reaches the filter unchanged. The callback must hand it back
128+
* as-is for core to normalize, not blow up on a strict array type.
129+
*
130+
* @since x.x.x
131+
*
132+
* @dataProvider data_non_array_args
133+
*
134+
* @param mixed $args A non-array value passed through the filter.
135+
*/
136+
public function test_passes_through_non_array_args( $args ): void {
137+
$filtered = $this->show_in_abilities->mark_setting( $args, array(), 'general', 'blogname' );
138+
139+
$this->assertSame( $args, $filtered );
140+
}
141+
142+
/**
143+
* Non-array argument values for the pass-through test.
144+
*
145+
* @since x.x.x
146+
*
147+
* @return array<string, array{0: mixed}> Data sets keyed by description.
148+
*/
149+
public function data_non_array_args(): array {
150+
return array(
151+
'null' => array( null ),
152+
'string' => array( 'sanitize_me' ),
153+
'false' => array( false ),
154+
);
155+
}
156+
122157
/**
123158
* An explicit `show_in_abilities` value already on the setting is preserved.
124159
*

0 commit comments

Comments
 (0)