Skip to content

Commit

Permalink
Add gutenberg_get_editor_styles() from Gutenberg 13.6 (#509)
Browse files Browse the repository at this point in the history
  • Loading branch information
dd32 authored Jul 21, 2022
1 parent 6b7601f commit b49448e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions public_html/wp-content/plugins/pattern-creator/pattern-creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,40 @@ function add_theme_styles_to_editor( $settings ) {
return $settings;
}
add_filter( 'block_editor_settings_all', __NAMESPACE__ . '\add_theme_styles_to_editor', 20 );

/**
* Load editor styles (this is copied from Gutenberg 13.6).
*
* @see https://github.com/WordPress/gutenberg/blob/release/13.6/lib/compat/wordpress-5.9/edit-site-page.php#L43-L77
*
* @return array Editor Styles Setting.
*/
function gutenberg_get_editor_styles() {
global $editor_styles;

// Ideally the code is extracted into a reusable function.
$styles = array();

if ( $editor_styles && current_theme_supports( 'editor-styles' ) ) {
foreach ( $editor_styles as $style ) {
if ( preg_match( '~^(https?:)?//~', $style ) ) {
$response = wp_remote_get( $style );
if ( ! is_wp_error( $response ) ) {
$styles[] = array(
'css' => wp_remote_retrieve_body( $response ),
);
}
} else {
$file = get_theme_file_path( $style );
if ( is_file( $file ) ) {
$styles[] = array(
'css' => file_get_contents( $file ),
'baseURL' => get_theme_file_uri( $style ),
);
}
}
}
}

return $styles;
}

0 comments on commit b49448e

Please sign in to comment.