| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\GlobalClasses; |
| 4 |
|
| 5 |
use Elementor\Plugin; |
| 6 |
|
| 7 |
class Global_Classes_CSS { |
| 8 |
public function register_hooks() { |
| 9 |
add_action( |
| 10 |
'elementor/frontend/after_enqueue_styles', |
| 11 |
fn() => $this->enqueue_styles() |
| 12 |
); |
| 13 |
|
| 14 |
add_action( |
| 15 |
'elementor/global_classes/update', |
| 16 |
fn( $context ) => $this->clear_css_cache( $context ) |
| 17 |
); |
| 18 |
|
| 19 |
add_action( |
| 20 |
'elementor/core/files/clear_cache', |
| 21 |
fn() => $this->clear_css_cache( Global_Classes_Repository::CONTEXT_FRONTEND ) |
| 22 |
); |
| 23 |
|
| 24 |
add_action( |
| 25 |
'deleted_post', |
| 26 |
fn( $post_id ) => $this->on_post_delete( $post_id ) |
| 27 |
); |
| 28 |
|
| 29 |
add_action( |
| 30 |
'elementor/core/files/after_generate_css', |
| 31 |
fn() => $this->generate_styles() |
| 32 |
); |
| 33 |
} |
| 34 |
|
| 35 |
private function enqueue_styles() { |
| 36 |
$css_file = is_preview() |
| 37 |
? new Global_Classes_CSS_Preview() |
| 38 |
: new Global_Classes_CSS_File(); |
| 39 |
|
| 40 |
$css_file->enqueue(); |
| 41 |
} |
| 42 |
|
| 43 |
private function generate_styles() { |
| 44 |
( new Global_Classes_CSS_File() )->update(); |
| 45 |
} |
| 46 |
|
| 47 |
private function on_post_delete( $post_id ) { |
| 48 |
if ( ! Plugin::$instance->kits_manager->is_kit( $post_id ) ) { |
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
$this->clear_css_cache( |
| 53 |
Global_Classes_Repository::CONTEXT_FRONTEND, |
| 54 |
$post_id |
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
private function clear_css_cache( string $context, $kit_id = null ): void { |
| 59 |
( new Global_Classes_CSS_Preview( $kit_id ) )->delete(); |
| 60 |
|
| 61 |
if ( Global_Classes_Repository::CONTEXT_FRONTEND === $context ) { |
| 62 |
( new Global_Classes_CSS_File( $kit_id ) )->delete(); |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
|