| 1 | <?php declare(strict_types = 1); |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 2 | |||
| 3 | namespace App\Providers\Assets; |
||
| 4 | |||
| 5 | use WPSteak\Providers\AbstractHookProvider; |
||
| 6 | use WPSteak\Services\Assets; |
||
| 7 | |||
| 8 | class Theme extends AbstractHookProvider { |
||
| 9 | |||
| 10 | use Assets; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * {@inheritDoc} |
||
| 14 | */ |
||
| 15 | public function register_hooks(): void { |
||
| 16 | $this->add_action( 'wp_enqueue_scripts', 'enqueue' ); |
||
| 17 | } |
||
| 18 | |||
| 19 | protected function enqueue(): void { |
||
|
0 ignored issues
–
show
|
|||
| 20 | $handle = "{$this->plugin->get_slug()}-theme"; |
||
| 21 | |||
| 22 | $this->enqueue_script( |
||
| 23 | $handle, |
||
| 24 | $this->plugin->get_url( 'dist/theme.js' ), |
||
| 25 | $this->plugin->get_path( 'dist/theme.js' ), |
||
| 26 | ['jquery', 'wp-i18n'], |
||
| 27 | true, |
||
|
0 ignored issues
–
show
|
|||
| 28 | ); |
||
| 29 | |||
| 30 | $this->enqueue_style( |
||
| 31 | $handle, |
||
| 32 | $this->plugin->get_url( 'dist/styles/theme.css' ), |
||
| 33 | $this->plugin->get_path( 'dist/styles/theme.css' ), |
||
|
0 ignored issues
–
show
|
|||
| 34 | ); |
||
| 35 | |||
| 36 | if ( ! function_exists( 'wp_set_script_translations' ) ) { |
||
| 37 | return; |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * The `.json` file must be on following format: domain-locale-handler.json |
||
| 42 | * You can generate this file with `po2json` |
||
| 43 | */ |
||
| 44 | wp_set_script_translations( |
||
| 45 | $handle, |
||
| 46 | $this->plugin->get_slug(), |
||
| 47 | $this->plugin->get_path( 'languages' ), |
||
|
0 ignored issues
–
show
|
|||
| 48 | ); |
||
| 49 | } |
||
| 50 | |||
| 51 | } |
||
| 52 |