PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.3.0
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.3.0
3.3.0 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 trunk 1.0.4 1.1.0 1.1.0.1 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 All 162 releases
cartflows / modules / elementor / classes / class-cartflows-elementor-editor.php

class-cartflows-elementor-editor.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 3.3.0, at modules/elementor/classes/class-cartflows-elementor-editor.php

198 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Elementor Editor Compatibility.
4 *
5 * @package CartFlows
6 */
7
8 // Exit if accessed directly.
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12 /**
13 * Checkout Markup
14 *
15 * @since 1.0.0
16 */
17 class Cartflows_Elementor_Editor {
18
19 /**
20 * Member Variable
21 *
22 * @var object instance
23 */
24 private static $instance;
25
26 /**
27 * Initiator
28 */
29 public static function get_instance() {
30
31 if ( ! isset( self::$instance ) ) {
32 self::$instance = new self();
33 }
34
35 return self::$instance;
36 }
37
38 /**
39 * Constructor
40 */
41 public function __construct() {
42
43 $this->elementor_editor_compatibility();
44
45 add_action( 'elementor/editor/after_save', array( $this, 'update_required_step_meta_data' ), 10, 2 );
46 }
47
48 /**
49 * Before checkout shortcode actions.
50 *
51 * @param int $step_id checkout id.
52 * @param array $editor_data editor data.
53 */
54 public function update_required_step_meta_data( $step_id, $editor_data ) {
55
56 if ( wcf()->utils->is_step_post_type( get_post_type( $step_id ) ) ) {
57
58 $step_type = get_post_meta( $step_id, 'wcf-step-type', true );
59 $widget_data = '';
60
61 switch ( $step_type ) {
62
63 case 'checkout':
64 $widget_data = $this->elementor_find_element_recursive( $editor_data, 'checkout-form' );
65 $meta_keys = array(
66 'layout' => 'wcf-checkout-layout',
67 );
68 break;
69
70 case 'optin':
71 break;
72
73 default:
74 }
75
76 if ( is_array( $widget_data ) && ! empty( $widget_data ) && isset( $widget_data['settings'] ) ) {
77
78 foreach ( $meta_keys as $key => $meta_key ) {
79
80 if ( isset( $widget_data['settings'][ $key ] ) ) {
81 update_post_meta( $step_id, $meta_key, $widget_data['settings'][ $key ] );
82 }
83 }
84 }
85 }
86 }
87
88 /**
89 * Get the elementor widget data.
90 *
91 * @param array $elements elements data.
92 * @param string $slug widget name.
93 */
94 public function elementor_find_element_recursive( $elements, $slug = 'checkout-form' ) {
95 foreach ( $elements as $element ) {
96 if ( 'widget' === $element['elType'] && $slug === $element['widgetType'] ) {
97 return $element;
98 }
99 if ( ! empty( $element['elements'] ) ) {
100 $element = $this->elementor_find_element_recursive( $element['elements'] );
101 if ( $element ) {
102 return $element;
103 }
104 }
105 }
106 return false;
107 }
108
109 /**
110 * Elementor editor compatibility.
111 */
112 public function elementor_editor_compatibility() {
113 // This file included on elementor actions.
114 //phpcs:disable WordPress.Security.NonceVerification.Recommended
115 if ( ! empty( $_REQUEST['action'] ) && is_admin() ) {
116
117 $current_post_id = false;
118 $elementor_ajax = false;
119
120 if ( 'elementor' === $_REQUEST['action'] && isset( $_GET['post'] ) && ! empty( $_GET['post'] ) ) {
121 $current_post_id = intval( $_GET['post'] );
122 }
123
124 if ( wp_doing_ajax() && 'elementor_ajax' === $_REQUEST['action'] && isset( $_REQUEST['editor_post_id'] ) && ! empty( $_REQUEST['editor_post_id'] ) ) {
125 $current_post_id = intval( $_REQUEST['editor_post_id'] );
126 $elementor_ajax = true;
127 }
128
129 if ( $current_post_id ) {
130
131 $current_post_type = get_post_type( $current_post_id );
132
133 if ( wcf()->utils->is_step_post_type( $current_post_type ) ) {
134
135 $cf_frontend = Cartflows_Frontend::get_instance();
136
137 /* Load woo templates from plugin */
138 add_filter( 'woocommerce_locate_template', array( $cf_frontend, 'override_woo_template' ), 20, 3 );
139
140 do_action( 'cartflows_elementor_editor_compatibility', $current_post_id, $elementor_ajax );
141 }
142 }
143
144 /* Compatibility without condition, just to add actions */
145 if ( 'elementor' === $_REQUEST['action'] || 'elementor_ajax' === $_REQUEST['action'] ) {
146
147 add_action( 'cartflows_elementor_before_checkout_shortcode', array( $this, 'before_checkout_shortcode_actions' ) );
148 add_action( 'cartflows_elementor_before_optin_shortcode', array( $this, 'before_optin_shortcode_actions' ) );
149
150 /*
151 * Thank you filters.
152 *
153 * This makes the order-details shortcode fall back to the store's most recent
154 * real order, so it is kept to users who can actually edit steps rather than to
155 * any admin-side request that merely carries an Elementor action.
156 *
157 * The post-type half of the gate is already enforced upstream: this class is
158 * only loaded by Cartflows_El_Widgets_Loader::include_widgets_files(), which
159 * runs from register_widgets() after confirming the global post is a
160 * cartflows_step. The check here is the capability half.
161 */
162 if ( current_user_can( 'cartflows_manage_flows_steps' ) ) {
163 add_filter( 'cartflows_show_demo_order_details', '__return_true' );
164 }
165 }
166 //phpcs:enable WordPress.Security.NonceVerification.Recommended
167 }
168 }
169
170 /**
171 * Before checkout shortcode actions.
172 *
173 * @param int $checkout_id checkout id.
174 */
175 public function before_checkout_shortcode_actions( $checkout_id ) {
176
177 // Added to modify the fields labels and placeholders to display it in the preview mode.
178 Cartflows_Checkout_Fields::get_instance()->checkout_field_actions();
179
180 do_action( 'cartflows_checkout_before_shortcode', $checkout_id );
181 }
182
183 /**
184 * Before optin shortcode actions.
185 *
186 * @param int $checkout_id checkout id.
187 */
188 public function before_optin_shortcode_actions( $checkout_id ) {
189
190 do_action( 'cartflows_optin_before_shortcode', $checkout_id );
191 }
192 }
193
194 /**
195 * Kicking this off by calling 'get_instance()' method
196 */
197 Cartflows_Elementor_Editor::get_instance();
198