Passed
Branch develop (133f20)
by Elvis Henrique
04:35
created

Theme::enqueue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 29
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 29
rs 9.7
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 * Theme.
4
 *
5
 * @package App
6
 */
7
8
declare(strict_types=1);
9
10
namespace App\Providers\Assets;
11
12
use WPSteak\Providers\AbstractHookProvider;
13
use WPSteak\Services\Assets;
14
15
/**
16
 * Theme class.
17
 */
18
class Theme extends AbstractHookProvider {
19
20
	use Assets;
21
22
	/**
23
	 * Register hooks.
24
	 *
25
	 * @return void
26
	 */
27
	public function register_hooks() {
28
		$this->add_action( 'wp_enqueue_scripts', 'enqueue' );
29
	}
30
31
	/**
32
	 * Enqueue.
33
	 *
34
	 * @return void
35
	 */
36
	protected function enqueue() {
37
		$handle = "{$this->plugin->get_slug()}-theme";
38
39
		$this->enqueue_script(
40
			$handle,
41
			$this->plugin->get_url( 'dist/theme.js' ),
42
			$this->plugin->get_path( 'dist/theme.js' ),
43
			[ 'jquery', 'wp-i18n' ],
44
			true
45
		);
46
47
		$this->enqueue_style(
48
			$handle,
49
			$this->plugin->get_url( 'dist/styles/theme.css' ),
50
			$this->plugin->get_path( 'dist/styles/theme.css' )
51
		);
52
53
		if ( ! function_exists( 'wp_set_script_translations' ) ) {
54
			return;
55
		}
56
57
		/**
58
		 * The `.json` file must be on following format: domain-locale-handler.json
59
		 * You can generate this file with `po2json`
60
		 */
61
		wp_set_script_translations(
62
			$handle,
63
			$this->plugin->get_slug(),
64
			$this->plugin->get_path( 'languages' )
65
		);
66
	}
67
}
68