[wp-trac] [WordPress Trac] #57674: unregister_setting() raises a PHP warning on unknown settings

WordPress Trac noreply at wordpress.org
Tue Oct 10 12:50:34 UTC 2023


#57674: unregister_setting() raises a PHP warning on unknown settings
-------------------------------------------------+-------------------------
 Reporter:  xknown                               |       Owner:
                                                 |  hellofromTonya
     Type:  defect (bug)                         |      Status:  closed
 Priority:  normal                               |   Milestone:  6.4
Component:  Options, Meta APIs                   |     Version:
 Severity:  normal                               |  Resolution:  fixed
 Keywords:  php81 has-patch has-unit-tests       |     Focuses:  php-
  commit                                         |  compatibility
-------------------------------------------------+-------------------------
Changes (by hellofromTonya):

 * status:  reviewing => closed
 * resolution:   => fixed


Comment:

 In [changeset:"56817" 56817]:
 {{{
 #!CommitTicketReference repository="" revision="56817"
 Options, Meta APIs: Check setting group exists before search in
 unregister_setting().

 Checks if the given `$option_group` exists before searching for the
 `$option_name`. Sets the `$pos` to `false`, as `array_search()` returns
 `false` if the option name (needle) does not exist.

 This changeset fixes 2 different PHP Warning|Notice scenarios:
 1. When the global `$new_allowed_options` is `null`, fixes raising `Trying
 to access array offset on value of type null` PHP Notice (PHP 7.4) |
 Warning (on PHP 8).

 2. When the global `$new_allowed_options` is an `array` and the setting
 group key does not exist, fixes raising "Undefined index:
 unknown_setting_group" PHP Notice (PHP 7) | Warning (on PHP 8).

 For both scenarios, the `array_search()` is skipped and the `$pos` is set
 to a default of `false`, i.e. which is the value returned when
 `array_search()` is unsuccessful.

 Props xknown, hellofromTonya, nicolefurlan, oglekler, SergeyBiryukov,
 shailu25.
 Fixes #57674.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57674#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list