/** * Intercepts any request with legacy-widget-preview in the query param and, if * set, renders a page containing a preview of the requested Legacy Widget * block. * * @since 5.8.0 */ function handle_legacy_widget_preview_iframe() { if ( empty( $_GET['legacy-widget-preview'] ) ) { return; }
if ( ! current_user_can( 'edit_theme_options' ) ) { return; }
// Use admin_init instead of init to ensure get_current_screen function is already available. // This isn't strictly required, but enables better compatibility with existing plugins. // See: https://github.com/WordPress/gutenberg/issues/32624. add_action( 'admin_init', 'handle_legacy_widget_preview_iframe', 20 );