| 1 |
<?php |
| 2 |
/** |
| 3 |
* Enqueue global block-related assets for admin. |
| 4 |
* |
| 5 |
* @package gutenify |
| 6 |
* @subpackage Assets |
| 7 |
* @since 1.0.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace gutenify; |
| 11 |
|
| 12 |
/** |
| 13 |
* Load assets for our blocks. |
| 14 |
* |
| 15 |
* @package Gutenify |
| 16 |
*/ |
| 17 |
|
| 18 |
// Exit if accessed directly. |
| 19 |
defined( 'ABSPATH' ) || exit; |
| 20 |
|
| 21 |
/** |
| 22 |
* Class Block_Editor_Assets |
| 23 |
* |
| 24 |
* Handles registration and enqueueing of scripts/styles |
| 25 |
* used by custom Gutenberg block enhancements. |
| 26 |
*/ |
| 27 |
class Block_Editor_Assets { |
| 28 |
/** |
| 29 |
* Hook into WordPress. |
| 30 |
* |
| 31 |
* @return void |
| 32 |
*/ |
| 33 |
public static function init() { |
| 34 |
add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'enqueue_block_editor_assets' ) ); |
| 35 |
} |
| 36 |
|
| 37 |
public static function enqueue_block_editor_assets() { |
| 38 |
// Plugin constants and flags. |
| 39 |
$constants = Helpers::plugin_constants(); |
| 40 |
$is_pro_active = Helpers::is_pro_active(); |
| 41 |
$plugin_main_slug = $constants['plugin_main_slug']; |
| 42 |
$plugin_main_base_url = Helpers::core_base_url(); |
| 43 |
$plugin_main_base_dir = Helpers::core_base_dir(); |
| 44 |
|
| 45 |
$asset_paths = array( |
| 46 |
// Admin. |
| 47 |
'admin-global' => array( |
| 48 |
'path' => 'dist/non-blocks/admin/global', |
| 49 |
), |
| 50 |
'extend-block-inspector-controls' => array( |
| 51 |
'path' => 'dist/non-blocks/extend/block-inspector-controls', |
| 52 |
), |
| 53 |
'extend-block-dynamic-css' => array( |
| 54 |
'path' => 'dist/non-blocks/extend/block-dynamic-css', |
| 55 |
), |
| 56 |
'extend-block-spacing' => array( |
| 57 |
'path' => 'dist/non-blocks/extend/block-spacing', |
| 58 |
), |
| 59 |
'extend-block-position' => array( |
| 60 |
'path' => 'dist/non-blocks/extend/block-position', |
| 61 |
), |
| 62 |
// 'extend-block-custom-css' => array( |
| 63 |
// 'path' => 'dist/non-blocks/extend/block-custom-css', |
| 64 |
// ), |
| 65 |
'extend-block-pro-notice' => array( |
| 66 |
'path' => 'dist/non-blocks/extend/block-pro-notice', |
| 67 |
), |
| 68 |
// 'extend-custom-list' => array( |
| 69 |
// 'path' => 'dist/non-blocks/extend/custom-list', |
| 70 |
// ), |
| 71 |
); |
| 72 |
|
| 73 |
if ( $is_pro_active ) { |
| 74 |
$asset_paths['extend-block-custom-css'] = array( |
| 75 |
'path' => 'dist/non-blocks/extend/block-custom-css', |
| 76 |
); |
| 77 |
} |
| 78 |
|
| 79 |
foreach ( $asset_paths as $handle => $asset ) { |
| 80 |
$path = $asset['path']; |
| 81 |
$asset_file = gutenify_get_block_asset_file_values( sprintf( '%s' . $path . '/index.asset.php', $plugin_main_base_dir ) ); |
| 82 |
$handle = $plugin_main_slug . '-' . str_replace( '/', '-', $handle ); |
| 83 |
|
| 84 |
$deps = ! empty( $asset['js_dependencies'] ) ? array_merge( $asset_file['dependencies'], $asset['js_dependencies'] ) : $asset_file['dependencies']; |
| 85 |
wp_enqueue_script( $handle, $plugin_main_base_url . $path . '/index.js', $deps, $asset_file['version'], true ); |
| 86 |
|
| 87 |
if ( file_exists( $plugin_main_base_dir . $path . '/index.css' ) ) { |
| 88 |
$deps = ! empty( $asset['style_dependencies'] ) ? $asset['style_dependencies'] : array(); |
| 89 |
wp_enqueue_style( $handle, $plugin_main_base_url . $path . '/index.css', $deps, $asset_file['version'] ); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
wp_enqueue_style( $plugin_main_slug . '-fontawesome' ); |
| 94 |
wp_enqueue_style( $plugin_main_slug . '-fonts' ); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
// Initialize the asset loader. |
| 99 |
Block_Editor_Assets::init(); |
| 100 |
|