PluginProbe
Elementor Website Builder – more than just a page builder / 3.35.0-dev4
Elementor Website Builder – more than just a page builder v3.35.0-dev4
4.3.0-beta3 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 All 452 releases
← All changes | modules/components/styles/component-styles.php +8 -38 4.3.0-beta33.35.0-dev4 View file →
@@ -5,9 +5,8 @@
5 5 use Elementor\Core\Base\Document;
6 6 use Elementor\Core\Utils\Collection;
7 7 use Elementor\Modules\AtomicWidgets\Styles\CacheValidity\Cache_Validity;
8 8 use Elementor\Modules\AtomicWidgets\Utils\Utils;
9 -use Elementor\Modules\Components\PropTypes\Component_Instance_Prop_Type;
10 9
11 10 /**
12 11 * Component styles fetching for render
13 12 */
@@ -24,60 +23,31 @@
24 23 add_action(
25 24 'elementor/core/files/clear_cache',
26 25 fn() => $this->invalidate_cache(),
27 26 );
28 -
29 - add_filter(
30 - 'elementor/document/related_posts',
31 - fn( array $related, $post_id ) => $this->get_related_posts( $related, $post_id ),
32 - 10,
33 - 2
34 - );
35 27 }
36 28
37 29 private function render_post( string $post_id ) {
38 - $component_ids = $this->get_component_ids_from_post_cached( $post_id );
30 + $cache_validity = new Cache_Validity();
39 31
40 - $this->declare_components_rendered( $component_ids );
41 - }
32 + if ( $cache_validity->is_valid( [ self::CACHE_ROOT_KEY, $post_id ] ) ) {
33 + $component_ids = $cache_validity->get_meta( [ self::CACHE_ROOT_KEY, $post_id ] );
42 34
43 - /**
44 - * Handler for the `elementor/document/related_posts` filter.
45 - *
46 - * @param int[] $related Accumulated ids from previous filter handlers.
47 - * @param string|int $post_id Parent post id being inspected.
48 - * @return int[] Merged list of related post ids.
49 - */
50 - private function get_related_posts( array $related, $post_id ): array {
51 - $component_ids = $this->get_component_ids_from_post_cached( (string) $post_id );
35 + $this->declare_components_rendered( $component_ids );
52 36
53 - return array_values( array_unique( array_merge( $related, array_map( 'intval', $component_ids ) ) ) );
54 - }
55 -
56 - /**
57 - * Returns the component ids embedded in $post_id, reading from the
58 - * traversal cache when available and writing to it otherwise.
59 - *
60 - * Both the render-action listener and the `elementor/document/related_posts`
61 - * filter handler delegate here so the traversal logic lives in one place.
62 - */
63 - private function get_component_ids_from_post_cached( string $post_id ): array {
64 - $cache_validity = new Cache_Validity();
65 -
66 - if ( $cache_validity->is_valid( [ self::CACHE_ROOT_KEY, $post_id ] ) ) {
67 - return (array) $cache_validity->get_meta( [ self::CACHE_ROOT_KEY, $post_id ] );
37 + return;
68 38 }
69 39
70 40 $components = $this->get_components_from_post( $post_id );
71 41 $component_ids = Collection::make( $components )
72 - ->map( fn( $component ) => Component_Instance_Prop_Type::extract_component_id( $component['settings'] ?? [] ) )
73 - ->filter( fn( $component_id ) => null !== $component_id )
42 + ->filter( fn( $component ) => isset( $component['settings']['component_instance']['value']['component_id']['value'] ) )
43 + ->map( fn( $component ) => $component['settings']['component_instance']['value']['component_id']['value'] )
74 44 ->unique()
75 45 ->all();
76 46
77 47 $cache_validity->validate( [ self::CACHE_ROOT_KEY, $post_id ], $component_ids );
78 48
79 - return $component_ids;
49 + $this->declare_components_rendered( $component_ids );
80 50 }
81 51
82 52 private function declare_components_rendered( array $post_ids ) {
83 53 foreach ( $post_ids as $post_id ) {