Skip to content

Commit

Permalink
Add checks for other code generation output
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Lende committed Apr 11, 2023
1 parent e874e41 commit 10fd25d
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions lib/class-wp-duotone-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,9 @@ private static function get_css_var( $slug ) {
* Outputs all necessary SVG for duotone filters, CSS for classic themes.
*/
public static function output_footer_assets() {
echo self::get_svg_definitions( self::$used_svg_filter_data );
if ( ! empty( self::$used_svg_filter_data ) ) {
echo self::get_svg_definitions( self::$used_svg_filter_data );
}

// This is for classic themes - in block themes, the CSS is added in the head via wp_add_inline_style in the wp_enqueue_scripts action.
if ( ! wp_is_block_theme() && ! empty( self::$used_global_styles_presets ) ) {
Expand All @@ -666,27 +668,29 @@ public static function output_footer_assets() {
* @return array The editor settings with duotone SVGs and CSS custom properties.
*/
public static function add_editor_settings( $settings ) {
if ( ! isset( $settings['styles'] ) ) {
$settings['styles'] = array();
}
if ( ! empty( self::$global_styles_presets ) ) {
if ( ! isset( $settings['styles'] ) ) {
$settings['styles'] = array();
}

$settings['styles'][] = array(
// For the editor we can add all of the presets by default.
'assets' => self::get_svg_definitions( self::$global_styles_presets ),
// The 'svgs' type is new in 6.3 and requires the corresponding JS changes in the EditorStyles component to work.
'__unstableType' => 'svgs',
// These styles not generated by global styles, so this must be false or they will be stripped out in gutenberg_get_block_editor_settings.
'isGlobalStyles' => false,
);
$settings['styles'][] = array(
// For the editor we can add all of the presets by default.
'assets' => self::get_svg_definitions( self::$global_styles_presets ),
// The 'svgs' type is new in 6.3 and requires the corresponding JS changes in the EditorStyles component to work.
'__unstableType' => 'svgs',
// These styles not generated by global styles, so this must be false or they will be stripped out in gutenberg_get_block_editor_settings.
'isGlobalStyles' => false,
);

$settings['styles'][] = array(
// For the editor we can add all of the presets by default.
'css' => self::get_global_styles_presets( self::$global_styles_presets ),
// This must be set and must be something other than 'theme' or they will be stripped out in the post editor <Editor> component.
'__unstableType' => 'presets',
// These styles are no longer generated by global styles, so this must be false or they will be stripped out in gutenberg_get_block_editor_settings.
'isGlobalStyles' => false,
);
$settings['styles'][] = array(
// For the editor we can add all of the presets by default.
'css' => self::get_global_styles_presets( self::$global_styles_presets ),
// This must be set and must be something other than 'theme' or they will be stripped out in the post editor <Editor> component.
'__unstableType' => 'presets',
// These styles are no longer generated by global styles, so this must be false or they will be stripped out in gutenberg_get_block_editor_settings.
'isGlobalStyles' => false,
);
}

return $settings;
}
Expand All @@ -704,12 +708,14 @@ public static function output_global_styles() {
* Appends the used block duotone filter declarations to the inline block supports CSS.
*/
public static function output_block_styles() {
gutenberg_style_engine_get_stylesheet_from_css_rules(
self::$block_css_declarations,
array(
'context' => 'block-supports',
)
);
if ( ! empty( self::$block_css_declarations ) ) {
gutenberg_style_engine_get_stylesheet_from_css_rules(
self::$block_css_declarations,
array(
'context' => 'block-supports',
)
);
}
}

/**
Expand Down

0 comments on commit 10fd25d

Please sign in to comment.