REST API: Fix autovivification deprecation notice in WP_Test_REST_Widgets_Controller::set_up().

If the `'widget_testwidget'` option does not exist, `false` was returned from `get_option()`. The `set_up()` logic expects an `array()` and assigns values to keys without checking for an array. The automatic creation of an array (autovivification) triggers a `Deprecated: Automatic conversion of false to array is deprecated in` deprecation notice on PHP 8.1.

This commit:
- Fixes the deprecation notice by making the default value an empty array.
- Moves getting the option within the conditional where it's needed.
- Provides a micro-optimization by only getting the options when the conditions are correct for processing.
- Makes the code consistent within the `set_up()` for both `get_option()` instances.

Follow-up to [51029].

Props jrf, hellofromTonya, BinaryKitten.
See #53635.
Built from https://develop.svn.wordpress.org/trunk@51830


git-svn-id: http://core.svn.wordpress.org/trunk@51437 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
hellofromTonya 2021-09-20 18:49:58 +00:00
parent 1c55ce2482
commit bb4c9b56f3

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.9-alpha-51829'; $wp_version = '5.9-alpha-51830';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.