PluginProbe
Countdown Block / 1.2.1
Countdown Block v1.2.1
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.5.0
countdown-block / countdown-block.php

countdown-block.php in Countdown Block 1.2.1, at countdown-block.php

128 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Name: Countdown Block
5 * Plugin URI: https://essential-blocks.com
6 * Description: Highlight Upcoming Events With Countdown Timer.
7 * Version: 1.2.1
8 * Author: WPDeveloper
9 * Author URI: https://wpdeveloper.net
10 * License: GPL-3.0-or-later
11 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
12 * Text Domain: countdown-block
13 *
14 * @package countdown-block
15 */
16
17 /**
18 * Registers all block assets so that they can be enqueued through the block editor
19 * in the corresponding context.
20 *
21 * @see https://developer.wordpress.org/block-editor/tutorials/block-tutorial/applying-styles-with-stylesheets/
22 */
23
24
25 define('COUNTDOWN_VERSION', "1.2.1");
26 define('COUNTDOWN_ADMIN_URL', plugin_dir_url(__FILE__));
27 define('COUNTDOWN_ADMIN_PATH', dirname(__FILE__));
28
29 require_once __DIR__ . '/includes/font-loader.php';
30 require_once __DIR__ . '/includes/post-meta.php';
31 require_once __DIR__ . '/includes/helpers.php';
32 require_once __DIR__ . '/lib/style-handler/style-handler.php';
33
34 function create_block_countdown_block_init()
35 {
36
37 $script_asset_path = COUNTDOWN_ADMIN_PATH . "/dist/index.asset.php";
38 if (!file_exists($script_asset_path)) {
39 throw new Error(
40 'You need to run `npm start` or `npm run build` for the "countdown-block/countdown" block first.'
41 );
42 }
43 $script_asset = require($script_asset_path);
44 $all_dependencies = array_merge($script_asset['dependencies'], array(
45 'wp-blocks',
46 'wp-i18n',
47 'wp-element',
48 'wp-block-editor',
49 'countdown-controls-util',
50 ));
51
52 $index_js = COUNTDOWN_ADMIN_URL . 'dist/index.js';
53 wp_register_script(
54 'create-block-countdown-block-editor',
55 $index_js,
56 $all_dependencies,
57 $script_asset['version'],
58 true
59 );
60
61 $style_css = COUNTDOWN_ADMIN_URL . 'dist/style.css';
62 wp_register_style(
63 'create-block-countdown-block-editor',
64 $style_css,
65 array(),
66 COUNTDOWN_VERSION,
67 "all"
68 );
69
70
71 $frontend_js = COUNTDOWN_ADMIN_URL . 'dist/frontend/index.js';
72 wp_register_script(
73 'essential-blocks-countdown-frontend',
74 $frontend_js,
75 array(),
76 COUNTDOWN_VERSION,
77 true
78 );
79
80
81 //
82 //
83 //
84 $controls_dependencies = require COUNTDOWN_ADMIN_PATH . '/dist/controls.asset.php';
85
86 wp_register_script(
87 "countdown-controls-util",
88 COUNTDOWN_ADMIN_URL . '/dist/controls.js',
89 array_merge($controls_dependencies['dependencies'], array("essential-blocks-edit-post")),
90 $controls_dependencies['version'],
91 true
92 );
93
94 wp_localize_script('countdown-controls-util', 'EssentialBlocksLocalize', array(
95 'eb_wp_version' => (float) get_bloginfo('version'),
96 'rest_rootURL' => get_rest_url(),
97 ));
98
99 wp_register_style(
100 'countdown-editor-css',
101 COUNTDOWN_ADMIN_URL . '/dist/controls.css',
102 array(
103 "create-block-countdown-block-editor"
104 ),
105 $controls_dependencies['version'],
106 'all'
107 );
108
109 if (!WP_Block_Type_Registry::get_instance()->is_registered('essential-blocks/countdown')) {
110 register_block_type(
111 Countdown_Helper::get_block_register_path("countdown-block/countdown", COUNTDOWN_ADMIN_PATH),
112 array(
113 'editor_script' => 'create-block-countdown-block-editor',
114 'editor_style' => 'countdown-editor-css',
115 'render_callback' => function ($attributes, $content) {
116 if (!is_admin()) {
117 wp_enqueue_script('essential-blocks-countdown-frontend');
118 wp_enqueue_style('create-block-countdown-block-editor');
119 }
120 return $content;
121 }
122 )
123 );
124 }
125 }
126
127 add_action('init', 'create_block_countdown_block_init');
128