| @@ -9,8 +9,13 @@ | ||
| 9 | 9 | * Singleton |
| 10 | 10 | */ |
| 11 | 11 | use SingletonTrait; |
| 12 | 12 | |
| 13 | + /** | |
| 14 | + * @var array | |
| 15 | + */ | |
| 16 | + private static $cache = []; | |
| 17 | + | |
| 13 | 18 | /*** |
| 14 | 19 | * Elementor Data key |
| 15 | 20 | */ |
| 16 | 21 | private const ELEMENTOR_DATA_KEY = '_elementor_data'; |
| @@ -37,8 +42,12 @@ | ||
| 37 | 42 | * |
| 38 | 43 | * @return array |
| 39 | 44 | */ |
| 40 | 45 | public function get_widget_data( string $widget_name, ?array $data = null, ?int $post_id = null ): array { |
| 46 | + $cache_key = 'get_widget_data_' . $widget_name . '_' . $post_id; | |
| 47 | + if ( isset( self::$cache[ $cache_key ] ) ) { | |
| 48 | + return self::$cache[ $cache_key ]; | |
| 49 | + } | |
| 41 | 50 | if ( ! $data && $post_id ) { |
| 42 | 51 | $data = $this->get_elementor_data( $post_id ); |
| 43 | 52 | } |
| 44 | 53 | |
| @@ -46,9 +55,9 @@ | ||
| 46 | 55 | return []; |
| 47 | 56 | } |
| 48 | 57 | |
| 49 | 58 | $this->search_el( $data, $widget_name ); |
| 50 | - | |
| 59 | + self::$cache[ $cache_key ] = $this->eldata; | |
| 51 | 60 | return $this->eldata; |
| 52 | 61 | } |
| 53 | 62 | |
| 54 | 63 | /*** |
| @@ -65,9 +74,9 @@ | ||
| 65 | 74 | |
| 66 | 75 | if ( ! empty( $value['elements'] ) && is_array( $value['elements'] ) ) { |
| 67 | 76 | $this->search_el( $value['elements'], $name ); |
| 68 | 77 | } else { |
| 69 | - if ( $value['elType'] === 'widget' && $value['widgetType'] === $name ) { | |
| 78 | + if ( 'widget' === $value['elType'] && $value['widgetType'] === $name ) { | |
| 70 | 79 | $this->eldata[] = $value; |
| 71 | 80 | } |
| 72 | 81 | } |
| 73 | 82 | } |