PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.4
Elementor Website Builder – more than just a page builder v4.2.4
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
← All changes | modules/global-classes/usage/document-usage.php +14 -21 4.0.94.2.4 View file →
@@ -1,11 +1,10 @@
1 1 <?php
2 2
3 3 namespace Elementor\Modules\GlobalClasses\Usage;
4 4
5 +use Elementor\Core\Base\Document as ElementorDocument;
5 6 use Elementor\Plugin;
6 -use Elementor\Core\Base\Document as ElementorDocument;
7 -use Elementor\Modules\GlobalClasses\Global_Classes_Repository;
8 7
9 8 /**
10 9 * Tracks usage of global CSS classes within a specific Elementor document.
11 10 */
@@ -14,8 +13,15 @@
14 13
15 14 /** @var ElementorDocument */
16 15 private ElementorDocument $document;
17 16
17 + /**
18 + * Map of known global class ID => true for O(1) membership checks.
19 + *
20 + * @var array<string, true>
21 + */
22 + private array $valid_class_id_set;
23 +
18 24 /** @var array<string, Css_Class_Usage> */
19 25 private array $usages = [];
20 26
21 27 /**
@@ -20,12 +26,14 @@
20 26
21 27 /**
22 28 * Constructor.
23 29 *
24 - * @param ElementorDocument $document The Elementor document object.
30 + * @param ElementorDocument $document The Elementor document object.
31 + * @param array<string, true> $valid_class_id_set Known global class IDs (e.g. from array_fill_keys).
25 32 */
26 - public function __construct( ElementorDocument $document ) {
33 + public function __construct( ElementorDocument $document, array $valid_class_id_set ) {
27 34 $this->document = $document;
35 + $this->valid_class_id_set = $valid_class_id_set;
28 36 }
29 37
30 38 /**
31 39 * Analyze the document to find and record usage of global CSS classes.
@@ -32,9 +40,8 @@
32 40 */
33 41 public function analyze(): void {
34 42 $page_id = $this->document->get_main_id();
35 43 $page_title = $this->document->get_post()->post_title;
36 - $class_ids = $this->get_all_global_class_ids();
37 44 $elements_data = $this->document->get_elements_raw_data() ?? [];
38 45
39 46 $document_type = $this->document->get_type();
40 47 if ( empty( $document_type ) ) {
@@ -46,9 +53,9 @@
46 53 }
47 54
48 55 Plugin::$instance->db->iterate_data(
49 56 $elements_data,
50 - function ( $element_data ) use ( $class_ids, $page_id, $page_title, $document_type ) {
57 + function ( $element_data ) use ( $page_id, $page_title, $document_type ) {
51 58 $class_values = $element_data['settings']['classes']['value'] ?? [];
52 59
53 60 if ( empty( $class_values ) || ! is_array( $class_values ) ) {
54 61 return;
@@ -54,9 +61,9 @@
54 61 return;
55 62 }
56 63
57 64 foreach ( $class_values as $class_id ) {
58 - if ( ! in_array( $class_id, $class_ids, true ) ) {
65 + if ( ! isset( $this->valid_class_id_set[ $class_id ] ) ) {
59 66 continue;
60 67 }
61 68
62 69 if ( ! isset( $this->usages[ $class_id ] ) ) {
@@ -80,20 +87,6 @@
80 87 * @return array<string, Css_Class_Usage>
81 88 */
82 89 public function get_usages(): array {
83 90 return $this->usages;
84 - }
85 -
86 - /**֜
87 - * Retrieve all registered global CSS class IDs.
88 - *
89 - * @return string[]
90 - */
91 - protected function get_all_global_class_ids(): array {
92 - return Global_Classes_Repository::make()
93 - ->all()
94 - ->get_items()
95 - ->filter( fn( $item ) => ! empty( $item['id'] ?? null ) )
96 - ->keys()
97 - ->all();
98 91 }
99 92 }