diff --git src/wp-includes/class-wp-widget-factory.php src/wp-includes/class-wp-widget-factory.php
index 82eda94e3a..eaa02be3cf 100644
|
|
|
class WP_Widget_Factory {
|
| 55 | 55 | * @param string|WP_Widget $widget Either the name of a `WP_Widget` subclass or an instance of a `WP_Widget` subclass. |
| 56 | 56 | */ |
| 57 | 57 | public function register( $widget ) { |
| | 58 | $widget_id = ''; |
| | 59 | |
| 58 | 60 | if ( $widget instanceof WP_Widget ) { |
| 59 | | $this->widgets[ spl_object_hash( $widget ) ] = $widget; |
| | 61 | $widget_id = spl_object_hash( $widget ); |
| | 62 | $this->widgets[ $widget_id ] = $widget; |
| 60 | 63 | } else { |
| 61 | | $this->widgets[ $widget ] = new $widget(); |
| | 64 | $widget_id = $widget; |
| | 65 | $this->widgets[ $widget_id ] = new $widget(); |
| | 66 | } |
| | 67 | |
| | 68 | /** |
| | 69 | * The WordPress Block Developer documentation site first informed allowing |
| | 70 | * a Legacy Widget migration to a Block Widget needed the Legacy Widget to |
| | 71 | * add a `$show_instance_in_rest` property to their class and set it to `true`. |
| | 72 | * |
| | 73 | * As WordPress 5.8.0 will finally use a widget option to allow this migration, |
| | 74 | * it seems fair to check for this property to eventually add the corresponding |
| | 75 | * option to the widget in case the early developer missed that change. |
| | 76 | * |
| | 77 | * see https://core.trac.wordpress.org/ticket/53332 |
| | 78 | */ |
| | 79 | if ( isset( $this->widgets[ $widget_id ]->show_instance_in_rest ) && ! isset( $this->widgets[ $widget_id ]->widget_options['show_instance_in_rest'] ) ) { |
| | 80 | $widget_options = array(); |
| | 81 | if ( is_array( $this->widgets[ $widget_id ]->widget_options ) ) { |
| | 82 | $widget_options = $this->widgets[ $widget_id ]->widget_options; |
| | 83 | } |
| | 84 | |
| | 85 | $this->widgets[ $widget_id ]->widget_options = array_merge( |
| | 86 | $widget_options, |
| | 87 | array( |
| | 88 | 'show_instance_in_rest' => $this->widgets[ $widget_id ]->show_instance_in_rest, |
| | 89 | ) |
| | 90 | ); |
| 62 | 91 | } |
| 63 | 92 | } |
| 64 | 93 | |