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