Edit File by line
/home/zeestwma/redstone.../wp-inclu.../blocks
File: legacy-widget.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/legacy-widget` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Renders the 'core/legacy-widget' block.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 5.8.0
[10] Fix | Delete
*
[11] Fix | Delete
* @global WP_Widget_Factory $wp_widget_factory.
[12] Fix | Delete
*
[13] Fix | Delete
* @param array $attributes The block attributes.
[14] Fix | Delete
*
[15] Fix | Delete
* @return string Rendered block.
[16] Fix | Delete
*/
[17] Fix | Delete
function render_block_core_legacy_widget( $attributes ) {
[18] Fix | Delete
global $wp_widget_factory;
[19] Fix | Delete
[20] Fix | Delete
if ( isset( $attributes['id'] ) ) {
[21] Fix | Delete
$sidebar_id = wp_find_widgets_sidebar( $attributes['id'] );
[22] Fix | Delete
return wp_render_widget( $attributes['id'], $sidebar_id );
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
if ( ! isset( $attributes['idBase'] ) ) {
[26] Fix | Delete
return '';
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
$id_base = $attributes['idBase'];
[30] Fix | Delete
$widget_key = $wp_widget_factory->get_widget_key( $id_base );
[31] Fix | Delete
$widget_object = $wp_widget_factory->get_widget_object( $id_base );
[32] Fix | Delete
[33] Fix | Delete
if ( ! $widget_key || ! $widget_object ) {
[34] Fix | Delete
return '';
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
if ( isset( $attributes['instance']['encoded'], $attributes['instance']['hash'] ) ) {
[38] Fix | Delete
$serialized_instance = base64_decode( $attributes['instance']['encoded'] );
[39] Fix | Delete
if ( ! hash_equals( wp_hash( $serialized_instance ), (string) $attributes['instance']['hash'] ) ) {
[40] Fix | Delete
return '';
[41] Fix | Delete
}
[42] Fix | Delete
$instance = unserialize( $serialized_instance );
[43] Fix | Delete
} else {
[44] Fix | Delete
$instance = array();
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
$args = array(
[48] Fix | Delete
'widget_id' => $widget_object->id,
[49] Fix | Delete
'widget_name' => $widget_object->name,
[50] Fix | Delete
);
[51] Fix | Delete
[52] Fix | Delete
ob_start();
[53] Fix | Delete
the_widget( $widget_key, $instance, $args );
[54] Fix | Delete
return ob_get_clean();
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
/**
[58] Fix | Delete
* Registers the 'core/legacy-widget' block.
[59] Fix | Delete
*
[60] Fix | Delete
* @since 5.8.0
[61] Fix | Delete
*/
[62] Fix | Delete
function register_block_core_legacy_widget() {
[63] Fix | Delete
register_block_type_from_metadata(
[64] Fix | Delete
__DIR__ . '/legacy-widget',
[65] Fix | Delete
array(
[66] Fix | Delete
'render_callback' => 'render_block_core_legacy_widget',
[67] Fix | Delete
)
[68] Fix | Delete
);
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
add_action( 'init', 'register_block_core_legacy_widget' );
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Intercepts any request with legacy-widget-preview in the query param and, if
[75] Fix | Delete
* set, renders a page containing a preview of the requested Legacy Widget
[76] Fix | Delete
* block.
[77] Fix | Delete
*
[78] Fix | Delete
* @since 5.8.0
[79] Fix | Delete
*/
[80] Fix | Delete
function handle_legacy_widget_preview_iframe() {
[81] Fix | Delete
if ( empty( $_GET['legacy-widget-preview'] ) ) {
[82] Fix | Delete
return;
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
if ( ! current_user_can( 'edit_theme_options' ) ) {
[86] Fix | Delete
return;
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
define( 'IFRAME_REQUEST', true );
[90] Fix | Delete
[91] Fix | Delete
?>
[92] Fix | Delete
<!doctype html>
[93] Fix | Delete
<html <?php language_attributes(); ?>>
[94] Fix | Delete
<head>
[95] Fix | Delete
<meta charset="<?php bloginfo( 'charset' ); ?>" />
[96] Fix | Delete
<meta name="viewport" content="width=device-width, initial-scale=1" />
[97] Fix | Delete
<link rel="profile" href="https://gmpg.org/xfn/11" />
[98] Fix | Delete
<?php wp_head(); ?>
[99] Fix | Delete
<style>
[100] Fix | Delete
/* Reset theme styles */
[101] Fix | Delete
html, body, #page, #content {
[102] Fix | Delete
padding: 0 !important;
[103] Fix | Delete
margin: 0 !important;
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
/* Hide root level text nodes */
[107] Fix | Delete
body {
[108] Fix | Delete
font-size: 0 !important;
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
/* Hide non-widget elements */
[112] Fix | Delete
body *:not(#page):not(#content):not(.widget):not(.widget *) {
[113] Fix | Delete
display: none !important;
[114] Fix | Delete
font-size: 0 !important;
[115] Fix | Delete
height: 0 !important;
[116] Fix | Delete
left: -9999px !important;
[117] Fix | Delete
max-height: 0 !important;
[118] Fix | Delete
max-width: 0 !important;
[119] Fix | Delete
opacity: 0 !important;
[120] Fix | Delete
pointer-events: none !important;
[121] Fix | Delete
position: absolute !important;
[122] Fix | Delete
top: -9999px !important;
[123] Fix | Delete
transform: translate(-9999px, -9999px) !important;
[124] Fix | Delete
visibility: hidden !important;
[125] Fix | Delete
z-index: -999 !important;
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
/* Restore widget font-size */
[129] Fix | Delete
.widget {
[130] Fix | Delete
font-size: var(--global--font-size-base);
[131] Fix | Delete
}
[132] Fix | Delete
</style>
[133] Fix | Delete
</head>
[134] Fix | Delete
<body <?php body_class(); ?>>
[135] Fix | Delete
<div id="page" class="site">
[136] Fix | Delete
<div id="content" class="site-content">
[137] Fix | Delete
<?php
[138] Fix | Delete
$registry = WP_Block_Type_Registry::get_instance();
[139] Fix | Delete
$block = $registry->get_registered( 'core/legacy-widget' );
[140] Fix | Delete
echo $block->render( $_GET['legacy-widget-preview'] );
[141] Fix | Delete
?>
[142] Fix | Delete
</div><!-- #content -->
[143] Fix | Delete
</div><!-- #page -->
[144] Fix | Delete
<?php wp_footer(); ?>
[145] Fix | Delete
</body>
[146] Fix | Delete
</html>
[147] Fix | Delete
<?php
[148] Fix | Delete
[149] Fix | Delete
exit;
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
// Use admin_init instead of init to ensure get_current_screen function is already available.
[153] Fix | Delete
// This isn't strictly required, but enables better compatibility with existing plugins.
[154] Fix | Delete
// See: https://github.com/WordPress/gutenberg/issues/32624.
[155] Fix | Delete
add_action( 'admin_init', 'handle_legacy_widget_preview_iframe', 20 );
[156] Fix | Delete
[157] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function