PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.7.1
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.7.1
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
templately / includes / Core / Importer / Runners / CustomCSS.php

CustomCSS.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.7.1, at includes/Core/Importer/Runners/CustomCSS.php

64 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately\Core\Importer\Runners;
4
5 use Templately\Core\Importer\Runners\BaseRunner;
6 use Templately\Core\Importer\Utils\Utils;
7
8 /**
9 * Imports the pack's site-wide custom CSS (`custom.css` at the pack root) into
10 * the `templately_custom_css` option, which Settings::add_custom_css() prints
11 * inside a <style> tag on wp_head.
12 *
13 * The value is written through Utils::update_option(), so the previous value is
14 * backed up to `__templately_templately_custom_css` and import_revert() restores
15 * it — the same backup/revert path every other imported option uses.
16 */
17 class CustomCSS extends BaseRunner {
18
19 const OPTION_KEY = 'templately_custom_css';
20 const FILE_NAME = 'custom.css';
21
22 public function get_name(): string {
23 return 'custom-css';
24 }
25
26 public function get_label(): string {
27 return __( 'Custom CSS', 'templately' );
28 }
29
30 public function should_log(): bool {
31 return true;
32 }
33
34 public function get_action(): string {
35 return 'eventLog';
36 }
37
38 public function log_message(): string {
39 return __( 'Importing custom CSS.', 'templately' );
40 }
41
42 public function should_run( $data, $imported_data = [] ): bool {
43 $file = $this->dir_path . self::FILE_NAME;
44 return is_readable( $file ) && filesize( $file ) > 0;
45 }
46
47 public function import( $data, $imported_data ): array {
48 $this->log( 0 );
49
50 $file = $this->dir_path . self::FILE_NAME;
51 $css = file_get_contents( $file );
52
53 if ( false === $css || '' === trim( $css ) ) {
54 return [];
55 }
56
57 // Backup the current value then write the pack CSS. The backup lands in
58 // `__templately_templately_custom_css`; import_revert() restores it.
59 Utils::update_option( self::OPTION_KEY, $css );
60
61 return [ 'custom_css' => true ];
62 }
63 }
64