PluginProbe
Ultimate Post Kit / trunk
Ultimate Post Kit vtrunk
4.2.1 4.2.2 4.2.3 4.5.0 4.5.2 4.5.3 4.2.0 4.1.18 4.1.17 4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 All 145 releases
ultimate-post-kit / loader.php

loader.php in Ultimate Post Kit trunk, at loader.php

392 lines 11.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace UltimatePostKit;
4
5 use Elementor\Plugin;
6 use UltimatePostKit\Admin;
7 use UltimatePostKit\Includes\Ultimate_Post_Kit_WPML;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 } // Exit if accessed directly
12
13 /**
14 * Main class for element pack
15 */
16 class Ultimate_Post_Kit_Loader {
17
18 /**
19 * @var Ultimate_Post_Kit_Loader
20 */
21 private static $_instance;
22
23 /**
24 * @var Manager
25 */
26 private $_modules_manager;
27
28 private $classes_aliases;
29
30 public $elements_data = [
31 'sections' => [],
32 'columns' => [],
33 'widgets' => [],
34 ];
35
36 /**
37 * @return string
38 * @deprecated
39 *
40 */
41 public function get_version() {
42 return BDTUPK_VER;
43 }
44
45 /**
46 * return active theme
47 */
48 public function get_theme() {
49 return wp_get_theme();
50 }
51
52 /**
53 * Throw error on object clone
54 *
55 * The whole idea of the singleton design pattern is that there is a single
56 * object therefore, we don't want the object to be cloned.
57 *
58 * @return void
59 * @since 1.0.0
60 */
61 public function __clone() {
62 // Cloning instances of the class is forbidden
63 _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'ultimate-post-kit' ), '1.6.0' );
64 }
65
66 /**
67 * Disable unserializing of the class
68 *
69 * @return void
70 * @since 1.0.0
71 */
72 public function __wakeup() {
73 // Unserializing instances of the class is forbidden
74 _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'ultimate-post-kit' ), '1.6.0' );
75 }
76
77 /**
78 * @return Plugin
79 */
80
81 public static function elementor() {
82 return Plugin::$instance;
83 }
84
85 /**
86 * @return Ultimate_Post_Kit_Loader
87 */
88 public static function instance() {
89 if ( is_null( self::$_instance ) ) {
90 self::$_instance = new self();
91 }
92 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- established hook name relied on across the plugin family; renaming would break integration.
93 do_action( 'bdthemes_ultimate_post_kit/init' );
94 return self::$_instance;
95 }
96
97
98 /**
99 * we loaded module manager + admin php from here
100 * @return [type] [description]
101 */
102 private function _includes() {
103 $category_image = ultimate_post_kit_option( 'category_image', 'ultimate_post_kit_other_settings', 'off' );
104 $duplicator = ultimate_post_kit_option( 'duplicator', 'ultimate_post_kit_other_settings', 'off' );
105 $live_copy = ultimate_post_kit_option( 'live-copy', 'ultimate_post_kit_other_settings', 'off' );
106
107
108 // Admin settings controller
109 require_once BDTUPK_ADMIN_PATH . 'module-settings.php';
110
111 // Dynamic Select control
112 require BDTUPK_INC_PATH . 'controls/select-input/dynamic-select-input-module.php';
113 require BDTUPK_INC_PATH . 'controls/select-input/dynamic-select.php';
114
115 //require BDTUPK_PATH . 'base/ultimate-post-kit-base.php';
116
117 // all widgets control from here
118 require_once BDTUPK_PATH . 'traits/global-widget-controls.php';
119 require_once BDTUPK_PATH . 'traits/global-swiper-functions.php';
120 require_once BDTUPK_INC_PATH . 'modules-manager.php';
121
122 // wpml compatibility class for wpml support
123 require_once BDTUPK_PATH . 'includes/class-elements-wpml-compatibility.php';
124
125 if ( $category_image == 'on' ) {
126 require BDTUPK_INC_PATH . 'ultimate-post-kit-category-image.php';
127 }
128 // if ($category_image == 'on') {
129 require BDTUPK_INC_PATH . 'ultimate-post-kit-metabox.php';
130 // }
131
132 // The class is namespaced, so the old unqualified class_exists() check never
133 // matched and the file could be loaded alongside a sibling plugin's duplicator.
134 // Also skip our copy entirely when Live Copy Paste is providing the same feature,
135 // since both provide the same duplicate-post admin action.
136 if ( $duplicator == 'on'
137 && ! class_exists( '\\UltimatePostKit\\Includes\\BdThemes_Duplicator' )
138 && ! class_exists( '\\ElementPack\\Includes\\BdThemes_Duplicator' )
139 && ! class_exists( '\\BdThemes_Duplicator' ) ) {
140 require BDTUPK_PATH . 'includes/class-duplicator.php';
141 }
142
143 if ( ! class_exists( '\\UltimatePostKit\\Includes\\LiveCopy\\BdThemes_Live_Copy' ) ) {
144 if ( ( $live_copy == 'on' ) && ( ! is_plugin_active( 'live-copy-paste/live-copy-paste.php' ) ) ) {
145 require_once BDTUPK_PATH . 'includes/live-copy/class-live-copy.php';
146 }
147 }
148 }
149
150 /**
151 * Autoloader function for all classes files
152 *
153 * @param [type] class [description]
154 *
155 * @return [type] [description]
156 */
157 public function autoload( $class ) {
158 if ( 0 !== strpos( $class, __NAMESPACE__ ) ) {
159 return;
160 }
161
162 $class_to_load = $class;
163
164 if ( ! class_exists( $class_to_load ) ) {
165 $filename = strtolower(
166 preg_replace(
167 [ '/^' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/' ],
168 [ '', '$1-$2', '-', DIRECTORY_SEPARATOR ],
169 $class_to_load
170 )
171 );
172 $filename = BDTUPK_PATH . $filename . '.php';
173
174 if ( is_readable( $filename ) ) {
175 include( $filename );
176 }
177 }
178 }
179
180 public function register_site_styles() {
181 $direction_suffix = is_rtl() ? '.rtl' : '';
182
183 wp_register_style( 'upk-all-styles', BDTUPK_ASSETS_URL . 'css/upk-all-styles' . $direction_suffix . '.css', [], BDTUPK_VER );
184 wp_register_style( 'upk-font', BDTUPK_ASSETS_URL . 'css/upk-font' . $direction_suffix . '.css', [], BDTUPK_VER );
185 }
186
187 public function register_site_scripts() {
188
189 // $suffix = '.min';
190
191 wp_register_script( 'goodshare', BDTUPK_ASSETS_URL . 'vendor/js/goodshare.min.js', [ 'jquery' ], '6.3.0', true );
192 wp_register_script( 'scrolline', BDTUPK_ASSETS_URL . 'vendor/js/jquery.scrolline.min.js', [ 'jquery' ], BDTUPK_VER, true );
193 wp_register_script( 'news-ticker-js', BDTUPK_ASSETS_URL . 'vendor/js/newsticker.min.js', [ 'jquery' ], BDTUPK_VER, true );
194 wp_register_script( 'fslightbox', BDTUPK_ASSETS_URL . 'vendor/js/fslightbox.min.js', [], '3.8.0', true );
195 wp_register_script( 'upk-animations', BDTUPK_ASSETS_URL . 'js/extensions/upk-animations.min.js', [ 'jquery' ], BDTUPK_VER, true );
196
197 wp_register_script( 'upk-ajax-loadmore', BDTUPK_ASSETS_URL . 'js/extensions/upk-ajax-loadmore.min.js', [ 'jquery' ], BDTUPK_VER, true );
198
199 wp_register_script( 'upk-all-scripts', BDTUPK_ASSETS_URL . 'js/upk-all-scripts.min.js', [
200 'jquery',
201 'scrolline'
202 ], BDTUPK_VER, true );
203 }
204
205
206 /**
207 * Loading site related style from here.
208 * @return [type] [description]
209 */
210 public function enqueue_site_styles() {
211
212 $direction_suffix = is_rtl() ? '.rtl' : '';
213
214 wp_register_style( 'upk-site', BDTUPK_ASSETS_URL . 'css/upk-site' . $direction_suffix . '.css', [], BDTUPK_VER );
215 wp_enqueue_style( 'upk-site' );
216 }
217
218
219 /**
220 * Loading site related script that needs all time such as uikit.
221 * @return [type] [description]
222 */
223 public function enqueue_site_scripts() {
224
225 // $suffix = '.min';
226
227
228 wp_register_script( 'upk-site', BDTUPK_ASSETS_URL . 'js/upk-site.min.js', [
229 'jquery'
230 ], BDTUPK_VER, true ); // tooltip file should be separate
231
232 wp_enqueue_script( 'upk-site' );
233
234 $script_config = [
235 'ajaxurl' => admin_url( 'admin-ajax.php' ),
236 'nonce' => wp_create_nonce( 'upk-site' ),
237 'mailchimp' => [
238 'subscribing' => esc_html_x( 'Subscribing you please wait...', 'Mailchimp String', 'ultimate-post-kit' ),
239 ],
240 'elements_data' => $this->elements_data,
241 ];
242
243
244 $script_config = apply_filters( 'ultimate_post_kit/frontend/localize_settings', $script_config );
245
246 // TODO for editor script
247 wp_localize_script( 'upk-site', 'UltimatePostKitConfig', $script_config );
248 }
249
250 public function enqueue_editor_scripts() {
251
252 // $suffix = '.min';
253
254 wp_register_script( 'upk-editor', BDTUPK_ASSETS_URL . 'js/upk-editor.min.js', [
255 'backbone-marionette',
256 'elementor-common-modules',
257 'elementor-editor-modules',
258 ], BDTUPK_VER, true );
259
260 wp_enqueue_script( 'upk-editor' );
261
262 $_is_upk_pro_activated = false;
263 if ( function_exists( 'upk_license_validation' ) && true === upk_license_validation() ) {
264 $_is_upk_pro_activated = true;
265 }
266
267 $localize_data = [
268 'pro_installed' => _is_upk_pro_activated(),
269 'pro_license_activated' => $_is_upk_pro_activated,
270 'promotional_widgets' => [],
271 ];
272
273 if ( ! $_is_upk_pro_activated ) {
274 $pro_widget_map = new \UltimatePostKit\Includes\Pro_Widget_Map();
275 $localize_data['promotional_widgets'] = $pro_widget_map->get_pro_widget_map();
276 }
277
278 wp_localize_script( 'upk-editor', 'UltimatePostKitConfigEditor', $localize_data );
279 }
280
281 /**
282 * Load editor editor related style from here
283 * @return [type] [description]
284 */
285 public function enqueue_preview_styles() {
286 $direction_suffix = is_rtl() ? '.rtl' : '';
287
288 wp_register_style( 'upk-preview', BDTUPK_ASSETS_URL . 'css/upk-preview' . $direction_suffix . '.css', '', BDTUPK_VER );
289 wp_enqueue_style( 'upk-preview' );
290 }
291
292
293 public function enqueue_editor_styles() {
294 $direction_suffix = is_rtl() ? '.rtl' : '';
295
296 wp_register_style( 'upk-editor', BDTUPK_ASSETS_URL . 'css/upk-editor' . $direction_suffix . '.css', '', BDTUPK_VER );
297 wp_register_style( 'upk-font', BDTUPK_URL . 'assets/css/upk-font' . $direction_suffix . '.css', [], BDTUPK_VER );
298
299 wp_enqueue_style( 'upk-editor' );
300 wp_add_inline_style(
301 'upk-editor',
302 '#elementor-panel{'
303 . '--upk-pro-control-tooltip:' . wp_json_encode( __( 'This is a pro control, available with Ultimate Post Kit Pro version.', 'ultimate-post-kit' ) ) . ';'
304 . '--upk-badge-new:' . wp_json_encode( __( 'NEW', 'ultimate-post-kit' ) ) . ';'
305 . '--upk-badge-pro:' . wp_json_encode( __( 'PRO', 'ultimate-post-kit' ) ) . ';'
306 . '--upk-badge-updated:' . wp_json_encode( __( 'UPDATED', 'ultimate-post-kit' ) ) . ';'
307 . '}'
308 );
309 wp_enqueue_style( 'upk-font' );
310 }
311
312 // Load WPML compatibility instance
313 public function wpml_compatiblity() {
314 return Ultimate_Post_Kit_WPML::get_instance();
315 }
316
317 /**
318 * initialize the category
319 * @return [type] [description]
320 */
321 public function ultimate_post_kit_init() {
322 $this->_modules_manager = new Manager();
323 }
324
325 /**
326 * initialize the category
327 * @return [type] [description]
328 */
329 public function ultimate_post_kit_category_register() {
330
331 $elementor = Plugin::$instance;
332
333 // Add element category in panel
334 $elementor->elements_manager->add_category( BDTUPK_SLUG, [ 'title' => BDTUPK_TITLE, 'icon' => 'font' ] );
335 }
336
337
338 private function setup_hooks() {
339 add_action( 'elementor/elements/categories_registered', [ $this, 'ultimate_post_kit_category_register' ] );
340 add_action( 'elementor/init', [ $this, 'ultimate_post_kit_init' ] );
341
342 add_action( 'elementor/editor/after_enqueue_styles', [ $this, 'enqueue_editor_styles' ] );
343 add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'enqueue_editor_scripts' ] );
344
345 add_action( 'wp_enqueue_scripts', [ $this, 'register_site_styles' ], 99999 );
346 add_action( 'wp_enqueue_scripts', [ $this, 'register_site_scripts' ], 99999 );
347 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_site_styles' ], 99999 );
348 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_site_scripts' ], 99999 );
349
350 add_action( 'elementor/preview/enqueue_styles', [ $this, 'enqueue_preview_styles' ] );
351 }
352
353 public function init(){
354 if ( ! defined( 'BDTUPK_CH' ) && is_admin() ) {
355 // Notice class
356 require_once BDTUPK_ADMIN_PATH . 'admin-biggopti.php';
357 require_once BDTUPK_ADMIN_PATH . 'admin.php';
358
359 // Load admin class for admin related content process
360 new Admin();
361 }
362 }
363
364 /**
365 * Ultimate_Post_Kit_Loader constructor.
366 */
367 private function __construct() {
368 // Register class automatically
369 spl_autoload_register( [ $this, 'autoload' ] );
370 // Include some backend files
371 $this->_includes();
372
373 // Finally hooked up all things here
374 $this->setup_hooks();
375
376 // Load WPML compatibility instance
377 $this->wpml_compatiblity()->init();
378
379 add_action( 'init', [ $this, 'init' ] );
380 }
381 }
382
383 if ( ! defined( 'BDTUPK_TESTS' ) ) {
384 // In tests we run the instance manually.
385 Ultimate_Post_Kit_Loader::instance();
386 }
387
388 // handy fundtion for push data
389 function ultimate_post_kit_config() {
390 return Ultimate_Post_Kit_Loader::instance();
391 }
392