Skip to content

Commit

Permalink
Gutenberg: Add editor styles to WordPress.com Simple sites' site edit…
Browse files Browse the repository at this point in the history
…or (#22640)

Co-authored-by: sdixon194 <steve.dixon@automattic.com>
  • Loading branch information
Copons and sdixon194 authored Feb 9, 2022
1 parent 05f142d commit 2f77f6a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/try-inline_editor_styles
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: enhancement

Added a new method to inline styles in the site editor.
56 changes: 56 additions & 0 deletions projects/plugins/jetpack/class.jetpack-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,62 @@ public static function enqueue_block_editor_assets() {
);
}

/**
* Add the Gutenberg editor stylesheet to iframed editors, such as the site editor,
* which don't have access to stylesheets added with `wp_enqueue_style`.
*
* This workaround is currently used by WordPress.com Simple sites.
*
* @since $$next-version$$
*
* @return void
*/
public static function add_iframed_editor_style() {
if ( ! self::should_load() ) {
return;
}

global $pagenow;
if ( ! isset( $pagenow ) ) {
return;
}

$allowed_pages = array( 'admin.php', 'themes.php' );
$is_site_editor_page = in_array( $pagenow, $allowed_pages, true ) &&
isset( $_GET['page'] ) && 'gutenberg-edit-site' === $_GET['page']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended

// WP 5.9 puts the site editor in `site-editor.php` when Gutenberg is not active.
if ( 'site-editor.php' !== $pagenow && ! $is_site_editor_page ) {
return;
}

$blocks_dir = self::get_blocks_directory();
$blocks_variation = self::blocks_variation();

if ( 'production' !== $blocks_variation ) {
$blocks_env = '-' . esc_attr( $blocks_variation );
} else {
$blocks_env = '';
}

$path = "{$blocks_dir}editor{$blocks_env}.css";
$dir = dirname( JETPACK__PLUGIN_FILE );

if ( file_exists( "$dir/$path" ) ) {
if ( is_rtl() ) {
$rtlcsspath = substr( $path, 0, -4 ) . '.rtl.css';
if ( file_exists( "$dir/$rtlcsspath" ) ) {
$path = $rtlcsspath;
}
}

$url = Assets::normalize_path( plugins_url( $path, JETPACK__PLUGIN_FILE ) );
$url = add_query_arg( 'minify', 'false', $url );

add_editor_style( $url );
}
}

/**
* Some blocks do not depend on a specific module,
* and can consequently be loaded outside of the usual modules.
Expand Down

0 comments on commit 2f77f6a

Please sign in to comment.