PluginProbe
Elementor Website Builder – more than just a page builder / 3.32.3
Elementor Website Builder – more than just a page builder v3.32.3
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 +22 -15 4.1.0-dev23.32.3 View file →
@@ -1,10 +1,11 @@
1 1 <?php
2 2
3 3 namespace Elementor\Modules\GlobalClasses\Usage;
4 4
5 +use Elementor\Plugin;
5 6 use Elementor\Core\Base\Document as ElementorDocument;
6 -use Elementor\Plugin;
7 +use Elementor\Modules\GlobalClasses\Global_Classes_Repository;
7 8
8 9 /**
9 10 * Tracks usage of global CSS classes within a specific Elementor document.
10 11 */
@@ -13,15 +14,8 @@
13 14
14 15 /** @var ElementorDocument */
15 16 private ElementorDocument $document;
16 17
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 -
24 18 /** @var array<string, Css_Class_Usage> */
25 19 private array $usages = [];
26 20
27 21 /**
@@ -26,14 +20,12 @@
26 20
27 21 /**
28 22 * Constructor.
29 23 *
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).
24 + * @param ElementorDocument $document The Elementor document object.
32 25 */
33 - public function __construct( ElementorDocument $document, array $valid_class_id_set ) {
34 - $this->document = $document;
35 - $this->valid_class_id_set = $valid_class_id_set;
26 + public function __construct( ElementorDocument $document ) {
27 + $this->document = $document;
36 28 }
37 29
38 30 /**
39 31 * Analyze the document to find and record usage of global CSS classes.
@@ -40,8 +32,9 @@
40 32 */
41 33 public function analyze(): void {
42 34 $page_id = $this->document->get_main_id();
43 35 $page_title = $this->document->get_post()->post_title;
36 + $class_ids = $this->get_all_global_class_ids();
44 37 $elements_data = $this->document->get_elements_raw_data() ?? [];
45 38
46 39 $document_type = $this->document->get_type();
47 40 if ( empty( $document_type ) ) {
@@ -53,9 +46,9 @@
53 46 }
54 47
55 48 Plugin::$instance->db->iterate_data(
56 49 $elements_data,
57 - function ( $element_data ) use ( $page_id, $page_title, $document_type ) {
50 + function ( $element_data ) use ( $class_ids, $page_id, $page_title, $document_type ) {
58 51 $class_values = $element_data['settings']['classes']['value'] ?? [];
59 52
60 53 if ( empty( $class_values ) || ! is_array( $class_values ) ) {
61 54 return;
@@ -61,9 +54,9 @@
61 54 return;
62 55 }
63 56
64 57 foreach ( $class_values as $class_id ) {
65 - if ( ! isset( $this->valid_class_id_set[ $class_id ] ) ) {
58 + if ( ! in_array( $class_id, $class_ids, true ) ) {
66 59 continue;
67 60 }
68 61
69 62 if ( ! isset( $this->usages[ $class_id ] ) ) {
@@ -87,6 +80,20 @@
87 80 * @return array<string, Css_Class_Usage>
88 81 */
89 82 public function get_usages(): array {
90 83 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();
91 98 }
92 99 }