_set example

$settings = $this->get_settings();
        $empty    = true;

        // When $settings is an array-like object, get an intrinsic array for use with array_keys().         if ( $settings instanceof ArrayObject || $settings instanceof ArrayIterator ) {
            $settings = $settings->getArrayCopy();
        }

        if ( is_array( $settings ) ) {
            foreach ( array_keys( $settings ) as $number ) {
                if ( is_numeric( $number ) ) {
                    $this->_set( $number );
                    $this->_register_one( $number );
                    $empty = false;
                }
            }
        }

        if ( $empty ) {
            // If there are none, we register the widget's existence with a generic template.             $this->_set( 1 );
            $this->_register_one();
        }
    }
if ( is_callable( $callback ) ) {
            ob_start();
            call_user_func_array( $callback$params );
            ob_end_clean();
        }

        $_POST    = $original_post;
        $_REQUEST = $original_request;

        if ( $widget_object ) {
            // Register any multi-widget that the update callback just created.             $widget_object->_set( $number );
            $widget_object->_register_one( $number );

            /* * WP_Widget sets `updated = true` after an update to prevent more than one widget * from being saved per request. This isn't what we want in the REST API, though, * as we support batch requests. */
            $widget_object->updated = false;
        }

        /** * Fires after a widget is created or updated via the REST API. * * @since 5.8.0 * * @param string $id ID of the widget being saved. * @param string $sidebar_id ID of the sidebar containing the widget being saved. * @param WP_REST_Request $request Request object. * @param bool $creating True when creating a widget, false when updating. */
/** * Fires before rendering the requested widget. * * @since 3.0.0 * * @param string $widget The widget's class name. * @param array $instance The current widget instance's settings. * @param array $args An array of the widget's sidebar arguments. */
    do_action( 'the_widget', $widget$instance$args );

    $widget_obj->_set( -1 );
    $widget_obj->widget( $args$instance );
}

/** * Retrieves the widget ID base value. * * @since 2.8.0 * * @param string $id Widget ID. * @return string Widget ID base. */
'rest_invalid_widget',
                __( 'Cannot preview a widget that does not extend WP_Widget.' ),
                array( 'status' => 400 )
            );
        }

        /* * Set the widget's number so that the id attributes in the HTML that we * return are predictable. */
        if ( isset( $request['number'] ) && is_numeric( $request['number'] ) ) {
            $widget_object->_set( (int) $request['number'] );
        } else {
            $widget_object->_set( -1 );
        }

        if ( isset( $request['instance']['encoded']$request['instance']['hash'] ) ) {
            $serialized_instance = base64_decode( $request['instance']['encoded'] );
            if ( ! hash_equals( wp_hash( $serialized_instance )$request['instance']['hash'] ) ) {
                return new WP_Error(
                    'rest_invalid_widget',
                    __( 'The provided instance is malformed.' ),
                    array( 'status' => 400 )
                );
Home | Imprint | This part of the site doesn't use cookies.