PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 1.1.14
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v1.1.14
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.1.14, at modules/landing/classes/class-cartflows-landing-meta.php

237 lines 5.6 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, 'landing_meta_box' ), // Callback.
68 wcf()->utils->get_step_post_type(), // Post_type.
69 'normal', // Context.
70 'high' // Priority.
71 );
72 }
73 }
74
75 /**
76 * Landing Metabox Markup
77 *
78 * @param object $post Post object.
79 * @return void
80 */
81 function landing_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 $landing_data = array();
104 foreach ( $meta as $key => $value ) {
105
106 $landing_data[ $key ] = $meta[ $key ]['default'];
107 }
108
109 do_action( 'wcf_landing_settings_markup_before', $meta );
110 $this->page_header_tab( $landing_data, $post->ID );
111 do_action( 'wcf_landing_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-info',
134 ),
135 array(
136 'title' => __( 'Custom Script', 'cartflows' ),
137 'id' => 'wcf-landing-custom-script-header',
138 'class' => 'wcf-landing-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
139 'icon' => 'dashicons-format-aside',
140 ),
141 );
142
143 ?>
144 <div class="wcf-thankyou-table wcf-metabox-wrap widefat">
145 <div class="wcf-table-container">
146 <div class="wcf-column-left">
147 <div class="wcf-tab-wrapper">
148
149 <?php foreach ( $tabs as $key => $tab ) { ?>
150 <div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
151 <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
152 <span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
153 </div>
154 <?php } ?>
155 <input type="hidden" id="wcf_active_tab" name="wcf_active_tab" value="<?php echo esc_attr( $active_tab ); ?>" />
156
157 </div>
158 </div>
159 <div class="wcf-column-right">
160 <div class="wcf-thankyou-shortcodes wcf-tab-content active widefat">
161 <?php
162
163 $next_step_link = wcf()->utils->get_linking_url(
164 array( 'class' => 'wcf-next-step' )
165 );
166
167 echo wcf()->meta->get_shortcode_field(
168 array(
169 'label' => __( 'Next Step Link', 'cartflows' ),
170 'name' => 'wcf-next-step-link',
171 'content' => $next_step_link,
172 )
173 );
174
175 ?>
176 </div>
177
178 <?php $this->tab_custom_script( $options, $post_id ); ?>
179
180 <?php $this->right_column_footer( $options, $post_id ); ?>
181 </div>
182 </div>
183 </div>
184
185 <?php
186
187 }
188
189 /**
190 * Get metabox options
191 *
192 * @param int $post_id post ID.
193 * @return array
194 */
195 public static function get_meta_option( $post_id ) {
196
197 if ( null === self::$meta_option ) {
198 /**
199 * Set metabox options
200 *
201 * @see http://php.net/manual/en/filter.filters.sanitize.php
202 */
203 // self::$meta_option = array(); .
204 self::$meta_option = wcf()->options->get_landing_fields( $post_id );
205 }
206
207 return self::$meta_option;
208 }
209
210 /**
211 * Metabox Save
212 *
213 * @param number $post_id Post ID.
214 * @return void
215 */
216 function save_meta_box( $post_id ) {
217
218 // Checks save status.
219 $is_autosave = wp_is_post_autosave( $post_id );
220 $is_revision = wp_is_post_revision( $post_id );
221
222 $is_valid_nonce = ( isset( $_POST['nonce-landing-step-meta'] ) && wp_verify_nonce( $_POST['nonce-landing-step-meta'], 'save-nonce-landing-step-meta' ) ) ? true : false;
223
224 // Exits script depending on save status.
225 if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
226 return;
227 }
228
229 wcf()->options->save_landing_fields( $post_id );
230 }
231 }
232
233 /**
234 * Kicking this off by calling 'get_instance()' method
235 */
236 Cartflows_Landing_Meta::get_instance();
237