PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.2.0
GenerateBlocks v2.2.0
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / includes / class-map-deprecated-attributes.php
generateblocks / includes Last commit date
blocks 1 year ago dynamic-tags 6 months ago pattern-library 1 year ago utils 2 years ago class-do-css.php 2 years ago class-dynamic-content.php 6 months ago class-dynamic-tag-security.php 6 months ago class-enqueue-css.php 1 year ago class-legacy-attributes.php 4 years ago class-map-deprecated-attributes.php 2 years ago class-meta-handler.php 6 months ago class-plugin-update.php 1 year ago class-query-loop.php 2 years ago class-query-utils.php 6 months ago class-render-blocks.php 1 year ago class-rest.php 1 year ago class-settings.php 1 year ago dashboard.php 1 year ago defaults.php 1 year ago deprecated.php 1 year ago functions.php 6 months ago general.php 8 months ago
class-map-deprecated-attributes.php
244 lines
1 <?php
2 /**
3 * Maps our old attributes to their new attribute names.
4 *
5 * @package GenerateBlocks
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 /**
13 * Map our deprecated attributes.
14 */
15 class GenerateBlocks_Map_Deprecated_Attributes {
16 /**
17 * Class instance.
18 *
19 * @access private
20 * @var $instance Class instance.
21 */
22 private static $instance;
23
24 /**
25 * Our devices.
26 *
27 * @access private
28 * @var $devices List of devices.
29 */
30 private static $devices = [ '', 'Tablet', 'Mobile' ];
31
32 /**
33 * Initiator
34 */
35 public static function get_instance() {
36 if ( ! isset( self::$instance ) ) {
37 self::$instance = new self();
38 }
39 return self::$instance;
40 }
41
42 /**
43 * Get all of our mapped attributes.
44 *
45 * @param array $settings Existing settings.
46 * @return array Mapped settings.
47 */
48 public static function map_attributes( $settings ) {
49 $settings = self::map_spacing( $settings );
50 $settings = self::map_borders( $settings );
51 $settings = self::map_typography( $settings );
52
53 return $settings;
54 }
55
56 /**
57 * Map our old spacing attributes.
58 *
59 * @param array $settings Existing settings.
60 * @return array Mapped spacing settings.
61 */
62 public static function map_spacing( $settings ) {
63 if ( ! empty( $settings['spacing'] ) ) {
64 return $settings;
65 }
66
67 $padding_attributes = [
68 'paddingTop',
69 'paddingRight',
70 'paddingBottom',
71 'paddingLeft',
72 ];
73
74 $margin_attributes = [
75 'marginTop',
76 'marginRight',
77 'marginBottom',
78 'marginLeft',
79 ];
80
81 foreach ( self::$devices as $device ) {
82 foreach ( $padding_attributes as $attribute ) {
83 $setting_name = $attribute . $device;
84
85 if ( $settings[ $setting_name ] || is_numeric( $settings[ $setting_name ] ) ) {
86 $unit = is_numeric( $settings[ $setting_name ] )
87 ? $settings['paddingUnit']
88 : '';
89
90 $settings['spacing'][ $setting_name ] = $settings[ $setting_name ] . $unit;
91 }
92 }
93
94 foreach ( $margin_attributes as $attribute ) {
95 $setting_name = $attribute . $device;
96
97 if ( $settings[ $setting_name ] || is_numeric( $settings[ $setting_name ] ) ) {
98 $unit = is_numeric( $settings[ $setting_name ] )
99 ? $settings['marginUnit']
100 : '';
101
102 $settings['spacing'][ $setting_name ] = $settings[ $setting_name ] . $unit;
103 }
104 }
105 }
106
107 return $settings;
108 }
109
110 /**
111 * Map our old border attributes.
112 *
113 * @param array $settings Existing settings.
114 * @return array Mapped border settings.
115 */
116 public static function map_borders( $settings ) {
117 if ( ! empty( $settings['borders'] ) ) {
118 return $settings;
119 }
120
121 $border_radius_attributes = [
122 'borderRadiusTopLeft' => 'borderTopLeftRadius',
123 'borderRadiusTopRight' => 'borderTopRightRadius',
124 'borderRadiusBottomRight' => 'borderBottomRightRadius',
125 'borderRadiusBottomLeft' => 'borderBottomLeftRadius',
126 ];
127
128 foreach ( self::$devices as $device ) {
129 foreach ( $border_radius_attributes as $old_attribute_name => $new_attribute_name ) {
130 $setting_name = $old_attribute_name . $device;
131
132 if ( $settings[ $setting_name ] || is_numeric( $settings[ $setting_name ] ) ) {
133 $unit = is_numeric( $settings[ $setting_name ] )
134 ? $settings['borderRadiusUnit']
135 : '';
136
137 $settings['borders'][ $new_attribute_name . $device ] = $settings[ $setting_name ] . $unit;
138 }
139 }
140 }
141
142 $border_width_attributes = [
143 'borderSizeTop' => 'borderTopWidth',
144 'borderSizeRight' => 'borderRightWidth',
145 'borderSizeBottom' => 'borderBottomWidth',
146 'borderSizeLeft' => 'borderLeftWidth',
147 ];
148
149 foreach ( self::$devices as $device ) {
150 foreach ( $border_width_attributes as $old_attribute_name => $new_attribute_name ) {
151 $setting_name = $old_attribute_name . $device;
152
153 if ( $settings[ $setting_name ] || is_numeric( $settings[ $setting_name ] ) ) {
154 $unit = is_numeric( $settings[ $setting_name ] )
155 ? 'px'
156 : '';
157
158 $settings['borders'][ $new_attribute_name . $device ] = $settings[ $setting_name ] . $unit;
159
160 $border_style_name = str_replace( 'Width', 'Style', $new_attribute_name );
161 $settings['borders'][ $border_style_name . $device ] = 'solid';
162
163 if ( ! empty( $settings['borderColor'] ) ) {
164 $border_color_name = str_replace( 'Width', 'Color', $new_attribute_name );
165 $settings['borders'][ $border_color_name ] = isset( $settings['borderColorOpacity'] )
166 ? generateblocks_hex2rgba( $settings['borderColor'], $settings['borderColorOpacity'] )
167 : $settings['borderColor'];
168 }
169
170 if ( ! empty( $settings['borderColorHover'] ) ) {
171 $border_color_hover_name = str_replace( 'Width', 'ColorHover', $new_attribute_name );
172 $settings['borders'][ $border_color_hover_name ] = isset( $settings['borderColorHoverOpacity'] )
173 ? generateblocks_hex2rgba( $settings['borderColorHover'], $settings['borderColorHoverOpacity'] )
174 : $settings['borderColorHover'];
175 }
176
177 if ( ! empty( $settings['borderColorCurrent'] ) ) {
178 $border_color_current_name = str_replace( 'Width', 'ColorCurrent', $new_attribute_name );
179 $settings['borders'][ $border_color_current_name ] = $settings['borderColorCurrent'];
180 }
181 }
182 }
183 }
184
185 return $settings;
186 }
187
188 /**
189 * Map our old typography attributes.
190 *
191 * @param array $settings Existing settings.
192 * @return array Mapped spacing settings.
193 */
194 public static function map_typography( $settings ) {
195 if ( ! empty( $settings['typography'] ) ) {
196 return $settings;
197 }
198
199 $old_attributes = [
200 'fontFamily',
201 'fontSize',
202 'lineHeight',
203 'letterSpacing',
204 'fontWeight',
205 'textTransform',
206 'alignment',
207 ];
208
209 foreach ( self::$devices as $device ) {
210 foreach ( $old_attributes as $attribute ) {
211 $setting_name = $attribute . $device;
212
213 if ( isset( $settings[ $setting_name ] ) && ( $settings[ $setting_name ] || is_numeric( $settings[ $setting_name ] ) ) ) {
214 $unit = '';
215
216 switch ( $attribute ) {
217 case 'fontSize':
218 $unit = $settings['fontSizeUnit'];
219 break;
220
221 case 'lineHeight':
222 $unit = $settings['lineHeightUnit'];
223 break;
224
225 case 'letterSpacing':
226 $unit = 'em';
227 break;
228 }
229
230 // textAlign used to be called "alignment".
231 if ( 'alignment' === $attribute ) {
232 $settings['typography'][ 'textAlign' . $device ] = $settings[ $setting_name ];
233 continue;
234 }
235
236 $settings['typography'][ $setting_name ] = $settings[ $setting_name ] . $unit;
237 }
238 }
239 }
240
241 return $settings;
242 }
243 }
244