PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 1.1.2
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v1.1.2
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 / thankyou / classes / class-cartflows-thankyou-meta.php

class-cartflows-thankyou-meta.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 1.1.2, at modules/thankyou/classes/class-cartflows-thankyou-meta.php

406 lines 10.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Checkout post meta box
4 *
5 * @package CartFlows
6 */
7
8 /**
9 * Meta Boxes setup
10 */
11 class Cartflows_Thankyou_Meta extends Cartflows_Meta {
12
13 /**
14 * Instance
15 *
16 * @var $instance
17 */
18 private static $instance;
19
20 /**
21 * Meta Option
22 *
23 * @var $meta_option
24 */
25 private static $meta_option = null;
26
27 /**
28 * Initiator
29 */
30 public static function get_instance() {
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 /* Init Metabox */
44 add_action( 'load-post.php', array( $this, 'init_metabox' ) );
45 add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
46 }
47
48 /**
49 * Init Metabox
50 */
51 public function init_metabox() {
52
53 add_action( 'add_meta_boxes', array( $this, 'setup_meta_box' ) );
54 add_action( 'save_post', array( $this, 'save_meta_box' ) );
55 }
56
57 /**
58 * Setup Metabox
59 */
60 function setup_meta_box() {
61
62 if ( _is_wcf_thankyou_type() ) {
63 add_meta_box(
64 'wcf-thankyou-settings', // Id.
65 __( 'Thank You Page Settings', 'cartflows' ), // Title.
66 array( $this, 'markup_meta_box' ), // Callback.
67 wcf()->utils->get_step_post_type(), // Post_type.
68 'normal', // Context.
69 'high' // Priority.
70 );
71 }
72 }
73
74 /**
75 * Metabox Markup
76 *
77 * @param object $post Post object.
78 * @return void
79 */
80 function markup_meta_box( $post ) {
81
82 wp_nonce_field( 'save-nonce-thankyou-step-meta', 'nonce-thankyou-step-meta' );
83 $stored = get_post_meta( $post->ID );
84
85 $checkout_meta = self::get_meta_option( $post->ID );
86
87 // Set stored and override defaults.
88 foreach ( $stored as $key => $value ) {
89 if ( array_key_exists( $key, $checkout_meta ) ) {
90 self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? maybe_unserialize( $stored[ $key ][0] ) : '';
91 } else {
92 self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : '';
93 }
94 }
95
96 // Get defaults.
97 $meta = self::get_meta_option( $post->ID );
98
99 /**
100 * Get options
101 */
102 $thankyou_data = array();
103
104 foreach ( $meta as $key => $value ) {
105
106 $thankyou_data[ $key ] = $meta[ $key ]['default'];
107 }
108
109 do_action( 'wcf_thankyou_settings_markup_before', $meta );
110 $this->page_header_tab( $thankyou_data, $post->ID );
111 do_action( 'wcf_thankyou_settings_markup_after', $meta );
112 }
113
114 /**
115 * Page Header Tabs
116 *
117 * @param array $options Post meta.
118 * @param int $post_id Post ID.
119 */
120 function page_header_tab( $options, $post_id ) {
121
122 $active_tab = get_post_meta( $post_id, 'wcf-active-tab', true );
123
124 if ( empty( $active_tab ) ) {
125 $active_tab = 'wcf-thankyou-shortcodes';
126 }
127
128 $tabs = array(
129 array(
130 'title' => __( 'Shortcodes', 'cartflows' ),
131 'id' => 'wcf-thankyou-shortcodes',
132 'class' => 'wcf-thankyou-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
133 'icon' => 'dashicons-editor-code',
134 ),
135 array(
136 'title' => __( 'Thank You Design', 'cartflows' ),
137 'id' => 'wcf-thankyou-design',
138 'class' => 'wcf-thankyou-design' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
139 'icon' => 'dashicons-admin-customizer',
140 ),
141 array(
142 'title' => __( 'Thank You Fields', 'cartflows' ),
143 'id' => 'wcf-thankyou-fields',
144 'class' => 'wcf-thankyou-fields' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
145 'icon' => 'dashicons-welcome-widgets-menus',
146 ),
147 );
148
149 ?>
150 <div class="wcf-thankyou-table wcf-metabox-wrap widefat">
151 <div class="wcf-table-container">
152 <div class="wcf-column-left">
153 <div class="wcf-tab-wrapper">
154
155 <?php foreach ( $tabs as $key => $tab ) { ?>
156 <div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
157 <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
158 <span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
159 </div>
160 <?php } ?>
161 <input type="hidden" id="wcf-active-tab" name="wcf-active-tab" value="<?php echo esc_attr( $active_tab ); ?>" />
162
163 </div>
164 </div>
165 <div class="wcf-column-right">
166 <div class="wcf-thankyou-shortcodes wcf-tab-content active widefat">
167 <?php
168 echo wcf()->meta->get_shortcode_field(
169 array(
170 'label' => __( 'Order Details', 'cartflows' ),
171 'name' => 'wcf-order-details',
172 'content' => esc_html( '[cartflows_order_details]' ),
173 )
174 );
175 ?>
176 </div>
177 <div class="wcf-thankyou-design wcf-tab-content widefat">
178 <?php
179
180 echo wcf()->meta->get_section(
181 array(
182 'label' => __( 'Text', 'cartflows' ),
183 )
184 );
185
186 echo wcf()->meta->get_color_picker_field(
187 array(
188 'label' => __( 'Color', 'cartflows' ),
189 'name' => 'wcf-tq-text-color',
190 'value' => $options['wcf-tq-text-color'],
191 )
192 );
193
194 echo wcf()->meta->get_font_family_field(
195 array(
196 'for' => 'wcf-tq-font-family',
197 'label' => __( 'Font Family', 'cartflows' ),
198 'name' => 'wcf-tq-font-family',
199 'value' => $options['wcf-tq-font-family'],
200 )
201 );
202
203 echo wcf()->meta->get_section(
204 array(
205 'label' => __( 'Heading', 'cartflows' ),
206 )
207 );
208
209 echo wcf()->meta->get_color_picker_field(
210 array(
211 'label' => __( 'Color', 'cartflows' ),
212 'name' => 'wcf-tq-heading-color',
213 'value' => $options['wcf-tq-heading-color'],
214 )
215 );
216
217 echo wcf()->meta->get_font_family_field(
218 array(
219 'for' => 'wcf-tq-heading-font-family',
220 'label' => __( 'Font Family', 'cartflows' ),
221 'name' => 'wcf-tq-heading-font-family',
222 'value' => $options['wcf-tq-heading-font-family'],
223 )
224 );
225
226 echo wcf()->meta->get_font_weight_field(
227 array(
228 'for' => 'wcf-tq-heading-font-family',
229 'label' => __( 'Font Weight', 'cartflows' ),
230 'name' => 'wcf-tq-heading-font-wt',
231 'value' => $options['wcf-tq-heading-font-wt'],
232 )
233 );
234
235 echo wcf()->meta->get_checkbox_field(
236 array(
237 'label' => __( 'Advanced Options', 'cartflows' ),
238 'name' => 'wcf-tq-advance-options-fields',
239 'value' => $options['wcf-tq-advance-options-fields'],
240 'after' => 'Enable',
241 )
242 );
243
244 echo wcf()->meta->get_number_field(
245 array(
246 'for' => 'wcf-heading',
247 'label' => __( 'Container Width (In px)', 'cartflows' ),
248 'name' => 'wcf-tq-container-width',
249 'value' => $options['wcf-tq-container-width'],
250 )
251 );
252
253 echo wcf()->meta->get_color_picker_field(
254 array(
255 'label' => __( 'Section Background Color', 'cartflows' ),
256 'name' => 'wcf-tq-section-bg-color',
257 'value' => $options['wcf-tq-section-bg-color'],
258 )
259 );
260
261 ?>
262 </div>
263 <div class="wcf-thankyou-fields wcf-tab-content widefat">
264 <?php
265 echo wcf()->meta->get_checkbox_field(
266 array(
267 'name' => 'wcf-show-overview-section',
268 'value' => $options['wcf-show-overview-section'],
269 'after' => __( 'Enable Order Overview ', 'cartflows' ),
270 )
271 );
272
273 echo wcf()->meta->get_checkbox_field(
274 array(
275 'name' => 'wcf-show-details-section',
276 'value' => $options['wcf-show-details-section'],
277 'after' => __( 'Enable Order Details ', 'cartflows' ),
278 )
279 );
280
281 echo wcf()->meta->get_checkbox_field(
282 array(
283 'name' => 'wcf-show-billing-section',
284 'value' => $options['wcf-show-billing-section'],
285 'after' => __( 'Enable Billing Details ', 'cartflows' ),
286 )
287 );
288
289 echo wcf()->meta->get_checkbox_field(
290 array(
291 'name' => 'wcf-show-shipping-section',
292 'value' => $options['wcf-show-shipping-section'],
293 'after' => __( 'Enable Shipping Details ', 'cartflows' ),
294 )
295 );
296
297 echo wcf()->meta->get_hidden_field(
298 array(
299 'name' => 'wcf-field-google-font-url',
300 'value' => $options['wcf-field-google-font-url'],
301 )
302 );
303 ?>
304 </div>
305 <?php $this->right_column_footer( $options, $post_id ); ?>
306 </div>
307 </div>
308 </div>
309
310 <?php
311
312 }
313
314 /**
315 * Get metabox options
316 *
317 * @param int $post_id post ID.
318 * @return array
319 */
320 public static function get_meta_option( $post_id ) {
321
322 if ( null === self::$meta_option ) {
323
324 /**
325 * Set metabox options
326 *
327 * @see http://php.net/manual/en/filter.filters.sanitize.php
328 */
329 self::$meta_option = wcf()->options->get_thankyou_fields( $post_id );
330 }
331
332 return self::$meta_option;
333
334 }
335
336 /**
337 * Metabox Save
338 *
339 * @param number $post_id Post ID.
340 * @return void
341 */
342 function save_meta_box( $post_id ) {
343
344 // Checks save status.
345 $is_autosave = wp_is_post_autosave( $post_id );
346 $is_revision = wp_is_post_revision( $post_id );
347
348 $is_valid_nonce = ( isset( $_POST['nonce-thankyou-step-meta'] ) && wp_verify_nonce( $_POST['nonce-thankyou-step-meta'], 'save-nonce-thankyou-step-meta' ) ) ? true : false;
349
350 // Exits script depending on save status.
351 if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
352 return;
353 }
354
355 /**
356 * Get meta options
357 */
358 $post_meta = self::get_meta_option( $post_id );
359
360 foreach ( $post_meta as $key => $data ) {
361
362 $meta_value = false;
363
364 if ( in_array( $key, array( ' ' ) ) ) {
365
366 if ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) {
367 $meta_value = array_map( 'sanitize_text_field', $_POST[ $key ] );
368 }
369 } else {
370 // Sanitize values.
371 $sanitize_filter = ( isset( $data['sanitize'] ) ) ? $data['sanitize'] : 'FILTER_DEFAULT';
372
373 switch ( $sanitize_filter ) {
374
375 case 'FILTER_SANITIZE_STRING':
376 $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_STRING );
377 break;
378
379 case 'FILTER_SANITIZE_URL':
380 $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_URL );
381 break;
382
383 case 'FILTER_SANITIZE_NUMBER_INT':
384 $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_NUMBER_INT );
385 break;
386
387 default:
388 $meta_value = filter_input( INPUT_POST, $key, FILTER_DEFAULT );
389 break;
390 }
391 }
392
393 if ( $meta_value ) {
394 update_post_meta( $post_id, $key, $meta_value );
395 } else {
396 delete_post_meta( $post_id, $key );
397 }
398 }
399 }
400 }
401
402 /**
403 * Kicking this off by calling 'get_instance()' method
404 */
405 Cartflows_Thankyou_Meta::get_instance();
406