@@ -25,106 +25,31 @@ function gutenberg_register_layout_support( $block_type ) {
25
25
}
26
26
}
27
27
28
- function gutenberg_generate_common_flow_layout_styles () {
29
- $ style_engine = WP_Style_Engine_Gutenberg::get_instance ();
30
-
31
- $ style_engine ->add_style (
32
- 'wp-layout-flow ' ,
33
- array (
34
- 'selector ' => '.alignleft ' ,
35
- 'rules ' => array (
36
- 'float ' => 'left ' ,
37
- 'margin-right ' => '2em ' ,
38
- 'margin-left ' => '0 ' ,
39
- ),
40
- )
41
- );
42
-
43
- $ style_engine ->add_style (
44
- 'wp-layout-flow ' ,
45
- array (
46
- 'selector ' => '.alignright ' ,
47
- 'rules ' => array (
48
- 'float ' => 'right ' ,
49
- 'margin-left ' => '2em ' ,
50
- 'margin-right ' => '0 ' ,
51
- ),
52
- )
53
- );
54
-
55
- $ style_engine ->add_style (
56
- 'wp-layout-flow ' ,
57
- array (
58
- 'selector ' => '> .alignfull ' ,
59
- 'rules ' => array (
60
- 'max-width ' => 'none ' ,
61
- ),
62
- )
63
- );
64
-
65
- $ style_engine ->add_style (
66
- 'wp-layout-flow--global-gap ' ,
67
- array (
68
- 'selector ' => '> * ' ,
69
- 'rules ' => array (
70
- 'margin-top ' => '0 ' ,
71
- 'margin-bottom ' => '0 ' ,
72
- ),
73
- )
74
- );
75
-
76
- $ style_engine ->add_style (
77
- 'wp-layout-flow--global-gap ' ,
78
- array (
79
- 'selector ' => '> * + * ' ,
80
- 'rules ' => array (
81
- 'margin-top ' => 'var( --wp--style--block-gap ) ' ,
82
- 'margin-bottom ' => '0 ' ,
83
- ),
84
- )
85
- );
86
- }
87
-
88
- function gutenberg_generate_common_flex_layout_styles () {
89
- $ style_engine = WP_Style_Engine_Gutenberg::get_instance ();
90
-
91
- $ style_engine ->add_style (
92
- 'wp-layout-flex ' ,
93
- array (
94
- 'rules ' => array (
95
- 'display ' => 'flex ' ,
96
- 'gap ' => '0.5em ' ,
97
- ),
98
- )
99
- );
100
-
101
- $ style_engine ->add_style (
102
- 'wp-layout-flex ' ,
103
- array (
104
- 'selector ' => '> * ' ,
105
- 'rules ' => array (
106
- 'margin ' => '0 ' ,
107
- ),
108
- )
109
- );
110
- }
111
-
112
28
function gutenberg_get_layout_preset_styles ( $ preset_metadata , $ presets_by_origin ) {
113
- WP_Style_Engine_Gutenberg::get_instance ()->reset ();
29
+ $ style_engine = WP_Style_Engine_Gutenberg::get_instance ();
30
+ $ style_engine ->reset ();
114
31
115
32
$ presets = end ( $ presets_by_origin );
116
33
117
34
foreach ( $ presets as $ preset ) {
118
- if ( isset ( $ preset ['type ' ] ) ) {
119
- if ( 'flow ' === $ preset ['type ' ] ) {
120
- $ output_styles = gutenberg_generate_common_flow_layout_styles ();
121
- } else if ( 'flex ' === $ preset ['type ' ] ) {
122
- $ output_styles = gutenberg_generate_common_flex_layout_styles ();
35
+ if ( ! empty ( $ preset ['type ' ] ) && ! empty ( $ preset ['styles ' ] ) ) {
36
+ $ slug = ! empty ( $ preset ['slug ' ] ) ? $ preset ['slug ' ] : $ preset ['type ' ];
37
+ $ base_class = 'wp-layout- ' . sanitize_title ( $ slug );
38
+
39
+ foreach ( $ preset ['styles ' ] as $ style ) {
40
+ if ( ! empty ( $ style ['rules ' ] ) && is_array ( $ style ['rules ' ] ) ) {
41
+ $ options = array (
42
+ 'selector ' => ! empty ( $ style ['selector ' ] ) ? $ style ['selector ' ] : null ,
43
+ 'suffix ' => ! empty ( $ style ['suffix ' ] ) ? sanitize_title ( $ style ['suffix ' ] ) : null ,
44
+ 'rules ' => $ style ['rules ' ],
45
+ );
46
+ $ style_engine ->add_style ( $ base_class , $ options );
47
+ }
123
48
}
124
49
}
125
50
}
126
51
127
- return WP_Style_Engine_Gutenberg:: get_instance () ->get_generated_styles ();
52
+ return $ style_engine ->get_generated_styles ();
128
53
}
129
54
130
55
/**
0 commit comments