| 1 |
<?php |
| 2 |
|
| 3 |
namespace Depicter\Modules; |
| 4 |
|
| 5 |
|
| 6 |
use Depicter\Modules\Elementor\SliderWidget; |
| 7 |
use Depicter\Modules\WooCommerce\Module; |
| 8 |
use WPEmerge\ServiceProviders\ServiceProviderInterface; |
| 9 |
|
| 10 |
/** |
| 11 |
* Register widgets. |
| 12 |
*/ |
| 13 |
class ModulesServiceProvider implements ServiceProviderInterface { |
| 14 |
/** |
| 15 |
* {@inheritDoc} |
| 16 |
*/ |
| 17 |
public function register( $container ) { |
| 18 |
add_action( 'plugins_loaded', [ $this, 'elementorModulesLoaded' ] ); |
| 19 |
$this->modulesLoaded(); |
| 20 |
|
| 21 |
$app = $container[ WPEMERGE_APPLICATION_KEY ]; |
| 22 |
|
| 23 |
$container[ 'depicter.modules.manager' ] = function () { |
| 24 |
return new Modules(); |
| 25 |
}; |
| 26 |
$app->alias( 'modules', 'depicter.modules.manager' ); |
| 27 |
|
| 28 |
$container[ 'depicter.modules.woocommerce' ] = function () { |
| 29 |
return new Module(); |
| 30 |
}; |
| 31 |
$app->alias( 'WooCommerce', 'depicter.modules.woocommerce' ); |
| 32 |
} |
| 33 |
|
| 34 |
public function elementorModulesLoaded() { |
| 35 |
if( defined( 'ELEMENTOR_VERSION' ) ){ |
| 36 |
New Elementor\Module(); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
public function modulesLoaded(){ |
| 41 |
|
| 42 |
add_action( 'init', [ $this, 'loadGutenbergModule' ] ); |
| 43 |
|
| 44 |
add_action( 'init', [ $this, 'initBeaverModule' ] ); |
| 45 |
add_action( 'wp_enqueue_scripts', [ $this, 'load_beaver_builder_widget_script'] ); |
| 46 |
|
| 47 |
add_action( 'vc_before_init', [ $this, 'initWPBakeryModule' ] ); |
| 48 |
add_action( 'init', [ $this, 'initDiviModule' ], 99 ); |
| 49 |
|
| 50 |
add_action( 'init', [ $this, 'loadOxygenModule' ] ); |
| 51 |
|
| 52 |
add_action( 'init', [ $this, 'loadBricksElements'], 11 ); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* {@inheritDoc} |
| 57 |
*/ |
| 58 |
public function bootstrap( $container ) { |
| 59 |
|
| 60 |
} |
| 61 |
|
| 62 |
public function load_beaver_builder_widget_script() { |
| 63 |
if ( class_exists( '\FLBuilderModel' ) && \FLBuilderModel::is_builder_active() ) { |
| 64 |
$this->enqueueEditorScripts(); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
public function enqueueEditorScripts() { |
| 69 |
|
| 70 |
\Depicter::core()->assets()->enqueueStyle( |
| 71 |
'depicter-admin', |
| 72 |
\Depicter::core()->assets()->getUrl() . '/resources/styles/admin/admin.css' |
| 73 |
); |
| 74 |
|
| 75 |
\Depicter::core()->assets()->enqueueScript( |
| 76 |
'depicter-admin', |
| 77 |
\Depicter::core()->assets()->getUrl() . '/resources/scripts/admin/index.js', |
| 78 |
['jquery'], |
| 79 |
true |
| 80 |
); |
| 81 |
|
| 82 |
wp_localize_script( 'depicter-admin', 'depicterParams',[ |
| 83 |
'ajaxUrl' => admin_url( 'admin-ajax.php' ), |
| 84 |
'editorUrl' => \Depicter::editor()->getEditUrl('1'), |
| 85 |
'token' => \Depicter::csrf()->getToken( \Depicter\Security\CSRF::EDITOR_ACTION ), |
| 86 |
'publishedText' => esc_html__( 'Published', 'depicter' ) |
| 87 |
]); |
| 88 |
} |
| 89 |
|
| 90 |
public function loadGutenbergModule() { |
| 91 |
require_once 'Gutenberg/module.php'; |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* Load beaver builder module |
| 96 |
* |
| 97 |
* @return void |
| 98 |
*/ |
| 99 |
public function initBeaverModule() { |
| 100 |
if ( class_exists( '\FLBuilder' ) ) { |
| 101 |
require_once 'Beaver/module.php'; |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* Load WPBakery module |
| 107 |
* |
| 108 |
* @return void |
| 109 |
*/ |
| 110 |
public function initWPBakeryModule() { |
| 111 |
require_once 'WPBakery/module.php'; |
| 112 |
|
| 113 |
if ( !empty( $_GET['vc_action'] ) && $_GET['vc_action'] == 'vc_inline' ) { |
| 114 |
$this->enqueueEditorScripts(); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Load divi module |
| 120 |
* |
| 121 |
* @return void |
| 122 |
*/ |
| 123 |
public function initDiviModule() { |
| 124 |
if ( class_exists( 'DiviExtension' ) ) { |
| 125 |
require_once 'Divi/depicter-divi.php'; |
| 126 |
|
| 127 |
if ( !empty( $_GET['et_fb'] ) ) { |
| 128 |
add_action( 'wp_enqueue_scripts', [ $this, 'enqueueEditorScripts' ] ); |
| 129 |
} |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
public function loadOxygenModule() { |
| 134 |
if ( class_exists('\OxyEl') ) { |
| 135 |
require_once 'Oxygen/module.php'; |
| 136 |
} |
| 137 |
|
| 138 |
if ( isset( $_GET['ct_builder'] ) ) { |
| 139 |
add_action( 'wp_enqueue_scripts', [ $this, 'enqueueEditorScripts' ] ); |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
public function loadBricksElements() { |
| 144 |
if ( ! class_exists( '\Bricks\Elements' ) ) { |
| 145 |
return; |
| 146 |
} |
| 147 |
|
| 148 |
\Bricks\Elements::register_element( __DIR__ . '/Bricks/widget.php', ); |
| 149 |
} |
| 150 |
} |
| 151 |
|