Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
93.10% covered (success)
93.10%
27 / 29
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Assets
92.86% covered (success)
92.86%
26 / 28
50.00% covered (danger)
50.00%
1 / 2
6.01
0.00% covered (danger)
0.00%
0 / 1
 init
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 admin_enqueue_scripts
92.59% covered (success)
92.59%
25 / 27
0.00% covered (danger)
0.00%
0 / 1
5.01
1<?php
2/**
3 * BeyondWords Settings Fields — asset enqueue.
4 *
5 * @package BeyondWords\Editor\Components\SettingsFields
6 * @since   7.0.0
7 */
8
9declare( strict_types = 1 );
10
11namespace BeyondWords\Editor\Components\SettingsFields;
12
13defined( 'ABSPATH' ) || exit;
14
15/**
16 * Settings Fields asset enqueue.
17 *
18 * @since 7.0.0
19 */
20class 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 Settings Fields 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--settings-fields',
49            BEYONDWORDS__PLUGIN_URI . 'src/editor/components/settings-fields/classic-metabox.js',
50            [],
51            BEYONDWORDS__PLUGIN_VERSION,
52            true
53        );
54
55        wp_localize_script(
56            'beyondwords-metabox--settings-fields',
57            'beyondwordsSettingsFields',
58            [
59                'embedLabels' => [
60                    'none'         => __( 'None', 'speechkit' ),
61                    'audio_post'   => __( 'Audio (post)', 'speechkit' ),
62                    'audio_script' => __( 'Audio (script)', 'speechkit' ),
63                    'video_post'   => __( 'Video (post)', 'speechkit' ),
64                    'video_script' => __( 'Video (script)', 'speechkit' ),
65                ],
66            ]
67        );
68
69        wp_enqueue_script( 'beyondwords-metabox--settings-fields' );
70    }
71}