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
← All changes | classes/class-cartflows-flow-frontend.php +188 -27 1.1.12 → 3.3.0 View file →
@@ -4,8 +4,12 @@
4 4 *
5 5 * @package CartFlows
6 6 */
7 7
8 +// Exit if accessed directly.
9 +if ( ! defined( 'ABSPATH' ) ) {
10 + exit;
11 +}
8 12 /**
9 13 * Flow Markup
10 14 *
11 15 * @since 1.0.0
@@ -24,9 +28,9 @@
24 28 * Initiator
25 29 */
26 30 public static function get_instance() {
27 31 if ( ! isset( self::$instance ) ) {
28 - self::$instance = new self;
32 + self::$instance = new self();
29 33 }
30 34 return self::$instance;
31 35 }
32 36
@@ -36,25 +40,84 @@
36 40 public function __construct() {
37 41
38 42 /* Analytics */
39 43 add_action( 'cartflows_wp_footer', array( $this, 'footer_markup' ) );
44 + add_action( 'admin_bar_menu', array( $this, 'add_edit_flow_menu' ), 999 );
45 + add_action( 'admin_bar_menu', array( $this, 'update_edit_step_menu_link' ), 999 );
46 + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_gcp_color_vars' ), 23 );
40 47 }
41 48
49 +
50 +
42 51 /**
52 + * Add a new admin bar menu to navigate to edit the flow.
53 + *
54 + * @param object $admin_bar The object of admin bar.
55 + * @return void
56 + */
57 + public function add_edit_flow_menu( $admin_bar ) {
58 +
59 + if ( wcf()->utils->is_step_post_type() ) {
60 + $flow_id = wcf()->utils->get_flow_id();
61 +
62 + if ( ! empty( $flow_id ) ) {
63 +
64 + $path = Cartflows_Helper::get_global_setting( '_cartflows_store_checkout' ) === $flow_id ? 'store-checkout' : 'flows';
65 +
66 + $admin_bar->add_node(
67 + array(
68 + 'id' => 'edit-flow',
69 + 'title' => '<span class="ab-icon dashicons dashicons-edit"></span>' . esc_html__( 'Edit Funnel', 'cartflows' ),
70 + 'href' => admin_url( 'admin.php?page=cartflows&path=' . $path . '&action=wcf-edit-flow&flow_id=' . $flow_id ),
71 + 'meta' => array(
72 + 'class' => 'wcf-admin_bar-edit_flow--menu',
73 + ),
74 + )
75 + );
76 + }
77 + }
78 + }
79 +
80 + /**
43 81 * Footer markup
44 82 */
45 - function footer_markup() {
83 + public function footer_markup() {
46 84
85 + // Keep onboarding template previews aspirational — no admin notices inside the iframe.
86 + if ( isset( $_GET['wcf-load-onboarding-iframe'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
87 + return;
88 + }
89 +
47 90 if ( wcf()->utils->is_step_post_type() ) {
48 - // @codingStandardsIgnoreStart
91 + $flow_id = wcf()->utils->get_flow_id();
92 +
93 + $default_strings = array(
94 + 'message' => __( 'Test mode is currently enabled to help you preview your funnel. You can turn it off anytime from the funnel\'s settings in the admin dashboard.', 'cartflows' ),
95 + 'link_text' => __( 'Click here to disable it.', 'cartflows' ),
96 + );
97 +
98 + $test_mode_strings = array_merge(
99 + $default_strings,
100 + // Make sure that if empty strings are sent, then assign the default strings.
101 + array_filter(
102 + apply_filters( 'cartflows_test_mode_strings', $default_strings )
103 + )
104 + );
105 +
49 106 ?>
50 - <?php if( $this->is_flow_testmode() ) { ?>
51 - <div class="wcf-preview-mode">
52 - <span><?php _e( 'Test mode is active — which displays random products for previewing. It can be deactivated from the flow settings in the admin dashboard.', 'cartflows' ); ?></span>
53 - </div>
107 + <?php if ( $this->is_flow_testmode( $flow_id ) ) { ?>
108 + <div class="wcf-preview-mode">
109 + <span><?php echo esc_html( $test_mode_strings['message'] ); ?></span>
110 + <?php if ( current_user_can( 'cartflows_manage_flows_steps' ) ) { ?>
111 + <?php
112 + $path = Cartflows_Helper::get_global_setting( '_cartflows_store_checkout' ) === $flow_id ? 'store-checkout' : 'flows';
113 + $flow_edit_link = admin_url( 'admin.php?page=cartflows&path=' . $path . '&action=wcf-edit-flow&flow_id=' . $flow_id );
114 + ?>
115 + <a href="<?php echo esc_url( $flow_edit_link ); ?>"><?php echo esc_html( $test_mode_strings['link_text'] ); ?></a>
116 + <?php } ?>
117 + </div>
54 118 <?php } ?>
55 119 <?php
56 - // @codingStandardsIgnoreEnd
57 120 }
58 121 }
59 122
60 123 /**
@@ -64,9 +127,9 @@
64 127 * @param int $flow_id flow ID.
65 128 *
66 129 * @return boolean
67 130 */
68 - function is_flow_testmode( $flow_id = '' ) {
131 + public function is_flow_testmode( $flow_id = '' ) {
69 132
70 133 if ( ! $flow_id ) {
71 134 $flow_id = wcf()->utils->get_flow_id();
72 135 }
@@ -72,13 +135,13 @@
72 135 }
73 136
74 137 $test_mode = wcf()->options->get_flow_meta_value( $flow_id, 'wcf-testing' );
75 138
76 - if ( 'no' === $test_mode ) {
77 - return false;
139 + if ( 'yes' === $test_mode ) {
140 + return true;
78 141 }
79 142
80 - return true;
143 + return false;
81 144 }
82 145
83 146 /**
84 147 * Get steps data.
@@ -87,9 +150,9 @@
87 150 * @param int $flow_id flow ID.
88 151 *
89 152 * @return array
90 153 */
91 - function get_steps( $flow_id ) {
154 + public function get_steps( $flow_id ) {
92 155
93 156 $steps = get_post_meta( $flow_id, 'wcf-steps', true );
94 157
95 158 if ( ! is_array( $steps ) ) {
@@ -107,19 +170,23 @@
107 170 * @param array $order order data.
108 171 *
109 172 * @return bool
110 173 */
111 - function is_thankyou_page_exists( $order ) {
174 + public function is_thankyou_page_exists( $order ) {
112 175
113 176 $thankyou_step_exist = false;
114 177
115 - $flow_id = wcf()->utils->get_flow_id_from_order( $order->get_id() );
178 + $flow_id = wcf()->utils->get_flow_id_from_order( $order );
116 179
117 180 if ( $flow_id ) {
118 181
119 - $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
120 - $step_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
182 + $step_id = wcf()->utils->get_checkout_id_from_order( $order );
121 183
184 + // Get control step and flow steps.
185 + $wcf_step_obj = wcf_get_step( $step_id );
186 + $flow_steps = $wcf_step_obj->get_flow_steps();
187 + $control_step = $wcf_step_obj->get_control_step();
188 +
122 189 if ( is_array( $flow_steps ) ) {
123 190
124 191 $current_step_found = false;
125 192
@@ -131,14 +198,12 @@
131 198
132 199 $thankyou_step_exist = true;
133 200 break;
134 201 }
135 - } else {
202 + } elseif ( intval( $data['id'] ) === $control_step ) {
136 203
137 - if ( intval( $data['id'] ) === $step_id ) {
138 204
139 205 $current_step_found = true;
140 - }
141 206 }
142 207 }
143 208 }
144 209 }
@@ -153,19 +218,23 @@
153 218 * @param array $order order data.
154 219 *
155 220 * @return bool
156 221 */
157 - function get_thankyou_page_id( $order ) {
222 + public function get_thankyou_page_id( $order ) {
158 223
159 224 $thankyou_step_id = false;
160 225
161 - $flow_id = wcf()->utils->get_flow_id_from_order( $order->get_id() );
226 + $flow_id = wcf()->utils->get_flow_id_from_order( $order );
162 227
163 228 if ( $flow_id ) {
164 229
165 - $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
166 - $step_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
230 + $step_id = wcf()->utils->get_checkout_id_from_order( $order );
167 231
232 + // Get control step and flow steps.
233 + $wcf_step_obj = wcf_get_step( $step_id );
234 + $flow_steps = $wcf_step_obj->get_flow_steps();
235 + $control_step = $wcf_step_obj->get_control_step();
236 +
168 237 if ( is_array( $flow_steps ) ) {
169 238
170 239 $current_step_found = false;
171 240
@@ -177,14 +246,12 @@
177 246
178 247 $thankyou_step_id = intval( $data['id'] );
179 248 break;
180 249 }
181 - } else {
250 + } elseif ( intval( $data['id'] ) === $control_step ) {
182 251
183 - if ( intval( $data['id'] ) === $step_id ) {
184 252
185 253 $current_step_found = true;
186 - }
187 254 }
188 255 }
189 256 }
190 257 }
@@ -189,8 +256,102 @@
189 256 }
190 257 }
191 258
192 259 return $thankyou_step_id;
260 + }
261 +
262 + /**
263 + * Update the CartFlows steps link as per the latest UI.
264 + *
265 + * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar object.
266 + * @since 2.0.0
267 + */
268 + public function update_edit_step_menu_link( $wp_admin_bar ) {
269 +
270 + if ( wcf()->utils->is_step_post_type() ) {
271 +
272 + global $post;
273 +
274 + if ( ! empty( $post ) ) {
275 +
276 + $edit_node = $wp_admin_bar->get_node( 'edit' );
277 +
278 + if ( $edit_node ) {
279 + $post_id = $post->ID;
280 + $flow_id = wcf()->utils->get_flow_id_from_step_id( $post_id );
281 +
282 + // Show the edit node only if the page builder option is set to other and gutenberg, else remove/hide the node.
283 + if ( in_array( Cartflows_Helper::get_common_setting( 'default_page_builder' ), array( 'other', 'gutenberg' ) ) || Cartflows_Helper::is_instant_layout_enabled( intval( $flow_id ) ) ) {
284 + $edit_node->title = esc_html__( 'Edit Design', 'cartflows' );
285 + $edit_node->href = $this->get_prepared_edit_step_url( $post->ID );
286 + $wp_admin_bar->add_node( $edit_node );
287 + } else {
288 + $wp_admin_bar->remove_node( 'edit' );
289 + }
290 + }
291 + }
292 + }
293 + }
294 +
295 + /**
296 + * Enqueue the Global Color Pallet CSS vars to the page to use in the page builder settings.
297 + *
298 + * Note: Currently the GCP support is added for Elementor and Block Builder.
299 + *
300 + * @param string $css_dependency the CSS file handle as a dependency to add the inline css.
301 + * @since 2.0.0
302 + * @return void
303 + */
304 + public function enqueue_gcp_color_vars( $css_dependency = '' ) {
305 +
306 + if ( wcf()->utils->is_step_post_type() ) {
307 +
308 + $flow_id = wcf()->utils->get_flow_id();
309 +
310 + // Return if no flow ID is found.
311 + if ( empty( $flow_id ) ) {
312 + return;
313 + }
314 +
315 + if ( ! Cartflows_Helper::is_gcp_styling_enabled( (int) $flow_id ) ) {
316 + return;
317 + }
318 +
319 + $gcp_vars = Cartflows_Helper::generate_gcp_css_style( (int) $flow_id );
320 + $css_dependency = ! empty( $css_dependency ) ? $css_dependency : 'wcf-frontend-global';
321 +
322 + // Don't print the inline CSS style if no style is generated.
323 + if ( ! empty( $gcp_vars ) ) {
324 + $output = ':root { ' . $gcp_vars . ' }';
325 + wp_add_inline_style( $css_dependency, $output );
326 + }
327 + }
328 + }
329 +
330 + /**
331 + * Generates the edit URL for a step based on the page builder and Instant Checkout features.
332 + *
333 + * @since 2.1.0
334 + * @param int $step_id The ID of the step to generate the edit URL for.
335 + * @return string $edit_url The edit URL for the specified step.
336 + */
337 + public function get_prepared_edit_step_url( $step_id ) {
338 + // Default Edit Step URL.
339 + $edit_url = Cartflows_Helper::get_page_builder_edit_link( $step_id );
340 +
341 + // Get the current flow ID from the step.
342 + $flow_id = (int) wcf()->utils->get_flow_id_from_step_id( $step_id );
343 +
344 + // Update the edit URL if instant Checkout is enabled.
345 + if ( Cartflows_Helper::is_instant_layout_enabled( (int) $flow_id ) ) {
346 + $store_checkout = Cartflows_Helper::get_global_setting( '_cartflows_store_checkout' );
347 + $store_checkout_path = intval( $store_checkout ) === intval( $flow_id ) ? 'store-checkout' : 'flows';
348 +
349 + $edit_url = admin_url( 'admin.php?page=' . CARTFLOWS_SLUG . '&path=' . $store_checkout_path . '&action=wcf-edit-flow&flow_id=' . $flow_id . '&step_id=' . $step_id . '&tab=design' );
350 + }
351 +
352 + // Return the updated edit URL.
353 + return $edit_url;
193 354 }
194 355 }
195 356
196 357 /**