| 1 |
<?php |
| 2 |
/** |
| 3 |
* BeyondWords block-editor asset enqueue. |
| 4 |
* |
| 5 |
* @package BeyondWords\Editor\Block |
| 6 |
* @since 7.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
declare( strict_types = 1 ); |
| 10 |
|
| 11 |
namespace BeyondWords\Editor\Block; |
| 12 |
|
| 13 |
defined( 'ABSPATH' ) || exit; |
| 14 |
|
| 15 |
/** |
| 16 |
* Block-editor asset enqueue. |
| 17 |
* |
| 18 |
* @since 7.0.0 |
| 19 |
*/ |
| 20 |
class Assets { |
| 21 |
|
| 22 |
/** |
| 23 |
* Register WordPress hooks. |
| 24 |
*/ |
| 25 |
public static function init(): void { |
| 26 |
add_action( 'enqueue_block_editor_assets', [ self::class, 'enqueue_block_editor_assets' ], 1, 0 ); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Enqueue the bundled block-editor JS on compatible post-type screens. |
| 31 |
* |
| 32 |
* No API-valid check needed: class-plugin.php only calls init() with a |
| 33 |
* valid API connection. |
| 34 |
*/ |
| 35 |
public static function enqueue_block_editor_assets(): void { |
| 36 |
if ( ! in_array( get_post_type(), \BeyondWords\Settings\Utils::get_compatible_post_types(), true ) ) { |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
$asset_file = include BEYONDWORDS__PLUGIN_DIR . 'build/index.asset.php'; |
| 41 |
|
| 42 |
wp_enqueue_script( |
| 43 |
'beyondwords-block-js', |
| 44 |
BEYONDWORDS__PLUGIN_URI . 'build/index.js', |
| 45 |
$asset_file['dependencies'], |
| 46 |
$asset_file['version'], |
| 47 |
true |
| 48 |
); |
| 49 |
} |
| 50 |
} |
| 51 |
|