PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 2.8.16
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v2.8.16
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / includes / core / widgets / elementor / class-manager.php

class-manager.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 2.8.16, at includes/core/widgets/elementor/class-manager.php

373 lines 10.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Elementor manager
4 *
5 * @package
6 */
7 namespace WPFunnels\Widgets\Elementor;
8 use WPFunnels\Widgets\Elementor\Controls\Optin_Styles;
9 use WPFunnels\Widgets\Elementor\Controls\Product_Control;
10 use WPFunnels\Wpfnl_functions;
11
12
13 if (!defined('ABSPATH')) {
14 exit; // Exit if accessed directly.
15 }
16
17 /**
18 * Main Elementor Test Extension Class
19 *
20 * The main class that initiates and runs the plugin.
21 *
22 * @since 1.0.0
23 */
24 final class Manager
25 {
26
27 /**
28 * Plugin Version
29 *
30 * @since 1.0.0
31 *
32 * @var string The plugin version.
33 */
34 const VERSION = WPFNL_VERSION;
35
36 /**
37 * Minimum Elementor Version
38 *
39 * @since 1.0.0
40 *
41 * @var string Minimum Elementor version required to run the plugin.
42 */
43 const MINIMUM_ELEMENTOR_VERSION = '2.0.0';
44
45 /**
46 * Minimum PHP Version
47 *
48 * @since 1.0.0
49 *
50 * @var string Minimum PHP version required to run the plugin.
51 */
52 const MINIMUM_PHP_VERSION = '7.0';
53
54 /**
55 * Instance
56 *
57 * @since 1.0.0
58 *
59 * @access private
60 * @static
61 *
62 * @var Manager The single instance of the class.
63 */
64 private static $_instance = null;
65
66 /**
67 * Instance
68 *
69 * Ensures only one instance of the class is loaded or can be loaded.
70 *
71 * @return Manager An instance of the class.
72 * @since 1.0.0
73 *
74 * @access public
75 * @static
76 */
77 public static function instance() {
78 if (is_null(self::$_instance)) {
79 self::$_instance = new self();
80 }
81 return self::$_instance;
82 }
83
84 /**
85 * Constructor
86 *
87 * @since 1.0.0
88 *
89 * @access public
90 */
91 public function __construct() {
92
93 if( $this->is_compatible() ) {
94 add_action('elementor/init', [$this, 'init']);
95 add_action( 'elementor/editor/after_enqueue_styles', array( $this, 'enqueue_elementor_custom_style' ) );
96 add_filter( 'wpfunnels/page_template', array( $this, 'get_page_template' ) );
97 }
98
99 }
100
101
102 /**
103 * Add css file on Elementor admin
104 *
105 * @since 1.0.0
106 *
107 * @access public
108 */
109 public function enqueue_elementor_custom_style()
110 {
111 wp_enqueue_style('elementor-icon', WPFNL_URL. 'includes/core/widgets/elementor/assets/css/elemetor-icon-style.css');
112 }
113
114 /**
115 * Compatibility Checks
116 *
117 * Checks if the installed version of Elementor meets the plugin's minimum requirement.
118 * Checks if the installed PHP version meets the plugin's minimum requirement.
119 *
120 * @since 1.0.0
121 *
122 * @access public
123 */
124 public function is_compatible() {
125
126 // Check if Elementor installed and activated
127 if (!did_action('elementor/loaded')) {
128 return false;
129 }
130
131 // Check for required Elementor version
132 if (!version_compare(ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=')) {
133 return false;
134 }
135
136 // Check for required PHP version
137 if (version_compare(PHP_VERSION, self::MINIMUM_PHP_VERSION, '<')) {
138 return false;
139 }
140
141 return true;
142
143 }
144
145 /**
146 * Initialize the plugin
147 *
148 * Load the plugin only after Elementor (and other plugins) are loaded.
149 * Load the files required to run the plugin.
150 *
151 * Fired by `plugins_loaded` action hook.
152 *
153 * @since 1.0.0
154 *
155 * @access public
156 */
157 public function init() {
158
159 $editor_compatibility = Elemenetor_Editror_Compatibility::getInstance();
160 $editor_compatibility->elementor_compatibility();
161
162 add_action('elementor/init', [$this, 'add_elementor_widget_categories'],9999);
163 if ( version_compare(ELEMENTOR_VERSION, '3.5.0', '>=') ) {
164 add_action('elementor/widgets/register', [$this, 'init_widgets']);
165 } else {
166 add_action('elementor/widgets/widgets_registered', [$this, 'init_widgets']);
167 }
168
169 add_action('elementor/controls/controls_registered', [$this, 'init_controls']);
170 }
171
172
173 /**
174 * Register Category
175 *
176 * @since 1.0.0
177 *
178 * @access private
179 */
180 public function add_elementor_widget_categories()
181 {
182
183
184 $elementsManager = \Elementor\Plugin::instance()->elements_manager;
185 $elementsManager->add_category(
186 'wp-funnel',
187 [
188 'title' => __('WPFunnels', 'wpfnl'),
189 'icon' => 'fa fa-plug',
190 ]
191 );
192 }
193
194 /**
195 * Init Widgets
196 *
197 * Include widgets files and register them
198 *
199 * @since 1.0.0
200 *
201 * @access public
202 */
203 public function init_widgets()
204 {
205 $step_id = $this->get_step_id();
206
207 if($step_id) {
208 $step = $this->widget_registration_manager($step_id);
209 if ( $step ) {
210 $step_type = get_post_meta($step_id, '_step_type', true);
211 if( 'landing' === $step_type || 'custom' === $step_type ) {
212 if ( version_compare(ELEMENTOR_VERSION, '3.5.0', '>=') ) {
213 \Elementor\Plugin::instance()->widgets_manager->register(new Step_Pointer());
214 \Elementor\Plugin::instance()->widgets_manager->register(new OptinForm());
215 } else {
216 // for older version of elementor
217 \Elementor\Plugin::instance()->widgets_manager->register_widget_type(new Step_Pointer());
218 \Elementor\Plugin::instance()->widgets_manager->register_widget_type(new OptinForm());
219 }
220 }
221
222 $funnel_id = get_post_meta($step_id,'_funnel_id',true);
223 $type = get_post_meta($funnel_id,'_wpfnl_funnel_type',true);
224
225
226 if (Wpfnl_functions::is_plugin_activated('woocommerce/woocommerce.php')) {
227 if($step_type == 'checkout') {
228 if ( version_compare(ELEMENTOR_VERSION, '3.5.0', '>=') ) {
229 \Elementor\Plugin::instance()->widgets_manager->register(new Checkout_Form());
230 } else {
231 \Elementor\Plugin::instance()->widgets_manager->register_widget_type(new Checkout_Form());
232 }
233 }
234
235 if($step_type == 'thankyou') {
236 if ( version_compare(ELEMENTOR_VERSION, '3.5.0', '>=') ) {
237 \Elementor\Plugin::instance()->widgets_manager->register(new Order_Details());
238 } else {
239 \Elementor\Plugin::instance()->widgets_manager->register_widget_type(new Order_Details());
240 }
241 }
242 }
243
244 }
245 }elseif(wp_get_theme()->get('Name') == 'Woodmart'){
246 if ( version_compare(ELEMENTOR_VERSION, '3.5.0', '>=') ) {
247 \Elementor\Plugin::instance()->widgets_manager->register(new Step_Pointer());
248 \Elementor\Plugin::instance()->widgets_manager->register(new OptinForm());
249 \Elementor\Plugin::instance()->widgets_manager->register(new Checkout_Form());
250 \Elementor\Plugin::instance()->widgets_manager->register(new Order_Details());
251 } else {
252 // for older version of elementor
253 \Elementor\Plugin::instance()->widgets_manager->register_widget_type(new Step_Pointer());
254 \Elementor\Plugin::instance()->widgets_manager->register_widget_type(new OptinForm());
255 \Elementor\Plugin::instance()->widgets_manager->register_widget_type(new Checkout_Form());
256 \Elementor\Plugin::instance()->widgets_manager->register_widget_type(new Order_Details());
257 }
258 }
259
260 }
261
262
263 /**
264 * Get step id
265 *
266 * @since 2.7.7
267 * @return Int
268 */
269 public function get_step_id(){
270
271 $step_id = '';
272 if( wp_doing_ajax() ) {
273 if( isset($_POST['step_id']) ) {
274 $step_id = $_POST['step_id'];
275 } elseif ( isset($_POST['editor_post_id'] ) ) {
276 $step_id = $_POST['editor_post_id'];
277 } else {
278 $step_id = '';
279 }
280 if( !$step_id && isset($_POST['initial_document_id'] ) ) {
281 $step_id = $_POST['initial_document_id'];
282 }
283 if( $step_id ){
284 $cookie_name = 'wpfunnels_current_step_id';
285 $cookie = isset( $_COOKIE[$cookie_name] ) ? json_decode( wp_unslash( $_COOKIE[$cookie_name] ), true ) : $step_id;
286 setcookie( $cookie_name, $cookie, time() + 3600 * 6, '/', COOKIE_DOMAIN );
287 }
288
289 }else {
290 $step_id = isset($_GET['post']) ? $_GET['post'] : get_the_ID();
291 }
292
293
294
295 if( !$step_id ){
296 $class_name = "WPFunnels\\Compatibility\\Plugin\\ElectroExtension";
297 if (class_exists(ucfirst($class_name))) {
298 if( $class_name::getInstance()->maybe_activate() ){
299 if( !empty($_COOKIE['wpfunnels_current_post_id']) ){
300 $step_id = $_COOKIE['wpfunnels_current_post_id'];
301 }
302 }
303 }
304 }
305
306 if( !$step_id ){
307 $cookie_name = 'wpfunnels_current_step_id';
308 $cookie = isset( $_COOKIE[$cookie_name] ) ? json_decode( wp_unslash( $_COOKIE[$cookie_name] ), true ) : '';
309 if( $cookie ){
310 $step_id = $cookie;
311 setcookie( $cookie_name, null, strtotime( '-1 days' ), '/', COOKIE_DOMAIN );
312 }
313 }
314
315 return $step_id;
316 }
317
318
319
320 /**
321 * Init Controls
322 *
323 * Include controls files and register them
324 *
325 * @since 1.0.0
326 *
327 * @access public
328 */
329 public function init_controls() {
330 \Elementor\Plugin::$instance->controls_manager->register_control(\WPFunnels\Widgets\Elementor\Controls\Product_Control::ProductSelector, new Product_Control());
331 \Elementor\Plugin::$instance->controls_manager->register_control('optin_styles', new Optin_Styles());
332 }
333
334
335
336 /**
337 * Widget Registration manager
338 *
339 * @since 1.0.0
340 *
341 * @access private
342 */
343 public function widget_registration_manager($page_id) {
344 return get_post_meta($page_id, '_step_type', true);
345 }
346
347
348 /**
349 * Get page templates
350 *
351 * @param $template
352 *
353 * @return mixed
354 *
355 * @since 2.0.5
356 */
357 public function get_page_template( $template ) {
358
359 if ( Wpfnl_functions::is_elementor_active() && is_singular() ) {
360 $is_preview_mode = \Elementor\Plugin::$instance->preview->is_preview_mode();
361 if($is_preview_mode) {
362 $document = \Elementor\Plugin::$instance->documents->get_doc_for_frontend( get_the_ID() );
363 if ( $document ) {
364 $template = $document->get_meta( '_wp_page_template' );
365 }
366 }
367 }
368 return $template;
369 }
370 }
371
372 Manager::instance();
373