PluginProbe
YayMail – WooCommerce Email Customizer / 4.4.7
YayMail – WooCommerce Email Customizer v4.4.7
4.4.7 4.4.6 4.4.5 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 All 58 releases
yaymail / src / Abstracts / BasePattern.php

BasePattern.php in YayMail – WooCommerce Email Customizer 4.4.7, at src/Abstracts/BasePattern.php

82 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace YayMail\Abstracts;
3
4 /**
5 * BasePattern Class
6 */
7 abstract class BasePattern {
8 protected $id = null;
9 public const TYPE = '';
10
11 protected $section = null;
12
13 protected $available = true;
14 protected $position = 10;
15 protected $name = '';
16 protected $elements = [];
17
18 public function get_data() {
19 return [
20 'id' => $this->id,
21 'type' => static::TYPE,
22 'section' => $this->section,
23 'available' => $this->available,
24 'position' => $this->position,
25 'elements' => $this->elements,
26 'name' => $this->name,
27 ];
28 }
29
30 public function get_type() {
31 return static::TYPE;
32 }
33
34 /**
35 * @return string
36 */
37 public function get_section() {
38 return $this->section;
39 }
40
41 /**
42 * Element keys only the sidebar element registry reads (builder elements list).
43 * Elements placed from a pattern never use them, yet the same "Third party
44 * elements" SVG icon was repeated on every nested element, ~150KB of the inline
45 * yaymailData script. `name` is kept: the element editor and history labels use it.
46 */
47 private const SIDEBAR_ONLY_ELEMENT_KEYS = [ 'icon', 'group' ];
48
49 public function get_raw_data() {
50 $data = $this->get_data();
51 $data['elements'] = self::strip_sidebar_only_keys( $data['elements'] );
52 return $data;
53 }
54
55 /**
56 * Recursively drop SIDEBAR_ONLY_ELEMENT_KEYS from elements and their children.
57 *
58 * @param array $elements Pattern elements.
59 * @return array
60 */
61 private static function strip_sidebar_only_keys( $elements ) {
62 if ( ! is_array( $elements ) ) {
63 return $elements;
64 }
65
66 return array_map(
67 function( $element ) {
68 if ( ! is_array( $element ) ) {
69 return $element;
70 }
71 $element = array_diff_key( $element, array_flip( self::SIDEBAR_ONLY_ELEMENT_KEYS ) );
72 if ( ! empty( $element['children'] ) ) {
73 $element['children'] = self::strip_sidebar_only_keys( $element['children'] );
74 }
75 return $element;
76 },
77 $elements
78 );
79 }
80
81 }
82