| 1 |
<?php |
| 2 |
namespace Enteraddons\Classes; |
| 3 |
/** |
| 4 |
* Enteraddons helper class |
| 5 |
* |
| 6 |
* @package Enteraddons |
| 7 |
* @author ThemeLooks |
| 8 |
* @copyright 2022 ThemeLooks |
| 9 |
* @license GPL-2.0-or-later |
| 10 |
* |
| 11 |
* |
| 12 |
*/ |
| 13 |
if( !defined( 'WPINC' ) ) { |
| 14 |
die; |
| 15 |
} |
| 16 |
|
| 17 |
class Cache_Manager { |
| 18 |
|
| 19 |
public static function init() { |
| 20 |
add_action( 'elementor/editor/after_save', [ __CLASS__, 'widgets_cache' ], 10, 2 ); |
| 21 |
add_action( 'after_delete_post', [ __CLASS__, 'delete_cache' ] ); |
| 22 |
add_action( 'wp_enqueue_scripts', [ __CLASS__, 'enqueue_frontend' ] ); |
| 23 |
} |
| 24 |
|
| 25 |
public static function widgets_cache( $post_id, $editor_data ) { |
| 26 |
$widgets = self::getWidgetsList( $editor_data ); |
| 27 |
$Assets_Cache = new Assets_Cache( $post_id, $widgets ); |
| 28 |
$Assets_Cache::putStyle(); |
| 29 |
} |
| 30 |
|
| 31 |
public static function delete_cache( $post_id ) { |
| 32 |
$Assets_Cache = new Assets_Cache( $post_id ); |
| 33 |
$Assets_Cache::deleteCacheFile(); |
| 34 |
} |
| 35 |
|
| 36 |
public static function enqueue_frontend() { |
| 37 |
if( !\Enteraddons\Classes\Helper::is_elementor_edit_mode() ) { |
| 38 |
$Assets_Cache = new Assets_Cache( get_the_ID() ); |
| 39 |
$Assets_Cache::enqueue(); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
public static function getWidgetsList( $data ) { |
| 44 |
|
| 45 |
$widgets = []; |
| 46 |
foreach( new \RecursiveIteratorIterator( new \RecursiveArrayIterator( $data ), \RecursiveIteratorIterator::LEAVES_ONLY ) as $iteratorKey => $iteratorValue ){ |
| 47 |
if( $iteratorKey == 'widgetType' ) { |
| 48 |
$widgets[] = self::purifyWidgetsName( $iteratorValue ); |
| 49 |
} |
| 50 |
} |
| 51 |
return array_unique( $widgets ); |
| 52 |
} |
| 53 |
|
| 54 |
public static function purifyWidgetsName( $string ) { |
| 55 |
return str_replace('enteraddons-', '', $string); |
| 56 |
} |
| 57 |
} // End Class |
| 58 |
|