| 1 |
<?php |
| 2 |
/** |
| 3 |
* Uji Countdown Front |
| 4 |
* |
| 5 |
* Handles back-end blocks |
| 6 |
* |
| 7 |
* @author WPmanage |
| 8 |
* @category Blocks support |
| 9 |
* @package Uji-Countdown |
| 10 |
* @version 2.1 |
| 11 |
*/ |
| 12 |
|
| 13 |
// Exit if accessed directly. |
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Enqueue Gutenberg block assets for both frontend + backend. |
| 20 |
* |
| 21 |
*/ |
| 22 |
function uji_countdown_2020_uji_block_assets() { // phpcs:ignore |
| 23 |
// Register block styles for both frontend + backend. |
| 24 |
wp_register_style( |
| 25 |
'uji_countdown_2020-uji-style-css', // Handle. |
| 26 |
plugins_url( 'dist/style-ujicount.css', dirname( __FILE__ ) ), // Block style CSS. |
| 27 |
is_admin() ? array( 'wp-editor' ) : null, // Dependency to include the CSS after it. |
| 28 |
null // filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.style.build.css' ) // Version: File modification time. |
| 29 |
); |
| 30 |
|
| 31 |
// Register block editor script for backend. |
| 32 |
wp_register_script( |
| 33 |
'uji_countdown_2020-uji-block-js', // Handle. |
| 34 |
plugins_url( '/dist/ujicount.js', dirname( __FILE__ ) ), // Block.build.js: We register the block here. Built with Webpack. |
| 35 |
array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ), // Dependencies, defined above. |
| 36 |
null, // filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.build.js' ), // Version: filemtime — Gets file modification time. |
| 37 |
true // Enqueue the script in the footer. |
| 38 |
); |
| 39 |
|
| 40 |
// Register block editor styles for backend. |
| 41 |
wp_register_style( |
| 42 |
'uji_countdown_2020-uji-block-editor-css', // Handle. |
| 43 |
plugins_url( 'dist/style-ujicount.css', dirname( __FILE__ ) ), // Block editor CSS. |
| 44 |
array( 'wp-edit-blocks' ), // Dependency to include the CSS after it. |
| 45 |
null // filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: File modification time. |
| 46 |
); |
| 47 |
|
| 48 |
// WP Localized globals. Use dynamic PHP stuff in JavaScript via `ujiGlobal` object. |
| 49 |
wp_localize_script( |
| 50 |
'uji_countdown_2020-uji-block-js', |
| 51 |
'ujiGlobal', // Array containing dynamic data for a JS Global. |
| 52 |
[ |
| 53 |
'pluginDirPath' => plugin_dir_path( __DIR__ ), |
| 54 |
'pluginDirUrl' => plugin_dir_url( __DIR__ ), |
| 55 |
// Add more data here that you want to access from `ujiGlobal` object. |
| 56 |
] |
| 57 |
); |
| 58 |
|
| 59 |
/** |
| 60 |
* Register Gutenberg block on server-side. |
| 61 |
* |
| 62 |
* @link https://wordpress.org/gutenberg/handbook/blocks/writing-your-first-block-type#enqueuing-block-scripts |
| 63 |
* @since 1.16.0 |
| 64 |
*/ |
| 65 |
register_block_type( |
| 66 |
'urc/block-uji-countdown-2020', array( |
| 67 |
// Enqueue blocks.style.build.css on both frontend & backend. |
| 68 |
'style' => 'uji_countdown_2020-uji-style-css', |
| 69 |
// Enqueue blocks.build.js in the editor only. |
| 70 |
'editor_script' => 'uji_countdown_2020-uji-block-js', |
| 71 |
// Enqueue blocks.editor.build.css in the editor only. |
| 72 |
'editor_style' => 'uji_countdown_2020-uji-block-editor-css', |
| 73 |
) |
| 74 |
); |
| 75 |
|
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
// Hook: Block assets. |
| 80 |
add_action( 'init', 'uji_countdown_2020_uji_block_assets' ); |