| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\AtomicWidgets\Styles; |
| 4 |
|
| 5 |
use Elementor\Core\Base\Document; |
| 6 |
use Elementor\Core\Breakpoints\Breakpoint; |
| 7 |
use Elementor\Core\Utils\Collection; |
| 8 |
use Elementor\Modules\AtomicWidgets\Memo; |
| 9 |
use Elementor\Modules\AtomicWidgets\Cache_Validity; |
| 10 |
use Elementor\Plugin; |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; // Exit if accessed directly. |
| 14 |
} |
| 15 |
|
| 16 |
const FONTS_KEY_PREFIX = 'elementor_atomic_styles_fonts-'; |
| 17 |
|
| 18 |
class Style_Fonts { |
| 19 |
private string $style_key; |
| 20 |
|
| 21 |
public function __construct( string $style_key ) { |
| 22 |
$this->style_key = $style_key; |
| 23 |
} |
| 24 |
|
| 25 |
public static function make( string $style_key ) { |
| 26 |
return new static( $style_key ); |
| 27 |
} |
| 28 |
|
| 29 |
public function add( string $font ) { |
| 30 |
$style_fonts = $this->get_fonts(); |
| 31 |
|
| 32 |
if ( ! in_array( $font, $style_fonts, true ) ) { |
| 33 |
$style_fonts[] = $font; |
| 34 |
|
| 35 |
$this->update_fonts( $style_fonts ); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
public function get(): array { |
| 40 |
return $this->get_fonts(); |
| 41 |
} |
| 42 |
|
| 43 |
public function clear() { |
| 44 |
$this->update_fonts( [] ); |
| 45 |
} |
| 46 |
|
| 47 |
private function get_fonts(): array { |
| 48 |
$style_fonts_key = $this->get_key(); |
| 49 |
return get_option( $style_fonts_key, [] ); |
| 50 |
} |
| 51 |
|
| 52 |
private function update_fonts( array $fonts ) { |
| 53 |
$style_fonts_key = $this->get_key(); |
| 54 |
update_option( $style_fonts_key, $fonts ); |
| 55 |
} |
| 56 |
|
| 57 |
private function get_key(): string { |
| 58 |
return FONTS_KEY_PREFIX . $this->style_key; |
| 59 |
} |
| 60 |
} |
| 61 |
|