| 1 |
<?php |
| 2 |
namespace Enteraddons\Core\Base; |
| 3 |
/** |
| 4 |
* Enteraddons admin class |
| 5 |
* |
| 6 |
* @package Enteraddons |
| 7 |
* @author ThemeLooks |
| 8 |
* @copyright 2022 ThemeLooks |
| 9 |
* @license GPL-2.0-or-later |
| 10 |
* |
| 11 |
* |
| 12 |
*/ |
| 13 |
|
| 14 |
if( !defined( 'WPINC' ) ) { |
| 15 |
die; |
| 16 |
} |
| 17 |
|
| 18 |
if( !class_exists('Enqueue_Base') ) { |
| 19 |
|
| 20 |
class Enqueue_Base { |
| 21 |
|
| 22 |
public $assetsUrl; |
| 23 |
|
| 24 |
public $style; |
| 25 |
|
| 26 |
public $script; |
| 27 |
|
| 28 |
public $localize; |
| 29 |
|
| 30 |
function __construct() { |
| 31 |
$this->assets_dir_url(); |
| 32 |
$this->set_scripts(); |
| 33 |
add_action( 'elementor/frontend/after_register_scripts', [$this, 'init_scripts'] ); |
| 34 |
} |
| 35 |
|
| 36 |
public function set_scripts() {} |
| 37 |
|
| 38 |
public function init_scripts() { |
| 39 |
// Style |
| 40 |
$this->enqueue_style(); |
| 41 |
// Scripts |
| 42 |
$this->enqueue_scripts(); |
| 43 |
// Localize Script |
| 44 |
$this->localize_script(); |
| 45 |
} |
| 46 |
|
| 47 |
public function enqueue_style() { |
| 48 |
|
| 49 |
if( !empty( $this->style ) ) { |
| 50 |
|
| 51 |
foreach( $this->style as $style ) { |
| 52 |
$deps = !empty( $style['dependency'] ) ? $style['dependency'] : array(); |
| 53 |
$version = !empty( $style['version'] ) ? $style['version'] : ENTERADDONS_VERSION; |
| 54 |
$media = !empty( $style['media'] ) ? $style['media'] : 'all'; |
| 55 |
|
| 56 |
if( !empty( $style['register'] ) && $style['register'] == true ) { |
| 57 |
wp_register_style( $style['handle'], $style['url'], $deps,$version , $media ); |
| 58 |
} else { |
| 59 |
wp_enqueue_style( $style['handle'], $style['url'], $deps, $version, $media ); |
| 60 |
} |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
} |
| 65 |
|
| 66 |
} |
| 67 |
|
| 68 |
public function enqueue_scripts() { |
| 69 |
|
| 70 |
if( !empty( $this->script ) ) { |
| 71 |
|
| 72 |
foreach( $this->script as $script ) { |
| 73 |
|
| 74 |
$deps = !empty( $script['dependency'] ) ? $script['dependency'] : array(); |
| 75 |
$version = !empty( $script['version'] ) ? $script['version'] : ENTERADDONS_VERSION; |
| 76 |
$in_footer = !empty( $script['in_footer'] ) ? $script['in_footer'] : true; |
| 77 |
|
| 78 |
if( !empty( $script['register'] ) && $script['register'] == true ) { |
| 79 |
wp_register_script( $script['handle'], $script['url'], $deps, $version, $in_footer ); |
| 80 |
} else { |
| 81 |
wp_enqueue_script( $script['handle'], $script['url'], $deps, $version, $in_footer ); |
| 82 |
} |
| 83 |
|
| 84 |
} |
| 85 |
|
| 86 |
} |
| 87 |
|
| 88 |
} |
| 89 |
|
| 90 |
public function localize_script() { |
| 91 |
|
| 92 |
if( !empty( $this->localize ) ) { |
| 93 |
foreach( $this->localize as $script ) { |
| 94 |
wp_localize_script( $script['handle'], $script['object_name'], $script['data'] ); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
} |
| 99 |
|
| 100 |
public function assets_dir_url() {} |
| 101 |
|
| 102 |
} |
| 103 |
|
| 104 |
} |