Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/elemento.../modules/componen.../styles
File: component-styles.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Elementor\Modules\Components\Styles;
[2] Fix | Delete
[3] Fix | Delete
use Elementor\Core\Base\Document;
[4] Fix | Delete
use Elementor\Core\Utils\Collection;
[5] Fix | Delete
use Elementor\Modules\AtomicWidgets\Styles\CacheValidity\Cache_Validity;
[6] Fix | Delete
use Elementor\Modules\AtomicWidgets\Utils\Utils;
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Component styles fetching for render
[10] Fix | Delete
*/
[11] Fix | Delete
class Component_Styles {
[12] Fix | Delete
const CACHE_ROOT_KEY = 'component-styles-related-posts';
[13] Fix | Delete
[14] Fix | Delete
public function register_hooks() {
[15] Fix | Delete
add_action( 'elementor/post/render', fn( $post_id ) => $this->render_post( $post_id ) );
[16] Fix | Delete
[17] Fix | Delete
add_action( 'elementor/document/after_save', fn( Document $document ) => $this->invalidate_cache(
[18] Fix | Delete
[ $document->get_main_post()->ID ]
[19] Fix | Delete
), 20, 2 );
[20] Fix | Delete
[21] Fix | Delete
add_action(
[22] Fix | Delete
'elementor/core/files/clear_cache',
[23] Fix | Delete
fn() => $this->invalidate_cache(),
[24] Fix | Delete
);
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
private function render_post( string $post_id ) {
[28] Fix | Delete
$cache_validity = new Cache_Validity();
[29] Fix | Delete
[30] Fix | Delete
if ( $cache_validity->is_valid( [ self::CACHE_ROOT_KEY, $post_id ] ) ) {
[31] Fix | Delete
$component_ids = $cache_validity->get_meta( [ self::CACHE_ROOT_KEY, $post_id ] );
[32] Fix | Delete
[33] Fix | Delete
$this->declare_components_rendered( $component_ids );
[34] Fix | Delete
[35] Fix | Delete
return;
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
$components = $this->get_components_from_post( $post_id );
[39] Fix | Delete
$component_ids = Collection::make( $components )
[40] Fix | Delete
->filter( fn( $component ) => isset( $component['settings']['component_instance']['value']['component_id']['value'] ) )
[41] Fix | Delete
->map( fn( $component ) => $component['settings']['component_instance']['value']['component_id']['value'] )
[42] Fix | Delete
->unique()
[43] Fix | Delete
->all();
[44] Fix | Delete
[45] Fix | Delete
$cache_validity->validate( [ self::CACHE_ROOT_KEY, $post_id ], $component_ids );
[46] Fix | Delete
[47] Fix | Delete
$this->declare_components_rendered( $component_ids );
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
private function declare_components_rendered( array $post_ids ) {
[51] Fix | Delete
foreach ( $post_ids as $post_id ) {
[52] Fix | Delete
do_action( 'elementor/post/render', $post_id );
[53] Fix | Delete
}
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
private function get_components_from_post( string $post_id ): array {
[57] Fix | Delete
$components = [];
[58] Fix | Delete
[59] Fix | Delete
Utils::traverse_post_elements( $post_id, function( $element_data ) use ( &$components ) {
[60] Fix | Delete
if ( isset( $element_data['widgetType'] ) && 'e-component' === $element_data['widgetType'] ) {
[61] Fix | Delete
$components[] = $element_data;
[62] Fix | Delete
}
[63] Fix | Delete
} );
[64] Fix | Delete
[65] Fix | Delete
return $components;
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
private function invalidate_cache( ?array $post_ids = null ) {
[69] Fix | Delete
$cache_validity = new Cache_Validity();
[70] Fix | Delete
[71] Fix | Delete
if ( empty( $post_ids ) ) {
[72] Fix | Delete
$cache_validity->invalidate( [ self::CACHE_ROOT_KEY ] );
[73] Fix | Delete
[74] Fix | Delete
return;
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
foreach ( $post_ids as $post_id ) {
[78] Fix | Delete
$cache_validity->invalidate( [ self::CACHE_ROOT_KEY, $post_id ] );
[79] Fix | Delete
}
[80] Fix | Delete
}
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function