Changeset 52069 for trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php
- Timestamp:
- 11/09/2021 02:15:23 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php
r51882 r52069 100 100 ) 101 101 ); 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 ); 102 125 } 103 126 … … 561 584 562 585 /** 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 /** 563 658 * Retrieves the query params for collections. 564 659 *
Note: See TracChangeset
for help on using the changeset viewer.