Changeset 12085 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-patterns/functions.php
- Timestamp:
- 09/26/2022 06:03:26 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-patterns/functions.php
r12024 r12085 7 7 use function WordPressdotorg\MU_Plugins\Global_Header_Footer\{ is_rosetta_site, get_rosetta_name }; 8 8 9 require_once __DIR__ . '/includes/inline-styles.php';10 11 9 add_action( 'after_setup_theme', __NAMESPACE__ . '\setup' ); 12 10 add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_assets', 20 ); 13 add_action( 'wp_head', __NAMESPACE__ . '\generate_block_editor_styles_html' );14 11 add_action( 'wp_head', __NAMESPACE__ . '\add_social_meta_tags' ); 15 12 add_filter( 'document_title_parts', __NAMESPACE__ . '\set_document_title' ); … … 120 117 121 118 wp_enqueue_script( 'wporg-navigation', get_template_directory_uri() . "/js/navigation$suffix.js", array(), '20210331', true ); 122 }123 124 /**125 * Generate styles used in the block pattern preview iframe.126 * See https://github.com/WordPress/gutenberg/blob/6ad2a433769a4514fc52083e97aa47a0bc9edf07/lib/client-assets.php#L710127 */128 function generate_block_editor_styles_html() {129 wp_enqueue_global_styles();130 $handles = array( 'wp-block-library', 'global-styles' );131 132 $block_registry = \WP_Block_Type_Registry::get_instance();133 134 foreach ( $block_registry->get_all_registered() as $block_type ) {135 if ( ! empty( $block_type->style ) ) {136 $handles[] = $block_type->style;137 }138 139 if ( ! empty( $block_type->editor_style ) ) {140 $handles[] = $block_type->editor_style;141 }142 }143 144 $handles = array_unique( $handles );145 $done = wp_styles()->done;146 147 ob_start();148 149 wp_styles()->done = array();150 wp_styles()->do_items( $handles );151 wp_styles()->done = $done;152 153 wp_add_inline_script(154 'wporg-pattern-script',155 sprintf(156 'window.__editorStyles = JSON.parse( decodeURIComponent( \'%s\' ) );',157 rawurlencode( wp_json_encode( array( 'html' => ob_get_clean() ) ) )158 ),159 'before'160 );161 162 wp_dequeue_style( 'global-styles' );163 wp_deregister_style( 'global-styles' );164 119 } 165 120
Note: See TracChangeset
for help on using the changeset viewer.