@@ -24,6 +24,13 @@ class Settings_Controller {
24
24
*/
25
25
private Theme_Controller $ theme_controller ;
26
26
27
+ /**
28
+ * Allowed iframe style handles.
29
+ *
30
+ * @var string[]
31
+ */
32
+ private array $ allowed_iframe_style_handles = array ();
33
+
27
34
/**
28
35
* Assets for iframe editor (component styles, scripts, etc.)
29
36
*
@@ -55,10 +62,11 @@ public function get_settings(): array {
55
62
56
63
$ settings = array_merge ( $ core_default_settings , self ::DEFAULT_SETTINGS );
57
64
// Assets for iframe editor (component styles, scripts, etc.).
58
- $ settings ['__unstableResolvedAssets ' ] = $ this ->iframe_assets ;
59
- $ editor_content_styles = file_get_contents ( __DIR__ . '/content-editor.css ' );
60
- $ shares_content_styles = file_get_contents ( __DIR__ . '/content-shared.css ' );
61
- $ settings ['styles ' ] = array (
65
+ $ settings ['__unstableResolvedAssets ' ] = $ this ->iframe_assets ;
66
+ $ settings ['allowedIframeStyleHandles ' ] = $ this ->allowed_iframe_style_handles ;
67
+ $ editor_content_styles = file_get_contents ( __DIR__ . '/content-editor.css ' );
68
+ $ shares_content_styles = file_get_contents ( __DIR__ . '/content-shared.css ' );
69
+ $ settings ['styles ' ] = array (
62
70
array ( 'css ' => $ editor_content_styles ),
63
71
array ( 'css ' => $ shares_content_styles ),
64
72
);
@@ -180,6 +188,42 @@ public function translate_slug_to_color( string $color_slug ): string {
180
188
return $ this ->theme_controller ->translate_slug_to_color ( $ color_slug );
181
189
}
182
190
191
+ /**
192
+ * Get the allowed iframe style handles.
193
+ *
194
+ * @return array
195
+ */
196
+ private function get_allowed_iframe_style_handles () {
197
+ // Core style handles.
198
+ $ allowed_iframe_style_handles = array (
199
+ 'wp-components-css ' ,
200
+ 'wp-reset-editor-styles-css ' ,
201
+ 'wp-block-library-css ' ,
202
+ 'wp-block-editor-content-css ' ,
203
+ 'wp-edit-blocks-css ' ,
204
+ );
205
+
206
+ foreach ( \WP_Block_Type_Registry::get_instance ()->get_all_registered () as $ block ) {
207
+ if ( ! isset ( $ block ->supports ['email ' ] ) || ! $ block ->supports ['email ' ] ) {
208
+ continue ;
209
+ }
210
+
211
+ if ( strpos ( $ block ->name , 'core/ ' ) !== false ) {
212
+ continue ;
213
+ }
214
+
215
+ foreach ( $ block ->style_handles as $ handle ) {
216
+ $ allowed_iframe_style_handles [] = $ handle . '-css ' ;
217
+ }
218
+
219
+ foreach ( $ block ->editor_style_handles as $ handle ) {
220
+ $ allowed_iframe_style_handles [] = $ handle . '-css ' ;
221
+ }
222
+ }
223
+
224
+ return apply_filters ( 'woocommerce_email_editor_allowed_iframe_style_handles ' , $ allowed_iframe_style_handles );
225
+ }
226
+
183
227
/**
184
228
* Method to initialize iframe assets.
185
229
*
@@ -190,20 +234,19 @@ private function init_iframe_assets(): void {
190
234
return ;
191
235
}
192
236
193
- $ this ->iframe_assets = _wp_get_iframed_editor_assets ();
237
+ $ this ->iframe_assets = _wp_get_iframed_editor_assets ();
238
+ $ this ->allowed_iframe_style_handles = $ this ->get_allowed_iframe_style_handles ();
194
239
195
- // Remove layout styles and block library for classic themes. They are added only when a classic theme is active
196
- // and they add unwanted margins and paddings in the editor content.
197
240
$ cleaned_styles = array ();
198
241
foreach ( explode ( "\n" , (string ) $ this ->iframe_assets ['styles ' ] ) as $ asset ) {
199
- if ( strpos ( $ asset , 'wp-editor-classic-layout-styles-css ' ) !== false ) {
200
- continue ;
242
+ foreach ( $ this ->allowed_iframe_style_handles as $ handle ) {
243
+ if ( strpos ( $ asset , $ handle ) !== false ) {
244
+ $ cleaned_styles [] = $ asset ;
245
+ break ;
246
+ }
201
247
}
202
- if ( strpos ( $ asset , 'wp-block-library-theme-css ' ) !== false ) {
203
- continue ;
204
- }
205
- $ cleaned_styles [] = $ asset ;
206
248
}
249
+
207
250
$ this ->iframe_assets ['styles ' ] = implode ( "\n" , $ cleaned_styles );
208
251
}
209
252
}
0 commit comments