| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Load google fonts. |
| 5 |
*/ |
| 6 |
|
| 7 |
// Exit if accessed directly. |
| 8 |
if (!defined('ABSPATH')) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
class Countdown_Helper |
| 13 |
{ |
| 14 |
private static $instance; |
| 15 |
|
| 16 |
/** |
| 17 |
* Construct Method |
| 18 |
*/ |
| 19 |
public function __construct() |
| 20 |
{ |
| 21 |
add_action('admin_enqueue_scripts', array($this, 'enqueues')); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Register the plugin |
| 26 |
*/ |
| 27 |
public static function register() |
| 28 |
{ |
| 29 |
if (null === self::$instance) { |
| 30 |
self::$instance = new self; |
| 31 |
} |
| 32 |
|
| 33 |
return self::$instance; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Enqueue function |
| 38 |
*/ |
| 39 |
public function enqueues() |
| 40 |
{ |
| 41 |
global $pagenow; |
| 42 |
|
| 43 |
/** |
| 44 |
* Only for admin add/edit pages/posts |
| 45 |
*/ |
| 46 |
$query_string = isset($_SERVER['QUERY_STRING']) ? sanitize_text_field(wp_unslash($_SERVER['QUERY_STRING'])) : ''; |
| 47 |
|
| 48 |
if ($pagenow == 'post-new.php' || $pagenow == 'post.php' || $pagenow == 'site-editor.php' || ($pagenow == 'themes.php' && !empty($query_string) && strpos($query_string, 'gutenberg-edit-site') !== false)) { |
| 49 |
|
| 50 |
$modules_asset_path = COUNTDOWN_ADMIN_PATH . '/dist/modules.asset.php'; |
| 51 |
if (!file_exists($modules_asset_path)) { |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
$controls_dependencies = require $modules_asset_path; |
| 56 |
if (!is_array($controls_dependencies)) { |
| 57 |
$controls_dependencies = array(); |
| 58 |
} |
| 59 |
$controls_deps = isset($controls_dependencies['dependencies']) && is_array($controls_dependencies['dependencies']) ? $controls_dependencies['dependencies'] : array(); |
| 60 |
$controls_version = isset($controls_dependencies['version']) ? $controls_dependencies['version'] : COUNTDOWN_VERSION; |
| 61 |
|
| 62 |
wp_register_script( |
| 63 |
"countdown-controls-util", |
| 64 |
COUNTDOWN_ADMIN_URL . '/dist/modules.js', |
| 65 |
$controls_deps, |
| 66 |
$controls_version, |
| 67 |
true |
| 68 |
); |
| 69 |
|
| 70 |
wp_localize_script('countdown-controls-util', 'EssentialBlocksLocalize', array( |
| 71 |
'eb_wp_version' => (float) get_bloginfo('version'), |
| 72 |
'rest_rootURL' => get_rest_url(), |
| 73 |
)); |
| 74 |
|
| 75 |
if ($pagenow == 'post-new.php' || $pagenow == 'post.php') { |
| 76 |
wp_localize_script('countdown-controls-util', 'eb_conditional_localize', array( |
| 77 |
'editor_type' => 'edit-post' |
| 78 |
)); |
| 79 |
} else if ($pagenow == 'site-editor.php' || $pagenow == 'themes.php') { |
| 80 |
wp_localize_script('countdown-controls-util', 'eb_conditional_localize', array( |
| 81 |
'editor_type' => 'edit-site' |
| 82 |
)); |
| 83 |
} |
| 84 |
|
| 85 |
wp_enqueue_style( |
| 86 |
'countdown-editor-css', |
| 87 |
COUNTDOWN_ADMIN_URL . 'dist/modules.css', |
| 88 |
array(), |
| 89 |
$controls_version, |
| 90 |
'all' |
| 91 |
); |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Block Register Function |
| 97 |
*/ |
| 98 |
public static function get_block_register_path($blockname, $blockPath) |
| 99 |
{ |
| 100 |
// Never float-cast a WP version string: "5.10" would cast to 5.1. |
| 101 |
// version_compare( $wp, '5.7', '<' ) is exactly the old "<= 5.6" intent. |
| 102 |
if (version_compare(get_bloginfo('version'), '5.7', '<')) { |
| 103 |
return $blockname; |
| 104 |
} else { |
| 105 |
return $blockPath; |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
Countdown_Helper::register(); |
| 111 |
|