PluginProbe
YayMail – WooCommerce Email Customizer / 4.3.2
YayMail – WooCommerce Email Customizer v4.3.2
4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 3.4.2 3.4.3 All 55 releases
yaymail / src / Utils / Helpers.php

Helpers.php in YayMail – WooCommerce Email Customizer 4.3.2, at src/Utils/Helpers.php

485 lines 24.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YayMail\Utils;
4
5 defined( 'ABSPATH' ) || exit;
6
7 /**
8 * Helpers Classes
9 */
10 class Helpers {
11
12 // TODO: need to refactor this function
13 public static function prevent_xss_elements( $elements ) {
14 foreach ( $elements as $key => $element ) {
15 if ( isset( $element['settingRow']['content'] ) ) {
16 $elements[ $key ]['settingRow']['content'] = wp_kses_post( html_entity_decode( $element['settingRow']['content'], ENT_COMPAT, 'UTF-8' ) );
17 }
18 if ( isset( $element['settingRow']['contentTitle'] ) ) {
19 $elements[ $key ]['settingRow']['contentTitle'] = wp_kses_post( html_entity_decode( $element['settingRow']['contentTitle'], ENT_COMPAT, 'UTF-8' ) );
20 }
21 if ( isset( $element['settingRow']['contentAfter'] ) ) {
22 $elements[ $key ]['settingRow']['contentAfter'] = wp_kses_post( html_entity_decode( $element['settingRow']['contentAfter'], ENT_COMPAT, 'UTF-8' ) );
23 }
24 if ( isset( $element['settingRow']['contentBefore'] ) ) {
25 $elements[ $key ]['settingRow']['contentBefore'] = wp_kses_post( html_entity_decode( $element['settingRow']['contentBefore'], ENT_COMPAT, 'UTF-8' ) );
26 }
27 if ( isset( $element['settingRow']['col1TtContent'] ) ) {
28 $elements[ $key ]['settingRow']['col1TtContent'] = wp_kses_post( html_entity_decode( $element['settingRow']['col1TtContent'], ENT_COMPAT, 'UTF-8' ) );
29 }
30 if ( isset( $element['settingRow']['col2TtContent'] ) ) {
31 $elements[ $key ]['settingRow']['col2TtContent'] = wp_kses_post( html_entity_decode( $element['settingRow']['col2TtContent'], ENT_COMPAT, 'UTF-8' ) );
32 }
33 if ( isset( $element['settingRow']['col3TtContent'] ) ) {
34 $elements[ $key ]['settingRow']['col3TtContent'] = wp_kses_post( html_entity_decode( $element['settingRow']['col3TtContent'], ENT_COMPAT, 'UTF-8' ) );
35 }
36 if ( isset( $element['settingRow']['HTMLContent'] ) ) {
37 $elements[ $key ]['settingRow']['HTMLContent'] = wp_kses_post( html_entity_decode( $element['settingRow']['HTMLContent'], ENT_COMPAT, 'UTF-8' ) );
38 }
39 if ( isset( $element['settingRow']['col2Content'] ) ) {
40 $elements[ $key ]['settingRow']['col2Content'] = wp_kses_post( html_entity_decode( $element['settingRow']['col2Content'], ENT_COMPAT, 'UTF-8' ) );
41 }
42
43 // for column
44 // column1
45 if ( isset( $element['settingRow']['column1'] ) ) {
46 foreach ( $element['settingRow']['column1'] as $key1 => $element1 ) {
47 if ( isset( $element1['settingRow']['content'] ) ) {
48 $elements[ $key ]['settingRow']['column1'][ $key1 ]['settingRow']['content'] = wp_kses_post( html_entity_decode( $element1['settingRow']['content'], ENT_COMPAT, 'UTF-8' ) );
49 }
50 if ( isset( $element1['settingRow']['contentTitle'] ) ) {
51 $elements[ $key ]['settingRow']['column1'][ $key1 ]['settingRow']['contentTitle'] = wp_kses_post( html_entity_decode( $element1['settingRow']['contentTitle'], ENT_COMPAT, 'UTF-8' ) );
52 }
53 if ( isset( $element1['settingRow']['contentAfter'] ) ) {
54 $elements[ $key ]['settingRow']['column1'][ $key1 ]['settingRow']['contentAfter'] = wp_kses_post( html_entity_decode( $element1['settingRow']['contentAfter'], ENT_COMPAT, 'UTF-8' ) );
55 }
56 if ( isset( $element1['settingRow']['contentBefore'] ) ) {
57 $elements[ $key ]['settingRow']['column1'][ $key1 ]['settingRow']['contentBefore'] = wp_kses_post( html_entity_decode( $element1['settingRow']['contentBefore'], ENT_COMPAT, 'UTF-8' ) );
58 }
59 if ( isset( $element1['settingRow']['col1TtContent'] ) ) {
60 $elements[ $key ]['settingRow']['column1'][ $key1 ]['settingRow']['col1TtContent'] = wp_kses_post( html_entity_decode( $element1['settingRow']['col1TtContent'], ENT_COMPAT, 'UTF-8' ) );
61 }
62 if ( isset( $element1['settingRow']['col2TtContent'] ) ) {
63 $elements[ $key ]['settingRow']['column1'][ $key1 ]['settingRow']['col2TtContent'] = wp_kses_post( html_entity_decode( $element1['settingRow']['col2TtContent'], ENT_COMPAT, 'UTF-8' ) );
64 }
65 if ( isset( $element1['settingRow']['col3TtContent'] ) ) {
66 $elements[ $key ]['settingRow']['column1'][ $key1 ]['settingRow']['col3TtContent'] = wp_kses_post( html_entity_decode( $element1['settingRow']['col3TtContent'], ENT_COMPAT, 'UTF-8' ) );
67 }
68 if ( isset( $element1['settingRow']['HTMLContent'] ) ) {
69 $elements[ $key ]['settingRow']['column1'][ $key1 ]['settingRow']['HTMLContent'] = wp_kses_post( html_entity_decode( $element1['settingRow']['HTMLContent'], ENT_COMPAT, 'UTF-8' ) );
70 }
71 if ( isset( $element1['settingRow']['col2Content'] ) ) {
72 $elements[ $key ]['settingRow']['column1'][ $key1 ]['settingRow']['col2Content'] = wp_kses_post( html_entity_decode( $element1['settingRow']['col2Content'], ENT_COMPAT, 'UTF-8' ) );
73 }
74 }//end foreach
75 }//end if
76 // column2
77 if ( isset( $element['settingRow']['column2'] ) ) {
78 foreach ( $element['settingRow']['column2'] as $key1 => $element1 ) {
79 if ( isset( $element1['settingRow']['content'] ) ) {
80 $elements[ $key ]['settingRow']['column2'][ $key1 ]['settingRow']['content'] = wp_kses_post( html_entity_decode( $element1['settingRow']['content'], ENT_COMPAT, 'UTF-8' ) );
81 }
82 if ( isset( $element1['settingRow']['contentTitle'] ) ) {
83 $elements[ $key ]['settingRow']['column2'][ $key1 ]['settingRow']['contentTitle'] = wp_kses_post( html_entity_decode( $element1['settingRow']['contentTitle'], ENT_COMPAT, 'UTF-8' ) );
84 }
85 if ( isset( $element1['settingRow']['contentAfter'] ) ) {
86 $elements[ $key ]['settingRow']['column2'][ $key1 ]['settingRow']['contentAfter'] = wp_kses_post( html_entity_decode( $element1['settingRow']['contentAfter'], ENT_COMPAT, 'UTF-8' ) );
87 }
88 if ( isset( $element1['settingRow']['contentBefore'] ) ) {
89 $elements[ $key ]['settingRow']['column2'][ $key1 ]['settingRow']['contentBefore'] = wp_kses_post( html_entity_decode( $element1['settingRow']['contentBefore'], ENT_COMPAT, 'UTF-8' ) );
90 }
91 if ( isset( $element1['settingRow']['col1TtContent'] ) ) {
92 $elements[ $key ]['settingRow']['column2'][ $key1 ]['settingRow']['col1TtContent'] = wp_kses_post( html_entity_decode( $element1['settingRow']['col1TtContent'], ENT_COMPAT, 'UTF-8' ) );
93 }
94 if ( isset( $element1['settingRow']['col2TtContent'] ) ) {
95 $elements[ $key ]['settingRow']['column2'][ $key1 ]['settingRow']['col2TtContent'] = wp_kses_post( html_entity_decode( $element1['settingRow']['col2TtContent'], ENT_COMPAT, 'UTF-8' ) );
96 }
97 if ( isset( $element1['settingRow']['col3TtContent'] ) ) {
98 $elements[ $key ]['settingRow']['column2'][ $key1 ]['settingRow']['col3TtContent'] = wp_kses_post( html_entity_decode( $element1['settingRow']['col3TtContent'], ENT_COMPAT, 'UTF-8' ) );
99 }
100 if ( isset( $element1['settingRow']['HTMLContent'] ) ) {
101 $elements[ $key ]['settingRow']['column2'][ $key1 ]['settingRow']['HTMLContent'] = wp_kses_post( html_entity_decode( $element1['settingRow']['HTMLContent'], ENT_COMPAT, 'UTF-8' ) );
102 }
103 if ( isset( $element1['settingRow']['col2Content'] ) ) {
104 $elements[ $key ]['settingRow']['column2'][ $key1 ]['settingRow']['col2Content'] = wp_kses_post( html_entity_decode( $element1['settingRow']['col2Content'], ENT_COMPAT, 'UTF-8' ) );
105 }
106 }//end foreach
107 }//end if
108 // column3
109 if ( isset( $element['settingRow']['column3'] ) ) {
110 foreach ( $element['settingRow']['column3'] as $key1 => $element1 ) {
111 if ( isset( $element1['settingRow']['content'] ) ) {
112 $elements[ $key ]['settingRow']['column3'][ $key1 ]['settingRow']['content'] = wp_kses_post( html_entity_decode( $element1['settingRow']['content'], ENT_COMPAT, 'UTF-8' ) );
113 }
114 if ( isset( $element1['settingRow']['contentTitle'] ) ) {
115 $elements[ $key ]['settingRow']['column3'][ $key1 ]['settingRow']['contentTitle'] = wp_kses_post( html_entity_decode( $element1['settingRow']['contentTitle'], ENT_COMPAT, 'UTF-8' ) );
116 }
117 if ( isset( $element1['settingRow']['contentAfter'] ) ) {
118 $elements[ $key ]['settingRow']['column3'][ $key1 ]['settingRow']['contentAfter'] = wp_kses_post( html_entity_decode( $element1['settingRow']['contentAfter'], ENT_COMPAT, 'UTF-8' ) );
119 }
120 if ( isset( $element1['settingRow']['contentBefore'] ) ) {
121 $elements[ $key ]['settingRow']['column3'][ $key1 ]['settingRow']['contentBefore'] = wp_kses_post( html_entity_decode( $element1['settingRow']['contentBefore'], ENT_COMPAT, 'UTF-8' ) );
122 }
123 if ( isset( $element1['settingRow']['col1TtContent'] ) ) {
124 $elements[ $key ]['settingRow']['column3'][ $key1 ]['settingRow']['col1TtContent'] = wp_kses_post( html_entity_decode( $element1['settingRow']['col1TtContent'], ENT_COMPAT, 'UTF-8' ) );
125 }
126 if ( isset( $element1['settingRow']['col2TtContent'] ) ) {
127 $elements[ $key ]['settingRow']['column3'][ $key1 ]['settingRow']['col2TtContent'] = wp_kses_post( html_entity_decode( $element1['settingRow']['col2TtContent'], ENT_COMPAT, 'UTF-8' ) );
128 }
129 if ( isset( $element1['settingRow']['col3TtContent'] ) ) {
130 $elements[ $key ]['settingRow']['column3'][ $key1 ]['settingRow']['col3TtContent'] = wp_kses_post( html_entity_decode( $element1['settingRow']['col3TtContent'], ENT_COMPAT, 'UTF-8' ) );
131 }
132 if ( isset( $element1['settingRow']['HTMLContent'] ) ) {
133 $elements[ $key ]['settingRow']['column3'][ $key1 ]['settingRow']['HTMLContent'] = wp_kses_post( html_entity_decode( $element1['settingRow']['HTMLContent'], ENT_COMPAT, 'UTF-8' ) );
134 }
135 if ( isset( $element1['settingRow']['col2Content'] ) ) {
136 $elements[ $key ]['settingRow']['column3'][ $key1 ]['settingRow']['col2Content'] = wp_kses_post( html_entity_decode( $element1['settingRow']['col2Content'], ENT_COMPAT, 'UTF-8' ) );
137 }
138 }//end foreach
139 }//end if
140
141 // column4
142 if ( isset( $element['settingRow']['column4'] ) ) {
143 foreach ( $element['settingRow']['column4'] as $key1 => $element1 ) {
144 if ( isset( $element1['settingRow']['content'] ) ) {
145 $elements[ $key ]['settingRow']['column4'][ $key1 ]['settingRow']['content'] = wp_kses_post( html_entity_decode( $element1['settingRow']['content'], ENT_COMPAT, 'UTF-8' ) );
146 }
147 if ( isset( $element1['settingRow']['contentTitle'] ) ) {
148 $elements[ $key ]['settingRow']['column4'][ $key1 ]['settingRow']['contentTitle'] = wp_kses_post( html_entity_decode( $element1['settingRow']['contentTitle'], ENT_COMPAT, 'UTF-8' ) );
149 }
150 if ( isset( $element1['settingRow']['contentAfter'] ) ) {
151 $elements[ $key ]['settingRow']['column4'][ $key1 ]['settingRow']['contentAfter'] = wp_kses_post( html_entity_decode( $element1['settingRow']['contentAfter'], ENT_COMPAT, 'UTF-8' ) );
152 }
153 if ( isset( $element1['settingRow']['contentBefore'] ) ) {
154 $elements[ $key ]['settingRow']['column4'][ $key1 ]['settingRow']['contentBefore'] = wp_kses_post( html_entity_decode( $element1['settingRow']['contentBefore'], ENT_COMPAT, 'UTF-8' ) );
155 }
156 if ( isset( $element1['settingRow']['col1TtContent'] ) ) {
157 $elements[ $key ]['settingRow']['column4'][ $key1 ]['settingRow']['col1TtContent'] = wp_kses_post( html_entity_decode( $element1['settingRow']['col1TtContent'], ENT_COMPAT, 'UTF-8' ) );
158 }
159 if ( isset( $element1['settingRow']['col2TtContent'] ) ) {
160 $elements[ $key ]['settingRow']['column4'][ $key1 ]['settingRow']['col2TtContent'] = wp_kses_post( html_entity_decode( $element1['settingRow']['col2TtContent'], ENT_COMPAT, 'UTF-8' ) );
161 }
162 if ( isset( $element1['settingRow']['col3TtContent'] ) ) {
163 $elements[ $key ]['settingRow']['column4'][ $key1 ]['settingRow']['col3TtContent'] = wp_kses_post( html_entity_decode( $element1['settingRow']['col3TtContent'], ENT_COMPAT, 'UTF-8' ) );
164 }
165 if ( isset( $element1['settingRow']['HTMLContent'] ) ) {
166 $elements[ $key ]['settingRow']['column4'][ $key1 ]['settingRow']['HTMLContent'] = wp_kses_post( html_entity_decode( $element1['settingRow']['HTMLContent'], ENT_COMPAT, 'UTF-8' ) );
167 }
168 if ( isset( $element1['settingRow']['col2Content'] ) ) {
169 $elements[ $key ]['settingRow']['column4'][ $key1 ]['settingRow']['col2Content'] = wp_kses_post( html_entity_decode( $element1['settingRow']['col2Content'], ENT_COMPAT, 'UTF-8' ) );
170 }
171 }//end foreach
172 }//end if
173 }//end foreach
174 return $elements;
175 }
176
177 public static function elements_remove_settings_empty( $elements ) {
178 foreach ( $elements as $key => $element ) {
179 if ( 'TwoColumns' === $element['type'] || 'ThreeColumns' === $element['type'] || 'FourColumns' === $element['type'] ) {
180 if ( ! array_key_exists( 'column1', $elements[ $key ]['settingRow'] ) ) {
181 $elements[ $key ]['settingRow']['column1'] = [];
182 }
183 if ( ! array_key_exists( 'column2', $elements[ $key ]['settingRow'] ) ) {
184 $elements[ $key ]['settingRow']['column2'] = [];
185 }
186 if ( ( 'ThreeColumns' === $element['type'] || 'FourColumns' === $element['type'] ) && ! array_key_exists( 'column3', $elements[ $key ]['settingRow'] ) ) {
187 $elements[ $key ]['settingRow']['column3'] = [];
188 }
189 if ( 'FourColumns' === $element['type'] && ! array_key_exists( 'column4', $elements[ $key ]['settingRow'] ) ) {
190 $elements[ $key ]['settingRow']['column4'] = [];
191 }
192 }
193 if ( 'FeaturedProducts' === $element['type'] ) {
194 if ( ! isset( $element['settingRow']['showingItems'] ) ) {
195 $elements[ $key ]['settingRow']['showingItems'] = [];
196 }
197 if ( ! isset( $element['settingRow']['categories'] ) ) {
198 $elements[ $key ]['settingRow']['categories'] = [];
199 }
200 if ( ! isset( $element['settingRow']['tags'] ) ) {
201 $elements[ $key ]['settingRow']['tags'] = [];
202 }
203 if ( ! isset( $element['settingRow']['products'] ) ) {
204 $elements[ $key ]['settingRow']['products'] = [];
205 }
206 }
207 if ( 'SingleBanner' === $element['type'] ) {
208 if ( ! isset( $element['settingRow']['showingItems'] ) ) {
209 $elements[ $key ]['settingRow']['showingItems'] = [];
210 }
211 }
212 if ( 'SimpleOffer' === $element['type'] ) {
213 if ( ! isset( $element['settingRow']['showingItems'] ) ) {
214 $elements[ $key ]['settingRow']['showingItems'] = [];
215 }
216 }
217 }//end foreach
218 }
219
220 public static function is_yaymail_email( $template_name ) {
221 $all_emails = \yaymail_get_emails();
222 foreach ( $all_emails as $email ) {
223 if ( $template_name === $email->get_id() ) {
224 return true;
225 }
226 }
227 return false;
228 }
229
230 public static function snake_to_pascal( $input ) {
231 // Split the input string into words using hyphen as the delimiter
232 $words = explode( '_', $input );
233
234 // Capitalize the first letter of each word and join them
235 $pascal_case = implode( '', array_map( 'ucfirst', $words ) );
236
237 return $pascal_case;
238 }
239
240 public static function check_plugin_installed( $plugin_slug ) {
241 $installed_plugins = get_plugins();
242 return array_key_exists( $plugin_slug, $installed_plugins ) || in_array( $plugin_slug, $installed_plugins, true );
243 }
244
245 public static function get_order_from_shortcode_data( $data ) {
246 $order = $data['order'] ?? null;
247
248 if ( self::is_woocommerce_order( $order ) ) {
249 return $order;
250 }
251 return null;
252 }
253
254 public static function is_woocommerce_order( $order ) {
255 $is_wc_order = false;
256 if ( ! empty( $order ) && $order instanceof \WC_Order ) {
257 $is_wc_order = true;
258 }
259 return apply_filters( 'yaymail_is_woocommerce_order', $is_wc_order, $order );
260 }
261
262 /**
263 * Convert a given string to snake case.
264 *
265 * This function handles various text cases, including camel case, kebab case,
266 * and words with spaces. It replaces spaces and hyphens with underscores,
267 * and converts uppercase letters to underscore + lowercase.
268 *
269 * @param string $input The input string to be converted.
270 *
271 * @return string The converted string in snake case.
272 */
273 public static function to_snake_case( $input ) {
274 // Replace spaces with underscores
275 $snake_case = str_replace( ' ', '_', $input );
276
277 // Replace hyphens with underscores
278 $snake_case = str_replace( '-', '_', $snake_case );
279
280 // Replace uppercase letters with underscore + lowercase
281 $snake_case = preg_replace( '/([a-z])([A-Z])/', '$1_$2', $snake_case );
282
283 // Convert to lowercase
284 $snake_case = strtolower( $snake_case );
285
286 return $snake_case;
287 }
288
289 public static function snake_case_to_capitalized_words( $snake_case_string ) {
290 // Replace underscores with space
291 $space_separated_string = str_replace( '_', ' ', $snake_case_string );
292
293 // Capitalize each word
294 $capitalized_words = ucwords( $space_separated_string );
295 $capitalized_words = trim( $capitalized_words );
296
297 return $capitalized_words;
298 }
299
300 /**
301 * Checks if all keys from the specified array exist in another array.
302 *
303 * @param array $keys An array containing the keys to check.
304 * @param array $arr The array to search for the keys.
305 *
306 * @return bool True if all keys exist in the array, false otherwise.
307 */
308 public static function array_keys_exists( $keys, $arr ) {
309 return ! array_diff_key( array_flip( $keys ), $arr );
310 }
311
312 /**
313 * Get value of object recursively
314 *
315 * @param array $object
316 * @param array|string $path
317 * @return mixed|null
318 */
319 public static function get_object_value( $object, $path ) {
320 if ( ! is_array( $path ) ) {
321 // Make sure path is an array
322 $path = [ $path ];
323 }
324
325 $current = $object;
326
327 foreach ( $path as $key ) {
328 if ( isset( $current[ $key ] ) ) {
329 $current = $current[ $key ];
330 } else {
331 return null;
332 }
333 }
334
335 return $current;
336 }
337
338 /**
339 * Set value of object recursively
340 *
341 * @param array &$object
342 * @param array|string $path
343 * @param mixed $value
344 * @return void
345 */
346 public static function set_object_value( &$object, $path, $value ) {
347 if ( ! is_array( $path ) ) {
348 $path = [ $path ];
349 }
350
351 $current =& $object;
352
353 foreach ( $path as $key ) {
354 if ( ! isset( $current[ $key ] ) || ! is_array( $current[ $key ] ) ) {
355 $current[ $key ] = [];
356 }
357 $current =& $current[ $key ];
358 }
359
360 $current = $value;
361 }
362
363 public static function get_dummy_order( $order_status = \Automattic\WooCommerce\Enums\OrderStatus::COMPLETED ) {
364 $product = new \WC_Product();
365 $product->set_name( __( 'Happy YayCommerce', 'yaymail' ) );
366 $product->set_price( 18 );
367
368 $order = new \WC_Order();
369 if ( $product ) {
370 $order->add_product( $product, 2 );
371 }
372 $order->set_id( 1 );
373 $order->set_status( $order_status );
374 $order->set_date_created( time() );
375 $order->set_currency( 'USD' );
376 $order->set_discount_total( 18 );
377 $order->set_shipping_total( 0 );
378 $order->set_total( 18 );
379 $order->set_payment_method_title( __( 'Direct bank transfer', 'woocommerce' ) );
380 $order->set_customer_note( __( "This is a customer note. Customers can add a note to their order on checkout.\n\nIt can be multiple lines. If there’s no note, this section is hidden.", 'woocommerce' ) );
381
382 $address = [
383 'first_name' => 'John',
384 'last_name' => 'Doe',
385 'company' => 'YayCommerce',
386 'email' => 'johndoe@gmail.com',
387 'phone' => '(910) 529-1147',
388 'address_1' => '7400 Edwards Rd',
389 'city' => 'Mayville, Michigan',
390 'postcode' => '7400',
391 'country' => 'US',
392 'state' => 'CA',
393 ];
394 $order->set_billing_address( $address );
395 $order->set_shipping_address( $address );
396 return $order;
397 }
398
399 public static function is_true( $value ) {
400 return filter_var( $value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE );
401 }
402
403 /**
404 * Sanitize array data recursively
405 *
406 * @param mixed $data The data to sanitize.
407 * @return mixed Sanitized data.
408 */
409 public static function sanitize_array_recursive( $data ) {
410 if ( is_array( $data ) ) {
411 $sanitized = [];
412 foreach ( $data as $key => $value ) {
413 // Recursively sanitize values
414 $sanitized[ $key ] = self::sanitize_array_recursive( $value );
415 }
416 return $sanitized;
417 } elseif ( is_string( $data ) ) {
418 // Special handling for color values
419 if ( self::is_color_value( $data ) ) {
420 return sanitize_hex_color( $data );
421 }
422 // Regular text sanitization
423 return sanitize_text_field( $data );
424 }
425
426 return $data;
427 }
428
429 /**
430 * Check if a string is a color value
431 *
432 * @param string $value The value to check.
433 * @return bool True if it's a color value.
434 */
435 public static function is_color_value( $value ) {
436 // Check if it's a hex color (#RRGGBB or #RGB)
437 return preg_match( '/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/', $value );
438 }
439
440 /**
441 * Check if a WooCommerce feature is enabled
442 *
443 * @param string $feature_id The feature ID to check.
444 * @return bool True if the feature is enabled, false otherwise.
445 */
446 public static function check_wc_feature( $feature_id = '' ) {
447 if ( empty( $feature_id ) || ! class_exists( '\Automattic\WooCommerce\Internal\Features\FeaturesController' ) ) {
448 return false;
449 }
450
451 try {
452 $feature_controller = wc_get_container()->get( \Automattic\WooCommerce\Internal\Features\FeaturesController::class );
453
454 if ( ! $feature_controller ) {
455 return false;
456 }
457
458 return $feature_controller->feature_is_enabled( $feature_id );
459 } catch ( \Throwable $e ) {
460 return false;
461 }
462 }
463
464 /**
465 * Get the URL of the email setting page
466 *
467 * @param string $email_id The email ID.
468 * @return string The URL of the email setting page.
469 */
470 public static function yaymail_get_url_email_setting_page( $email_id ) {
471 if ( ! is_string( $email_id ) ) {
472 return '';
473 }
474
475 return add_query_arg(
476 [
477 'page' => 'wc-settings',
478 'tab' => 'email',
479 'section' => 'wc_email_' . $email_id,
480 ],
481 admin_url( 'admin.php' )
482 );
483 }
484 }
485