1 | <?php |
---|
2 | namespace AsinSmartInternationalLinks\Includes; |
---|
3 | |
---|
4 | class Loader |
---|
5 | { |
---|
6 | protected $plugin_name; |
---|
7 | protected $plugin_version; |
---|
8 | |
---|
9 | public function __construct() |
---|
10 | { |
---|
11 | $this->plugin_version = defined('ASINSMARTINTERNATIONALLINKS_VERSION') ? ASINSMARTINTERNATIONALLINKS_VERSION : '1.0.0'; |
---|
12 | $this->plugin_name = 'asin-smart-links'; |
---|
13 | $this->load_dependencies(); |
---|
14 | |
---|
15 | add_action('plugins_loaded', [$this, 'load_plugin_textdomain']); |
---|
16 | add_action('wp_enqueue_scripts', [$this, 'register_scripts']); |
---|
17 | } |
---|
18 | |
---|
19 | private function load_dependencies() |
---|
20 | { |
---|
21 | foreach (glob(ASINSMARTINTERNATIONALLINKS_PATH . 'Functionality/*.php') as $filename) { |
---|
22 | $class_name = '\\AsinSmartInternationalLinks\Functionality\\'. basename($filename, '.php'); |
---|
23 | if (class_exists($class_name)) { |
---|
24 | try { |
---|
25 | new $class_name($this->plugin_name, $this->plugin_version); |
---|
26 | } |
---|
27 | catch (\Throwable $e) { |
---|
28 | pb_log($e); |
---|
29 | continue; |
---|
30 | } |
---|
31 | } |
---|
32 | } |
---|
33 | } |
---|
34 | |
---|
35 | public function load_plugin_textdomain() |
---|
36 | { |
---|
37 | load_plugin_textdomain('asin-smart-links', false, dirname(ASINSMARTINTERNATIONALLINKS_BASENAME) . '/languages/'); |
---|
38 | } |
---|
39 | |
---|
40 | public function register_scripts() |
---|
41 | { |
---|
42 | wp_register_style( $this->plugin_name . '-styles', ASINSMARTINTERNATIONALLINKS_URL . 'dist/app.css', [], $this->plugin_version, 'all' ); |
---|
43 | wp_register_script( $this->plugin_name . '-script', ASINSMARTINTERNATIONALLINKS_URL . 'dist/app.js', [], $this->plugin_version, 'all' ); |
---|
44 | } |
---|
45 | } |
---|