PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 1.3.2
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v1.3.2
2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 1.8.1 All 42 releases
sellkit / includes / elementor / class.php

class.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster 1.3.2, at includes/elementor/class.php

263 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Sellkit\Elementor;
4
5 use Elementor\Plugin as Elementor;
6 use Elementor\Utils as ElementorUtils;
7
8 defined( 'ABSPATH' ) || die();
9
10 /**
11 * SellKit Elementor class.
12 *
13 * @since 1.1.0
14 */
15 class Sellkit_Elementor {
16
17 /**
18 * Class instance.
19 *
20 * @since 1.1.0
21 * @var Sellkit_Elementor
22 */
23 private static $instance = null;
24
25 /**
26 * Modules.
27 *
28 * @since 1.1.0
29 * @var array
30 */
31 public $modules = [];
32
33 /**
34 * Get a class instance.
35 *
36 * @since 1.1.0
37 *
38 * @return Sellkit_Elementor Class
39 */
40 public static function get_instance() {
41 if ( is_null( self::$instance ) ) {
42 self::$instance = new self();
43 }
44
45 return self::$instance;
46 }
47
48 /**
49 * Class constructor.
50 *
51 * @since 1.1.0
52 */
53 public function __construct() {
54 add_action( 'elementor/init', [ $this, 'init' ] );
55 add_action( 'elementor/frontend/after_register_scripts', [ $this, 'frontend_register_scripts' ], 10 );
56 add_action( 'elementor/frontend/after_register_styles', [ $this, 'frontend_register_styles' ], 10 );
57 add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'frontend_enqueue_styles' ], 10 );
58 add_action( 'elementor/frontend/after_enqueue_scripts', [ $this, 'frontend_enqueue_scripts' ], 10 );
59 add_action( 'elementor/editor/after_enqueue_styles', [ $this, 'editor_enqueue_styles' ], 10 );
60
61 spl_autoload_register( [ $this, 'autoload' ] );
62 remove_theme_support( 'wc-product-gallery-lightbox' );
63 }
64
65 /**
66 * Initialize.
67 *
68 * @since 1.1.0
69 */
70 public function init() {
71 $this->register_modules();
72
73 // Add this category, after basic category.
74 Elementor::$instance->elements_manager->add_category(
75 'sellkit',
76 [
77 'title' => __( 'Sellkit', 'sellkit' ),
78 'icon' => 'fa fa-plug',
79 ],
80 1
81 );
82 }
83
84 /**
85 * Initialize.
86 *
87 * @since 1.1.0
88 */
89 public function register_modules() {
90 // phpcs:disable
91 $modules = [
92 'base/base-widget',
93 'base/base-module',
94 'base/upsell-base-widget',
95 'modules/checkout',
96 'modules/order-cart-details',
97 'modules/order-details',
98 'modules/dynamic-keywords',
99 'modules/product-price',
100 'modules/product-images',
101 'modules/product-title',
102 'modules/product-description',
103 'modules/product-quantity',
104 'modules/accept-reject-button',
105 ];
106 // phpcs:enable
107
108 foreach ( $modules as $module ) {
109 // Prepare module data.
110 $module_data = explode( '/', $module );
111 $module_path = $module_data[0];
112 $module_name = $module_data[1];
113
114 // Prepare class name.
115 $class_name = str_replace( '-', ' ', $module_name );
116 $class_name = str_replace( ' ', '_', ucwords( $class_name ) );
117 $class_name = "Sellkit_Elementor_{$class_name}";
118 $class_name .= ( 'base' === $module_path ) ? '' : '_Module';
119
120 // Prepare class path.
121 $class_path = "elementor/{$module}";
122 $class_path .= ( 'base' === $module_path ) ? '' : '/module';
123
124 // Require.
125 sellkit()->load_files( [ $class_path ] );
126
127 if ( 'base' === $module_path ) {
128 continue;
129 }
130
131 // Register.
132 if ( $class_name::is_active() ) {
133 $this->modules[ $module_name ] = $class_name::get_instance();
134 }
135 }
136 }
137
138 /**
139 * Autoload classes based on namespace.
140 *
141 * @since 1.1.0
142 * @access public
143 *
144 * @param string $class Name of class.
145 */
146 public function autoload( $class ) {
147 // Return if sellkit name space is not set.
148 if ( class_exists( $class ) || 0 !== stripos( $class, __NAMESPACE__ ) ) {
149 return;
150 }
151
152 $filename = str_replace( __NAMESPACE__ . '\\', '', $class );
153 $filename = str_replace( '\\', DIRECTORY_SEPARATOR, $filename );
154 $filename = str_replace( '_', '-', $filename );
155 $filename = sellkit()->plugin_dir() . '/includes/elementor/' . strtolower( $filename ) . '.php';
156
157 // Return if file is not found.
158 if ( ! file_exists( $filename ) ) {
159 return;
160 }
161
162 include $filename;
163 }
164
165 /**
166 * Register front-end scripts
167 *
168 * @since 1.1.0
169 */
170 public function frontend_register_scripts() {
171 $suffix = ElementorUtils::is_script_debug() ? '' : '.min';
172
173 wp_register_script(
174 'sellkit-initialize-widgets',
175 sellkit()->plugin_url() . 'assets/dist/js/elementor-init' . $suffix . '.js',
176 [ 'jquery', 'wc-checkout' ],
177 sellkit()->version(),
178 true
179 );
180
181 wp_localize_script( 'sellkit-initialize-widgets', 'sellkit_elementor', $this->get_localize_data() );
182 }
183
184 /**
185 * Get localize data.
186 *
187 * @return array
188 */
189 public function get_localize_data() {
190 return [
191 'nonce' => wp_create_nonce( 'sellkit_elementor' ),
192 'wcNeedShipping' => ( function_exists( 'WC' ) ) ? WC()->cart->needs_shipping() : '',
193 ];
194 }
195
196 /**
197 * Registers styles.
198 *
199 * Registers all the front-end styles.
200 *
201 * Fires after Elementor front-end styles are registered.
202 *
203 * @since 1.1.0
204 * @access public
205 */
206 public function frontend_register_styles() {
207 $rtl = is_rtl() ? '-rtl' : '';
208 $suffix = ElementorUtils::is_script_debug() ? '' : '.min';
209
210 wp_register_style(
211 'sellkit-frontend',
212 sellkit()->plugin_url() . 'assets/dist/css/frontend' . $rtl . $suffix . '.css',
213 [],
214 sellkit()->version()
215 );
216 }
217
218 /**
219 * Enqueue all the front-end styles.
220 *
221 * Fires after Elementor front-end styles are enqueued.
222 *
223 * @since 1.1.0
224 * @access public
225 */
226 public function frontend_enqueue_styles() {
227 wp_enqueue_style( 'sellkit-frontend' );
228 }
229
230 /**
231 * Enqueue all the front-end scripts.
232 *
233 * Fires after Elementor front-end scripts are enqueued.
234 *
235 * @since 1.1.0
236 * @access public
237 */
238 public function frontend_enqueue_scripts() {
239 wp_enqueue_script( 'sellkit-initialize-widgets' );
240 }
241
242 /**
243 * Enqueue all the editor styles.
244 *
245 * Fires after Elementor editor style are enqueued.
246 *
247 * @since 1.1.0
248 * @access public
249 */
250 public function editor_enqueue_styles() {
251 $suffix = ElementorUtils::is_script_debug() ? '' : '.min';
252
253 wp_enqueue_style(
254 'sellkit-element-icons',
255 sellkit()->plugin_url() . 'assets/dist/css/editor' . $suffix . '.css',
256 [],
257 sellkit()->version()
258 );
259 }
260 }
261
262 Sellkit_Elementor::get_instance();
263