BaseHooks.php
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace WPML\Compatibility\FusionBuilder;
abstract class BaseHooks {
const HANDLE = 'wpml-compatibility-fusion';
const SCRIPT_SRC = '/dist/js/compatibility/fusion_builder/app.js';
const STYLE_SRC = '/res/css/compatibility/fusion_builder.css';
const OBJECT_NAME = 'WPML_COMPATIBILITY_FUSION';
protected function enqueue_style() {
self::check_asset( self::STYLE_SRC );
wp_enqueue_style(
self::HANDLE,
self::get_url( self::STYLE_SRC ),
[],
ICL_SITEPRESS_VERSION
);
}
protected function enqueue_script() {
self::check_asset( self::SCRIPT_SRC );
wp_enqueue_script(
self::HANDLE,
self::get_url( self::SCRIPT_SRC ),
[],
ICL_SITEPRESS_VERSION,
true
);
}
protected function localize_script( $data ) {
wp_localize_script(
self::HANDLE,
self::OBJECT_NAME,
$data
);
}
/**
* This class was originally located in WPML Core
* and later moved to WPML Page Builders addons.
* As we don't have needs to build JS/CSS assets
* in the WPML Page Builder addon, and we want to keep
* a simple build here, we'll keep the assets in Core
* (where it's built).
*
* @param string $uri
*
* @throws \Exception
*/
private static function check_asset( $uri ) {
$filepath = WPML_PLUGIN_PATH . $uri;
if ( ! file_exists( $filepath ) ) {
throw new \Exception( "The asset $filepath is missing in WPML Core" );
}
}
/**
* @param string $uri
*
* @return string
*/
private static function get_url( $uri ) {
return ICL_PLUGIN_URL . $uri;
}
}