PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.0.2
ShopBuilder – WooCommerce Builder For Elementor v2.0.2
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Helpers / ElementorDataMap.php

ElementorDataMap.php in ShopBuilder – WooCommerce Builder For Elementor 2.0.2, at app/Helpers/ElementorDataMap.php

76 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace RadiusTheme\SB\Helpers;
4
5 use RadiusTheme\SB\Traits\SingletonTrait;
6
7 class ElementorDataMap {
8 /**
9 * Singleton
10 */
11 use SingletonTrait;
12
13 /***
14 * Elementor Data key
15 */
16 private const ELEMENTOR_DATA_KEY = '_elementor_data';
17 /***
18 * @var array
19 */
20 private array $eldata = [];
21
22 /***
23 * @param int $post_id
24 *
25 * @return array|null
26 */
27 public function get_elementor_data( int $post_id ): ?array {
28 $data = get_post_meta( $post_id, self::ELEMENTOR_DATA_KEY, true );
29
30 return json_decode( $data, true );
31 }
32
33 /***
34 * @param string $widget_name
35 * @param array|null $data
36 * @param int|null $post_id
37 *
38 * @return array
39 */
40 public function get_widget_data( string $widget_name, ?array $data = null, ?int $post_id = null ): array {
41 if ( ! $data && $post_id ) {
42 $data = $this->get_elementor_data( $post_id );
43 }
44
45 if ( empty( $data ) || ! is_array( $data ) ) {
46 return [];
47 }
48
49 $this->search_el( $data, $widget_name );
50
51 return $this->eldata;
52 }
53
54 /***
55 * @param array $data
56 * @param string $name
57 *
58 * @return void
59 */
60 private function search_el( array $data, string $name ): void {
61 foreach ( $data as $value ) {
62 if ( ! is_array( $value ) ) {
63 continue;
64 }
65
66 if ( ! empty( $value['elements'] ) && is_array( $value['elements'] ) ) {
67 $this->search_el( $value['elements'], $name );
68 } else {
69 if ( $value['elType'] === 'widget' && $value['widgetType'] === $name ) {
70 $this->eldata[] = $value;
71 }
72 }
73 }
74 }
75 }
76