-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Plugin: Extract block editor styles replacement as filter #13625
Conversation
lib/client-assets.php
Outdated
* own custom styles, it's assumed that the first entry of the styles | ||
* setting should be the default (core) stylesheet. | ||
*/ | ||
array_shift( $settings['styles'] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it's simpler to just loop over the styles are replace the core editor styles if found (checking the path or something).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace the core editor styles if found (checking the path or something).
The problem is that the array contains only the CSS string, no file paths.
It looks something like:
$settings = array(
'styles' => array(
array( 'css' => 'body { /* ... */ }' )
)
);
So we've got nothing to work from to know whether it's the core style, unless we explicitly (re-)read the ABSPATH . WPINC . '/css/dist/editor/editor-styles.css'
file from disk and compare it with the array style contents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just do that.
Default styles matching made more reliable in d4be401 by exact file contents match. Fun testing instructions:
|
* Plugin: Extract block editor styles replacement as filter * Plugin: Override default styles by exact file contents match * Plugin: Fix editor styles prepend behavior
* Plugin: Extract block editor styles replacement as filter * Plugin: Override default styles by exact file contents match * Plugin: Fix editor styles prepend behavior
Extracted from: #13569
Related: #9008
This pull request seeks to implement Gutenberg's replacement
editor-styles
setting value as a filter onblock_settings
. This was allow for compatibility with the core implementation once Gutenberg stops reimplementing its own replacement editor (#13569).Implementation notes:
The change to assign
$styles
withABSPATH . WPINC . '/css/dist/editor/editor-styles.css'
is merely meant to provide direct alignment to the core implementation. It's never actually used, since the filtering behavior will substitute the styles with its own implementation. But it needs to exist because the filtering assumes that the styles would be the first entry of the default$settings['styles']
array. Unfortunately, we must operate on assumptions since the entries of styles are the contents of the stylesheets themselves, not named or assigned as paths. An alternative implementation could consider reading from theABSPATH . WPINC
to find and substitute the value by the actual file contents assigned, but there'd be a small amount of overhead in reading from the filesystem.Testing instructions:
Verify that the contents of the built copy of
packages/editor/src/editor-styles
are present on the page. This may require inspecting the source of the page. It's easier to verify that it's in-fact the Gutenberg copy by making a change to the source file and rebuilding it.Additionally, verify that the separate locale font family assignment (
font-family: 'Noto Serif'
) is not impacted by these changes, meaning that it is still present and occurs after theeditor-styles.css
.