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

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

267 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Landing post meta box
4 *
5 * @package CartFlows
6 */
7
8 /**
9 * Meta Boxes setup
10 */
11 class Cartflows_Landing_Meta extends Cartflows_Meta {
12
13
14 /**
15 * Instance
16 *
17 * @var $instance
18 */
19 private static $instance;
20
21 /**
22 * Meta Option
23 *
24 * @var $meta_option
25 */
26 private static $meta_option = null;
27
28 /**
29 * Initiator
30 */
31 public static function get_instance() {
32 if ( ! isset( self::$instance ) ) {
33 self::$instance = new self;
34 }
35
36 return self::$instance;
37 }
38
39 /**
40 * Constructor
41 */
42 public function __construct() {
43
44 /* Init Metabox */
45 add_action( 'load-post.php', array( $this, 'init_metabox' ) );
46 add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
47 }
48
49 /**
50 * Init Metabox
51 */
52 public function init_metabox() {
53
54 add_action( 'add_meta_boxes', array( $this, 'setup_meta_box' ) );
55 add_action( 'save_post', array( $this, 'save_meta_box' ) );
56 }
57
58 /**
59 * Setup Metabox
60 */
61 function setup_meta_box() {
62
63 if ( _is_wcf_landing_type() ) {
64 add_meta_box(
65 'wcf-ladning-settings', // Id.
66 __( 'Landing Page Settings', 'cartflows' ), // Title.
67 array( $this, 'markup_meta_box' ), // Callback.
68 wcf()->utils->get_step_post_type(), // Post_type.
69 'normal', // Context.
70 'high' // Priority.
71 );
72 }
73 }
74
75 /**
76 * Metabox Markup
77 *
78 * @param object $post Post object.
79 * @return void
80 */
81 function markup_meta_box( $post ) {
82
83 wp_nonce_field( 'save-nonce-landing-step-meta', 'nonce-landing-step-meta' );
84 $stored = get_post_meta( $post->ID );
85
86 $checkout_meta = self::get_meta_option( $post->ID );
87
88 // Set stored and override defaults.
89 foreach ( $stored as $key => $value ) {
90 if ( array_key_exists( $key, $checkout_meta ) ) {
91 self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? maybe_unserialize( $stored[ $key ][0] ) : '';
92 } else {
93 self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : '';
94 }
95 }
96
97 // Get defaults.
98 $meta = self::get_meta_option( $post->ID );
99
100 /**
101 * Get options
102 */
103 $checkout_data = array();
104
105 do_action( 'wcf_thankyou_settings_markup_before', $meta );
106 $this->page_header_tab( $checkout_data, $post->ID );
107 do_action( 'wcf_thankyou_settings_markup_after', $meta );
108 }
109
110 /**
111 * Page Header Tabs
112 *
113 * @param array $options Post meta.
114 * @param int $post_id Post ID.
115 */
116 function page_header_tab( $options, $post_id ) {
117
118 $active_tab = get_post_meta( $post_id, 'wcf_active_tab', true );
119
120 if ( empty( $active_tab ) ) {
121 $active_tab = 'wcf-thankyou-shortcodes';
122 }
123
124 $tabs = array(
125 array(
126 'title' => __( 'Shortcodes', 'cartflows' ),
127 'id' => 'wcf-thankyou-shortcodes',
128 'class' => 'wcf-thankyou-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
129 'icon' => 'dashicons-info',
130 ),
131 );
132
133 ?>
134 <div class="wcf-thankyou-table wcf-metabox-wrap widefat">
135 <div class="wcf-table-container">
136 <div class="wcf-column-left">
137 <div class="wcf-tab-wrapper">
138
139 <?php foreach ( $tabs as $key => $tab ) { ?>
140 <div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
141 <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
142 <span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
143 </div>
144 <?php } ?>
145 <input type="hidden" id="wcf_active_tab" name="wcf_active_tab" value="<?php echo esc_attr( $active_tab ); ?>" />
146
147 </div>
148 </div>
149 <div class="wcf-column-right">
150 <div class="wcf-thankyou-shortcodes wcf-tab-content active widefat">
151 <?php
152
153 $next_step_link = wcf()->utils->get_linking_url(
154 array( 'class' => 'wcf-next-step' )
155 );
156
157 echo wcf()->meta->get_shortcode_field(
158 array(
159 'label' => __( 'Next Step Link', 'cartflows' ),
160 'name' => 'wcf-next-step-link',
161 'content' => $next_step_link,
162 )
163 );
164
165 ?>
166 </div>
167 <?php $this->right_column_footer( $options, $post_id ); ?>
168 </div>
169 </div>
170 </div>
171
172 <?php
173
174 }
175
176 /**
177 * Get metabox options
178 *
179 * @param int $post_id post ID.
180 * @return array
181 */
182 public static function get_meta_option( $post_id ) {
183
184 if ( null === self::$meta_option ) {
185
186 /**
187 * Set metabox options
188 *
189 * @see http://php.net/manual/en/filter.filters.sanitize.php
190 */
191 self::$meta_option = array();
192 }
193
194 return self::$meta_option;
195 }
196
197 /**
198 * Metabox Save
199 *
200 * @param number $post_id Post ID.
201 * @return void
202 */
203 function save_meta_box( $post_id ) {
204
205 // Checks save status.
206 $is_autosave = wp_is_post_autosave( $post_id );
207 $is_revision = wp_is_post_revision( $post_id );
208
209 $is_valid_nonce = ( isset( $_POST['nonce-landing-step-meta'] ) && wp_verify_nonce( $_POST['nonce-landing-step-meta'], 'save-nonce-landing-step-meta' ) ) ? true : false;
210
211 // Exits script depending on save status.
212 if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
213 return;
214 }
215
216 /**
217 * Get meta options
218 */
219 $post_meta = self::get_meta_option( $post_id );
220
221 foreach ( $post_meta as $key => $data ) {
222
223 $meta_value = false;
224
225 if ( in_array( $key, array( ' ' ) ) ) {
226
227 if ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) {
228 $meta_value = array_map( 'sanitize_text_field', $_POST[ $key ] );
229 }
230 } else {
231 // Sanitize values.
232 $sanitize_filter = ( isset( $data['sanitize'] ) ) ? $data['sanitize'] : 'FILTER_DEFAULT';
233
234 switch ( $sanitize_filter ) {
235
236 case 'FILTER_SANITIZE_STRING':
237 $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_STRING );
238 break;
239
240 case 'FILTER_SANITIZE_URL':
241 $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_URL );
242 break;
243
244 case 'FILTER_SANITIZE_NUMBER_INT':
245 $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_NUMBER_INT );
246 break;
247
248 default:
249 $meta_value = filter_input( INPUT_POST, $key, FILTER_DEFAULT );
250 break;
251 }
252 }
253
254 if ( $meta_value ) {
255 update_post_meta( $post_id, $key, $meta_value );
256 } else {
257 delete_post_meta( $post_id, $key );
258 }
259 }
260 }
261 }
262
263 /**
264 * Kicking this off by calling 'get_instance()' method
265 */
266 Cartflows_Landing_Meta::get_instance();
267