Make WordPress Core


Ignore:
Timestamp:
11/09/2021 02:15:23 AM (3 years ago)
Author:
noisysocks
Message:

Add Site Editor and PHP changes from Gutenberg 10.1 - 11.9

  • First pass at adding the site editor from the Gutenberg plugin to wp-admin/site-editor.php.
  • Adds miscellaneous PHP changes from Gutenberg 10.1 - 11.9.

Follows [52042].
See #54337.
Props youknowriad, aristath, hellofromtonya, gziolo.

File:
1 edited

Legend:

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

    r51882 r52069  
    100100            )
    101101        );
     102
     103        register_rest_route(
     104            $this->namespace,
     105            '/' . $this->rest_base . '/(?P<id>[a-zA-Z0-9_-]+)/render',
     106            array(
     107                array(
     108                    'methods'             => WP_REST_Server::CREATABLE,
     109                    'permission_callback' => array( $this, 'get_item_permissions_check' ),
     110                    'callback'            => array( $this, 'render' ),
     111                    'args'                => array(
     112                        'id'       => array(
     113                            'description' => __( 'The widget type id.', 'default' ),
     114                            'type'        => 'string',
     115                            'required'    => true,
     116                        ),
     117                        'instance' => array(
     118                            'description' => __( 'Current instance settings of the widget.', 'default' ),
     119                            'type'        => 'object',
     120                        ),
     121                    ),
     122                ),
     123            )
     124        );
    102125    }
    103126
     
    561584
    562585    /**
     586     * Renders a single Legacy Widget and wraps it in a JSON-encodable array.
     587     *
     588     * @since 5.9.0
     589     *
     590     * @param WP_REST_Request $request Full details about the request.
     591     *
     592     * @return array An array with rendered Legacy Widget HTML.
     593     */
     594    public function render( $request ) {
     595        return array(
     596            'preview' => $this->render_legacy_widget_preview_iframe(
     597                $request['id'],
     598                isset( $request['instance'] ) ? $request['instance'] : null
     599            ),
     600        );
     601    }
     602
     603    /**
     604     * Renders a page containing a preview of the requested Legacy Widget block.
     605     *
     606     * @since 5.9.0
     607     *
     608     * @param string $id_base The id base of the requested widget.
     609     * @param array  $instance The widget instance attributes.
     610     *
     611     * @return string Rendered Legacy Widget block preview.
     612     */
     613    private function render_legacy_widget_preview_iframe( $id_base, $instance ) {
     614        if ( ! defined( 'IFRAME_REQUEST' ) ) {
     615            define( 'IFRAME_REQUEST', true );
     616        }
     617
     618        ob_start();
     619        ?>
     620        <!doctype html>
     621        <html <?php language_attributes(); ?>>
     622        <head>
     623            <meta charset="<?php bloginfo( 'charset' ); ?>" />
     624            <meta name="viewport" content="width=device-width, initial-scale=1" />
     625            <link rel="profile" href="https://gmpg.org/xfn/11" />
     626            <?php wp_head(); ?>
     627            <style>
     628                /* Reset theme styles */
     629                html, body, #page, #content {
     630                    padding: 0 !important;
     631                    margin: 0 !important;
     632                }
     633            </style>
     634        </head>
     635        <body <?php body_class(); ?>>
     636        <div id="page" class="site">
     637            <div id="content" class="site-content">
     638                <?php
     639                $registry = WP_Block_Type_Registry::get_instance();
     640                $block    = $registry->get_registered( 'core/legacy-widget' );
     641                echo $block->render(
     642                    array(
     643                        'idBase'   => $id_base,
     644                        'instance' => $instance,
     645                    )
     646                );
     647                ?>
     648            </div><!-- #content -->
     649        </div><!-- #page -->
     650        <?php wp_footer(); ?>
     651        </body>
     652        </html>
     653        <?php
     654        return ob_get_clean();
     655    }
     656
     657    /**
    563658     * Retrieves the query params for collections.
    564659     *
Note: See TracChangeset for help on using the changeset viewer.