| 1 |
<?php |
| 2 |
|
| 3 |
namespace AgeGate\Enqueue; |
| 4 |
|
| 5 |
use AgeGate\Common\Settings; |
| 6 |
use AgeGate\Presentation\Form; |
| 7 |
|
| 8 |
class Enqueue |
| 9 |
{ |
| 10 |
public function __construct() |
| 11 |
{ |
| 12 |
add_action('admin_enqueue_scripts', [$this, 'admin'], 99); |
| 13 |
add_action('wp_enqueue_scripts', [$this, 'assets']); |
| 14 |
} |
| 15 |
|
| 16 |
public function admin() |
| 17 |
{ |
| 18 |
if (($GLOBALS['pagenow'] ?? false) === 'plugins.php') { |
| 19 |
wp_enqueue_script('age-gate-update', AGE_GATE_URL . 'dist/update.js', [], AGE_GATE_VERSION, true); |
| 20 |
} |
| 21 |
|
| 22 |
$pages = [ |
| 23 |
'edit-tags.php', |
| 24 |
'edit.php', |
| 25 |
'post-new.php', |
| 26 |
'post.php', |
| 27 |
'term.php', |
| 28 |
'edit-tags.php', |
| 29 |
]; |
| 30 |
|
| 31 |
|
| 32 |
global $plugin_page; |
| 33 |
|
| 34 |
if ( |
| 35 |
($GLOBALS['pagenow'] ?? false) === 'admin.php' && strpos(($plugin_page ?: ''), 'age-gate') !== false |
| 36 |
|| in_array(($GLOBALS['pagenow'] ?? false), $pages)) { |
| 37 |
wp_enqueue_media(); |
| 38 |
wp_enqueue_style('age-gate-admin', AGE_GATE_URL . 'dist/admin.css', [], AGE_GATE_VERSION); |
| 39 |
|
| 40 |
wp_localize_script( |
| 41 |
'age-gate-admin', |
| 42 |
'ag_admin', |
| 43 |
[ |
| 44 |
'rest' => rest_url( 'age-gate/v3/admin/terms'), |
| 45 |
'nonce' => wp_create_nonce('wp_rest'), |
| 46 |
] |
| 47 |
); |
| 48 |
// wp_enqueue_script('age-gate-admin', AGE_GATE_URL . 'dist/admin.js', [], AGE_GATE_VERSION, true); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
public function assets() |
| 53 |
{ |
| 54 |
$settings = Settings::getInstance(); |
| 55 |
|
| 56 |
$path = sprintf('%s%s%s', AGE_GATE_URL, 'dist', ($settings->rawAssets ? '/raw' : '')); |
| 57 |
|
| 58 |
wp_enqueue_script('age-gate-all', $path . '/all.js', [], AGE_GATE_VERSION, true); |
| 59 |
|
| 60 |
wp_localize_script( 'age-gate-all', 'age_gate_common', [ |
| 61 |
'cookies' => $settings->labelNoCookies, |
| 62 |
'simple' => $settings->simplebar, |
| 63 |
]); |
| 64 |
|
| 65 |
wp_register_script('age-gate-shortcode', $path . '/shortcode.js', [], AGE_GATE_VERSION, true); |
| 66 |
|
| 67 |
if ($settings->enqueueCss) { |
| 68 |
wp_register_style('age-gate', $path . '/main.css', [], AGE_GATE_VERSION); |
| 69 |
} |
| 70 |
|
| 71 |
if ($settings->inputAutoTab && !$settings->stepped) { |
| 72 |
wp_enqueue_script('age-gate-autotab', $path . '/autotab.js', [], AGE_GATE_VERSION, !$settings->inHeader); |
| 73 |
} |
| 74 |
|
| 75 |
if ($settings->simplebar) { |
| 76 |
wp_enqueue_script('age-gate-simplebar', $path . '/simplebar.js', [], AGE_GATE_VERSION, true); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
if ($settings->stepped && $settings->inputType !== 'buttons') { |
| 81 |
wp_enqueue_style('age-gate-stepped', $path . '/stepped.css', [], AGE_GATE_VERSION); |
| 82 |
wp_enqueue_script('age-gate-stepped'); |
| 83 |
} |
| 84 |
|
| 85 |
(new Form()) |
| 86 |
->optionStyle() |
| 87 |
->enqueue(); |
| 88 |
} |
| 89 |
} |
| 90 |
|