| 1 |
<?php |
| 2 |
|
| 3 |
namespace AgeGate\Presentation; |
| 4 |
|
| 5 |
use AgeGate\Common\Settings; |
| 6 |
|
| 7 |
class Preload |
| 8 |
{ |
| 9 |
private $settings; |
| 10 |
|
| 11 |
public function __construct(Settings $settings) |
| 12 |
{ |
| 13 |
$this->settings = $settings; |
| 14 |
add_action('wp_head', [$this, 'assets'], 3); |
| 15 |
} |
| 16 |
|
| 17 |
public function assets() |
| 18 |
{ |
| 19 |
if ($this->settings->logo) { |
| 20 |
echo sprintf('<link rel="preload" href="%s" as="image" />', esc_attr($this->settings->logo)); |
| 21 |
echo "\r\n"; |
| 22 |
} |
| 23 |
|
| 24 |
if ($this->settings->backgroundImage) { |
| 25 |
$file = wp_get_attachment_url($this->settings->backgroundImage); |
| 26 |
$type = wp_check_filetype($file); |
| 27 |
|
| 28 |
if (strpos($type['type'], 'image') !== false && $this->settings->logo !== $this->settings->backgroundImage) { |
| 29 |
echo sprintf('<link rel="preload" href="%s" as="image" />', esc_attr($file)); |
| 30 |
echo "\r\n"; |
| 31 |
} |
| 32 |
} |
| 33 |
} |
| 34 |
} |
| 35 |
|