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

Disable CSSTidy property shorthand optimization in the editor or headstart #21891

Merged
merged 2 commits into from
Nov 29, 2021
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: bugfix

Custom CSS: disable CSSTidy shorthand optimizations to prevent block validation issues.
8 changes: 3 additions & 5 deletions projects/plugins/jetpack/modules/custom-css/custom-css.php
Original file line number Diff line number Diff line change
Expand Up @@ -1600,11 +1600,9 @@ static function filter_attr( $css, $element = 'div' ) {
$csstidy->set_cfg( 'remove_last_;', false );
$csstidy->set_cfg( 'css_level', 'CSS3.0' );

// Turn off css shorthands and leading zero removal when in block editor context as it breaks block validation.
if ( true === isset( $_REQUEST['_gutenberg_nonce'] ) && wp_verify_nonce( $_REQUEST['_gutenberg_nonce'], 'gutenberg_request' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
$csstidy->set_cfg( 'optimise_shorthands', 0 );
$csstidy->set_cfg( 'preserve_leading_zeros', true );
}
// Turn off css shorthands and leading zero removal as it breaks block validation.
$csstidy->set_cfg( 'optimise_shorthands', 0 );
$csstidy->set_cfg( 'preserve_leading_zeros', true );

$css = preg_replace( '/\\\\([0-9a-fA-F]{4})/', '\\\\\\\\$1', $css );
$css = wp_kses_split( $css, array(), array() );
Expand Down