Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

WP_REST_Widget_Types_Controller::render_legacy_widget_preview_iframe() WordPress Method

This method renders a preview iframe for a given widget type. Widget type previews are used to provide a live preview of a widget type in the Customizer. They are also used in the WP_REST_Widget_Types_Controller::render_widget_type() method to render a preview of a widget type in the WordPress admin. The iframe is loaded from the WordPress admin ajax URL with the following GET parameters: widget_type - The widget type ID. preview - The preview ID. The preview ID is used to ensure that the iframe is only rendered once for each widget type. The iframe is then inserted into the DOM with an ID of "widget-type-preview-iframe-{$widget_type}".

WP_REST_Widget_Types_Controller::render_legacy_widget_preview_iframe( string $id_base, array $instance ) #

Renders a page containing a preview of the requested Legacy Widget block.


Parameters

$id_base

(string)(Required)The id base of the requested widget.

$instance

(array)(Required)The widget instance attributes.


Top ↑

Return

(string) Rendered Legacy Widget block preview.


Top ↑

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php

	private function render_legacy_widget_preview_iframe( $id_base, $instance ) {
		if ( ! defined( 'IFRAME_REQUEST' ) ) {
			define( 'IFRAME_REQUEST', true );
		}

		ob_start();
		?>
		<!doctype html>
		<html <?php language_attributes(); ?>>
		<head>
			<meta charset="<?php bloginfo( 'charset' ); ?>" />
			<meta name="viewport" content="width=device-width, initial-scale=1" />
			<link rel="profile" href="https://gmpg.org/xfn/11" />
			<?php wp_head(); ?>
			<style>
				/* Reset theme styles */
				html, body, #page, #content {
					padding: 0 !important;
					margin: 0 !important;
				}
			</style>
		</head>
		<body <?php body_class(); ?>>
		<div id="page" class="site">
			<div id="content" class="site-content">
				<?php
				$registry = WP_Block_Type_Registry::get_instance();
				$block    = $registry->get_registered( 'core/legacy-widget' );
				echo $block->render(
					array(
						'idBase'   => $id_base,
						'instance' => $instance,
					)
				);
				?>
			</div><!-- #content -->
		</div><!-- #page -->
		<?php wp_footer(); ?>
		</body>
		</html>
		<?php
		return ob_get_clean();
	}


Top ↑

Changelog

Changelog
VersionDescription
5.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.