| @@ -40,36 +40,43 @@ | ||
| 40 | 40 | $global_styles[] = $preset_style; |
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - $block_classes = array( | |
| 45 | - 'css' => 'styles', | |
| 46 | - '__unstableType' => 'theme', | |
| 47 | - 'isGlobalStyles' => true, | |
| 48 | - ); | |
| 49 | - $actual_css = gutenberg_get_global_stylesheet( array( $block_classes['css'] ) ); | |
| 50 | - if ( '' !== $actual_css ) { | |
| 51 | - $block_classes['css'] = $actual_css; | |
| 52 | - $global_styles[] = $block_classes; | |
| 44 | + if ( wp_theme_has_theme_json() ) { | |
| 45 | + $block_classes = array( | |
| 46 | + 'css' => 'styles', | |
| 47 | + '__unstableType' => 'theme', | |
| 48 | + 'isGlobalStyles' => true, | |
| 49 | + ); | |
| 50 | + $actual_css = gutenberg_get_global_stylesheet( array( $block_classes['css'] ) ); | |
| 51 | + if ( '' !== $actual_css ) { | |
| 52 | + $block_classes['css'] = $actual_css; | |
| 53 | + $global_styles[] = $block_classes; | |
| 54 | + } | |
| 55 | + | |
| 56 | + /* | |
| 57 | + * Add the custom CSS as a separate stylesheet so any invalid CSS | |
| 58 | + * entered by users does not break other global styles. | |
| 59 | + */ | |
| 60 | + $global_styles[] = array( | |
| 61 | + 'css' => gutenberg_get_global_styles_custom_css(), | |
| 62 | + '__unstableType' => 'user', | |
| 63 | + 'isGlobalStyles' => true, | |
| 64 | + ); | |
| 65 | + } else { | |
| 66 | + // If there is no `theme.json` file, ensure base layout styles are still available. | |
| 67 | + $block_classes = array( | |
| 68 | + 'css' => 'base-layout-styles', | |
| 69 | + '__unstableType' => 'base-layout', | |
| 70 | + 'isGlobalStyles' => true, | |
| 71 | + ); | |
| 72 | + $actual_css = gutenberg_get_global_stylesheet( array( $block_classes['css'] ) ); | |
| 73 | + if ( '' !== $actual_css ) { | |
| 74 | + $block_classes['css'] = $actual_css; | |
| 75 | + $global_styles[] = $block_classes; | |
| 76 | + } | |
| 53 | 77 | } |
| 54 | 78 | |
| 55 | - // Get any additional css from the customizer and add it before global styles custom CSS. | |
| 56 | - $global_styles[] = array( | |
| 57 | - 'css' => wp_get_custom_css(), | |
| 58 | - '__unstableType' => 'user', | |
| 59 | - 'isGlobalStyles' => false, | |
| 60 | - ); | |
| 61 | - | |
| 62 | - /* | |
| 63 | - * Add the custom CSS as a separate stylesheet so any invalid CSS | |
| 64 | - * entered by users does not break other global styles. | |
| 65 | - */ | |
| 66 | - $global_styles[] = array( | |
| 67 | - 'css' => gutenberg_get_global_stylesheet( array( 'custom-css' ) ), | |
| 68 | - '__unstableType' => 'user', | |
| 69 | - 'isGlobalStyles' => true, | |
| 70 | - ); | |
| 71 | - | |
| 72 | 79 | $settings['styles'] = array_merge( $global_styles, get_block_editor_theme_styles() ); |
| 73 | 80 | |
| 74 | 81 | $settings['__experimentalFeatures'] = gutenberg_get_global_settings(); |
| 75 | 82 | // These settings may need to be updated based on data coming from theme.json sources. |
| @@ -74,17 +81,32 @@ | ||
| 74 | 81 | $settings['__experimentalFeatures'] = gutenberg_get_global_settings(); |
| 75 | 82 | // These settings may need to be updated based on data coming from theme.json sources. |
| 76 | 83 | if ( isset( $settings['__experimentalFeatures']['color']['palette'] ) ) { |
| 77 | 84 | $colors_by_origin = $settings['__experimentalFeatures']['color']['palette']; |
| 78 | - $settings['colors'] = $colors_by_origin['custom'] ?? $colors_by_origin['theme'] ?? $colors_by_origin['default']; | |
| 85 | + $settings['colors'] = isset( $colors_by_origin['custom'] ) ? | |
| 86 | + $colors_by_origin['custom'] : ( | |
| 87 | + isset( $colors_by_origin['theme'] ) ? | |
| 88 | + $colors_by_origin['theme'] : | |
| 89 | + $colors_by_origin['default'] | |
| 90 | + ); | |
| 79 | 91 | } |
| 80 | 92 | if ( isset( $settings['__experimentalFeatures']['color']['gradients'] ) ) { |
| 81 | 93 | $gradients_by_origin = $settings['__experimentalFeatures']['color']['gradients']; |
| 82 | - $settings['gradients'] = $gradients_by_origin['custom'] ?? $gradients_by_origin['theme'] ?? $gradients_by_origin['default']; | |
| 94 | + $settings['gradients'] = isset( $gradients_by_origin['custom'] ) ? | |
| 95 | + $gradients_by_origin['custom'] : ( | |
| 96 | + isset( $gradients_by_origin['theme'] ) ? | |
| 97 | + $gradients_by_origin['theme'] : | |
| 98 | + $gradients_by_origin['default'] | |
| 99 | + ); | |
| 83 | 100 | } |
| 84 | 101 | if ( isset( $settings['__experimentalFeatures']['typography']['fontSizes'] ) ) { |
| 85 | 102 | $font_sizes_by_origin = $settings['__experimentalFeatures']['typography']['fontSizes']; |
| 86 | - $settings['fontSizes'] = $font_sizes_by_origin['custom'] ?? $font_sizes_by_origin['theme'] ?? $font_sizes_by_origin['default']; | |
| 103 | + $settings['fontSizes'] = isset( $font_sizes_by_origin['custom'] ) ? | |
| 104 | + $font_sizes_by_origin['custom'] : ( | |
| 105 | + isset( $font_sizes_by_origin['theme'] ) ? | |
| 106 | + $font_sizes_by_origin['theme'] : | |
| 107 | + $font_sizes_by_origin['default'] | |
| 108 | + ); | |
| 87 | 109 | } |
| 88 | 110 | if ( isset( $settings['__experimentalFeatures']['color']['custom'] ) ) { |
| 89 | 111 | $settings['disableCustomColors'] = ! $settings['__experimentalFeatures']['color']['custom']; |
| 90 | 112 | unset( $settings['__experimentalFeatures']['color']['custom'] ); |
| @@ -115,12 +137,15 @@ | ||
| 115 | 137 | } |
| 116 | 138 | |
| 117 | 139 | if ( isset( $settings['__experimentalFeatures']['spacing']['spacingSizes'] ) ) { |
| 118 | 140 | $spacing_sizes_by_origin = $settings['__experimentalFeatures']['spacing']['spacingSizes']; |
| 119 | - $settings['spacingSizes'] = $spacing_sizes_by_origin['custom'] ?? $spacing_sizes_by_origin['theme'] ?? $spacing_sizes_by_origin['default']; | |
| 141 | + $settings['spacingSizes'] = isset( $spacing_sizes_by_origin['custom'] ) ? | |
| 142 | + $spacing_sizes_by_origin['custom'] : ( | |
| 143 | + isset( $spacing_sizes_by_origin['theme'] ) ? | |
| 144 | + $spacing_sizes_by_origin['theme'] : | |
| 145 | + $spacing_sizes_by_origin['default'] | |
| 146 | + ); | |
| 120 | 147 | } |
| 121 | - | |
| 122 | - $settings['canEditCSS'] = current_user_can( 'edit_css' ); | |
| 123 | 148 | |
| 124 | 149 | return $settings; |
| 125 | 150 | } |
| 126 | 151 | add_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings', 0 ); |