get_widget_object example


    protected function get_widgets() {
        global $wp_widget_factory$wp_registered_widgets;

        $widgets = array();

        foreach ( $wp_registered_widgets as $widget ) {
            $parsed_id     = wp_parse_widget_id( $widget['id'] );
            $widget_object = $wp_widget_factory->get_widget_object( $parsed_id['id_base'] );

            $widget['id']       = $parsed_id['id_base'];
            $widget['is_multi'] = (bool) $widget_object;

            if ( isset( $widget['name'] ) ) {
                $widget['name'] = html_entity_decode( $widget['name'], ENT_QUOTES, get_bloginfo( 'charset' ) );
            }

            if ( isset( $widget['description'] ) ) {
                $widget['description'] = html_entity_decode( $widget['description'], ENT_QUOTES, get_bloginfo( 'charset' ) );
            }

            
if ( isset( $attributes['id'] ) ) {
        $sidebar_id = wp_find_widgets_sidebar( $attributes['id'] );
        return wp_render_widget( $attributes['id']$sidebar_id );
    }

    if ( ! isset( $attributes['idBase'] ) ) {
        return '';
    }

    $id_base       = $attributes['idBase'];
    $widget_key    = $wp_widget_factory->get_widget_key( $id_base );
    $widget_object = $wp_widget_factory->get_widget_object( $id_base );

    if ( ! $widget_key || ! $widget_object ) {
        return '';
    }

    if ( isset( $attributes['instance']['encoded']$attributes['instance']['hash'] ) ) {
        $serialized_instance = base64_decode( $attributes['instance']['encoded'] );
        if ( ! hash_equals( wp_hash( $serialized_instance )(string) $attributes['instance']['hash'] ) ) {
            return '';
        }
        $instance = unserialize( $serialized_instance );
    }

    public function sanitize_widget_instance( $value$id_base = null ) {
        global $wp_widget_factory;

        if ( array() === $value ) {
            return $value;
        }

        if ( isset( $value['raw_instance'] ) && $id_base && wp_use_widgets_block_editor() ) {
            $widget_object = $wp_widget_factory->get_widget_object( $id_base );
            if ( ! empty( $widget_object->widget_options['show_instance_in_rest'] ) ) {
                if ( 'block' === $id_base && ! current_user_can( 'unfiltered_html' ) ) {
                    /* * The content of the 'block' widget is not filtered on the fly while editing. * Filter the content here to prevent vulnerabilities. */
                    $value['raw_instance']['content'] = wp_kses_post( $value['raw_instance']['content'] );
                }

                return $value['raw_instance'];
            }
        }

        wp_get_sidebars_widgets();
        $this->retrieve_widgets();

        $widget_id  = $request['id'];
        $sidebar_id = wp_find_widgets_sidebar( $widget_id );

        // Allow sidebar to be unset or missing when widget is not a WP_Widget.         $parsed_id     = wp_parse_widget_id( $widget_id );
        $widget_object = $wp_widget_factory->get_widget_object( $parsed_id['id_base'] );
        if ( is_null( $sidebar_id ) && $widget_object ) {
            return new WP_Error(
                'rest_widget_not_found',
                __( 'No widget was found with that id.' ),
                array( 'status' => 404 )
            );
        }

        if (
            $request->has_param( 'instance' ) ||
            $request->has_param( 'form_data' )
        )
Home | Imprint | This part of the site doesn't use cookies.