Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
91.67% |
22 / 24 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Assets | |
91.30% |
21 / 23 |
|
50.00% |
1 / 2 |
6.02 | |
0.00% |
0 / 1 |
| init | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| admin_enqueue_scripts | |
90.91% |
20 / 22 |
|
0.00% |
0 / 1 |
5.02 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * BeyondWords Content ID — asset enqueue. |
| 4 | * |
| 5 | * @package BeyondWords\Editor\Components\ContentId |
| 6 | * @since 7.0.0 |
| 7 | */ |
| 8 | |
| 9 | declare( strict_types = 1 ); |
| 10 | |
| 11 | namespace BeyondWords\Editor\Components\ContentId; |
| 12 | |
| 13 | defined( 'ABSPATH' ) || exit; |
| 14 | |
| 15 | /** |
| 16 | * Content ID 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( 'admin_enqueue_scripts', [ self::class, 'admin_enqueue_scripts' ] ); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Enqueue the Content ID JS on classic-editor post screens. |
| 31 | * |
| 32 | * @param string $hook Current admin page hook. |
| 33 | */ |
| 34 | public static function admin_enqueue_scripts( $hook ): void { |
| 35 | if ( \BeyondWords\Core\Utils::is_gutenberg_page() ) { |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | if ( 'post.php' !== $hook && 'post-new.php' !== $hook ) { |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | if ( ! in_array( get_post_type(), \BeyondWords\Settings\Utils::get_compatible_post_types(), true ) ) { |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | wp_register_script( |
| 48 | 'beyondwords-metabox--content-id', |
| 49 | BEYONDWORDS__PLUGIN_URI . 'src/editor/components/content-id/classic-metabox.js', |
| 50 | [ 'wp-i18n' ], |
| 51 | BEYONDWORDS__PLUGIN_VERSION, |
| 52 | true |
| 53 | ); |
| 54 | |
| 55 | wp_localize_script( |
| 56 | 'beyondwords-metabox--content-id', |
| 57 | 'beyondwordsData', |
| 58 | [ |
| 59 | 'nonce' => wp_create_nonce( 'wp_rest' ), |
| 60 | 'root' => esc_url_raw( rest_url() ), |
| 61 | ] |
| 62 | ); |
| 63 | |
| 64 | wp_enqueue_script( 'beyondwords-metabox--content-id' ); |
| 65 | } |
| 66 | } |