Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gutenberg: Add editor styles to WordPress.com Simple sites' site editor #22640

Merged
merged 7 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' );
Copons marked this conversation as resolved.
Show resolved Hide resolved
$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