PluginProbe
Countdown Block / trunk
Countdown Block vtrunk
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 trunk, at countdown-block.php

128 lines 4.1 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.5.0
8 * Requires at least: 6.0
9 * Tested up to: 7.0
10 * Requires PHP: 7.4
11 * Author: WPDeveloper
12 * Author URI: https://wpdeveloper.net
13 * License: GPL-3.0-or-later
14 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
15 * Text Domain: countdown-block
16 *
17 * @package countdown-block
18 */
19
20 // Exit if accessed directly.
21 if ( ! defined( 'ABSPATH' ) ) {
22 exit;
23 }
24
25 /**
26 * Registers all block assets so that they can be enqueued through the block editor
27 * in the corresponding context.
28 *
29 * @see https://developer.wordpress.org/block-editor/tutorials/block-tutorial/applying-styles-with-stylesheets/
30 */
31
32 define( 'COUNTDOWN_VERSION', "1.5.0" );
33 define( 'COUNTDOWN_ADMIN_URL', plugin_dir_url( __FILE__ ) );
34 define( 'COUNTDOWN_ADMIN_PATH', dirname( __FILE__ ) );
35
36 require_once __DIR__ . '/includes/font-loader.php';
37 require_once __DIR__ . '/includes/post-meta.php';
38 require_once __DIR__ . '/includes/helpers.php';
39 require_once __DIR__ . '/lib/style-handler/style-handler.php';
40
41 function create_block_countdown_block_init() {
42
43 $script_asset_path = COUNTDOWN_ADMIN_PATH . "/dist/index.asset.php";
44 if ( ! file_exists( $script_asset_path ) ) {
45 throw new Error(
46 'You need to run `npm start` or `npm run build` for the "countdown-block/countdown" block first.'
47 );
48 }
49 $script_asset = require $script_asset_path;
50 if ( ! is_array( $script_asset ) ) {
51 $script_asset = [];
52 }
53 $asset_dependencies = isset( $script_asset['dependencies'] ) && is_array( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : [];
54 $asset_version = isset( $script_asset['version'] ) ? $script_asset['version'] : COUNTDOWN_VERSION;
55 $all_dependencies = array_merge( $asset_dependencies, [
56 'wp-blocks',
57 'wp-i18n',
58 'wp-element',
59 'wp-block-editor',
60 'countdown-controls-util',
61 'essential-blocks-eb-animation'
62 ] );
63
64 $index_js = COUNTDOWN_ADMIN_URL . 'dist/index.js';
65 wp_register_script(
66 'create-block-countdown-block-editor',
67 $index_js,
68 $all_dependencies,
69 $asset_version,
70 true
71 );
72
73 $load_animation_js = COUNTDOWN_ADMIN_URL . 'assets/js/eb-animation-load.js';
74 wp_register_script(
75 'essential-blocks-eb-animation',
76 $load_animation_js,
77 [],
78 COUNTDOWN_VERSION,
79 true
80 );
81
82 $animate_css = COUNTDOWN_ADMIN_URL . 'assets/css/animate.min.css';
83 wp_register_style(
84 'essential-blocks-animation',
85 $animate_css,
86 [],
87 COUNTDOWN_VERSION
88 );
89
90 $style_css = COUNTDOWN_ADMIN_URL . 'dist/style.css';
91 wp_register_style(
92 'create-block-countdown-block-editor-css',
93 $style_css,
94 ['essential-blocks-animation'],
95 COUNTDOWN_VERSION,
96 "all"
97 );
98
99 $frontend_js = COUNTDOWN_ADMIN_URL . 'dist/frontend/index.js';
100 wp_register_script(
101 'essential-blocks-countdown-frontend',
102 $frontend_js,
103 [],
104 COUNTDOWN_VERSION,
105 true
106 );
107
108 if ( ! WP_Block_Type_Registry::get_instance()->is_registered( 'essential-blocks/countdown' ) ) {
109 register_block_type(
110 Countdown_Helper::get_block_register_path( "countdown-block/countdown", COUNTDOWN_ADMIN_PATH ),
111 [
112 'editor_script' => 'create-block-countdown-block-editor',
113 'editor_style' => 'create-block-countdown-block-editor-css',
114 'render_callback' => function ( $attributes, $content ) {
115 if ( ! is_admin() ) {
116 wp_enqueue_style( 'create-block-countdown-block-editor-css' );
117 wp_enqueue_script( 'essential-blocks-countdown-frontend' );
118 wp_enqueue_script( 'essential-blocks-eb-animation' );
119 }
120 return $content;
121 }
122 ]
123 );
124 }
125 }
126
127 add_action( 'init', 'create_block_countdown_block_init', 99 );
128