Make WordPress Core


Ignore:
Timestamp:
06/23/2021 01:33:20 AM (4 years ago)
Author:
noisysocks
Message:

Widgets: Fix widget preview not working if widget registered via a instance

The register_widget function can be called with a class name or a class
instance. Once called with a class instance, the class instance is converted to
hash as used key in array.

Props spacedmonkey, zieladam.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php

    r51183 r51216  
    472472
    473473        $serialized_instance = serialize( $instance );
     474        $widget_key = $wp_widget_factory->get_widget_key( $id );
    474475
    475476        $response = array(
     
    482483            'preview'  => trim(
    483484                $this->get_widget_preview(
    484                     $widget_object,
     485                    $widget_key,
    485486                    $instance
    486487                )
     
    504505     * instance. Used by encode_form_data() to preview a widget.
    505506
    506      * @param WP_Widget $widget_object Widget object to call widget() on.
     507     * @param string    $widget   The widget's PHP class name (see class-wp-widget.php).
    507508     * @param array     $instance Widget instance settings.
    508509     * @return string
    509510     */
    510     private function get_widget_preview( $widget_object, $instance ) {
     511    private function get_widget_preview( $widget, $instance ) {
    511512        ob_start();
    512         the_widget( get_class( $widget_object ), $instance );
     513        the_widget( $widget, $instance );
    513514        return ob_get_clean();
    514515    }
Note: See TracChangeset for help on using the changeset viewer.