| 1 |
<?php |
| 2 |
/** |
| 3 |
* Landing post meta box |
| 4 |
* |
| 5 |
* @package CartFlows |
| 6 |
*/ |
| 7 |
|
| 8 |
// Exit if accessed directly. |
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
/** |
| 13 |
* Meta Boxes setup |
| 14 |
*/ |
| 15 |
class Cartflows_Landing_Meta_Data extends Cartflows_Step_Meta_Base { |
| 16 |
|
| 17 |
|
| 18 |
/** |
| 19 |
* Instance |
| 20 |
* |
| 21 |
* @var $instance |
| 22 |
*/ |
| 23 |
private static $instance; |
| 24 |
|
| 25 |
|
| 26 |
/** |
| 27 |
* Initiator |
| 28 |
*/ |
| 29 |
public static function get_instance() { |
| 30 |
if ( ! isset( self::$instance ) ) { |
| 31 |
self::$instance = new self(); |
| 32 |
} |
| 33 |
|
| 34 |
return self::$instance; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Constructor |
| 39 |
*/ |
| 40 |
public function __construct() { |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Page Header Tabs. |
| 45 |
* |
| 46 |
* @param int $step_id Post ID. |
| 47 |
* @param array $options Post meta. |
| 48 |
*/ |
| 49 |
public function get_settings( $step_id, $options = array() ) { |
| 50 |
|
| 51 |
$this->step_id = $step_id; |
| 52 |
$this->options = $options; |
| 53 |
|
| 54 |
$tabs = array( |
| 55 |
'settings' => array( |
| 56 |
'title' => __( 'Settings', 'cartflows' ), |
| 57 |
'id' => 'settings', |
| 58 |
'class' => '', |
| 59 |
'icon' => 'dashicons-info', |
| 60 |
'priority' => 20, |
| 61 |
), |
| 62 |
|
| 63 |
); |
| 64 |
|
| 65 |
$settings = $this->get_settings_fields( $step_id ); |
| 66 |
|
| 67 |
$settings_data = array( |
| 68 |
'tabs' => $tabs, |
| 69 |
'settings' => $settings, |
| 70 |
); |
| 71 |
|
| 72 |
return $settings_data; |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Page Header Tabs. |
| 77 |
* |
| 78 |
* @param int $step_id Step ID. |
| 79 |
*/ |
| 80 |
public function get_settings_fields( $step_id ) { |
| 81 |
|
| 82 |
$next_step_link = wcf()->utils->get_linking_url( |
| 83 |
array( 'class' => 'wcf-next-step' ) |
| 84 |
); |
| 85 |
|
| 86 |
$options = $this->get_data( $step_id ); |
| 87 |
|
| 88 |
// Determine whether to show CodeMirror editors or the legacy textarea. |
| 89 |
$show_code_editor = \CartflowsAdmin\AdminCore\Inc\AdminHelper::should_show_code_editor(); |
| 90 |
|
| 91 |
$general_fields = array( |
| 92 |
'slug' => array( |
| 93 |
'type' => 'text', |
| 94 |
'name' => 'step_post_name', |
| 95 |
'label' => __( 'Step Slug', 'cartflows' ), |
| 96 |
'value' => get_post_field( 'post_name' ), |
| 97 |
'display_align' => 'vertical', |
| 98 |
), |
| 99 |
'wcf-disable-step-toggle' => array( |
| 100 |
'type' => 'toggle', |
| 101 |
'label' => __( 'Disable Step', 'cartflows' ), |
| 102 |
'name' => 'wcf-disable-step', |
| 103 |
'value' => $options['wcf-disable-step'], |
| 104 |
'tooltip' => __( 'Turn this on to disable the step', 'cartflows' ), |
| 105 |
'is_fullwidth' => true, |
| 106 |
), |
| 107 |
); |
| 108 |
|
| 109 |
if ( $show_code_editor ) { |
| 110 |
// Migration completed: show separate JS and CSS CodeMirror editors. |
| 111 |
$general_fields['wcf-landing-custom-js'] = array( |
| 112 |
'type' => 'code', |
| 113 |
'label' => __( 'Custom JavaScript', 'cartflows' ), |
| 114 |
'name' => 'wcf-step-custom-js', |
| 115 |
'value' => $options['wcf-step-custom-js'], |
| 116 |
'display_align' => 'vertical', |
| 117 |
'language' => 'javascript', |
| 118 |
'tooltip' => __( 'Add your own custom JavaScript code here. Do not include script tags.', 'cartflows' ), |
| 119 |
); |
| 120 |
$general_fields['wcf-landing-custom-css'] = array( |
| 121 |
'type' => 'code', |
| 122 |
'label' => __( 'Custom CSS', 'cartflows' ), |
| 123 |
'name' => 'wcf-step-custom-css', |
| 124 |
'value' => $options['wcf-step-custom-css'], |
| 125 |
'display_align' => 'vertical', |
| 126 |
'language' => 'css', |
| 127 |
'tooltip' => __( 'Add your own custom CSS code here. Do not include style tags.', 'cartflows' ), |
| 128 |
); |
| 129 |
} else { |
| 130 |
// Migration not completed: show the legacy combined textarea. |
| 131 |
$general_fields['wcf-landing-custom-script'] = array( |
| 132 |
'type' => 'textarea', |
| 133 |
'label' => __( 'Custom Script', 'cartflows' ), |
| 134 |
'name' => 'wcf-custom-script', |
| 135 |
'value' => $options['wcf-custom-script'], |
| 136 |
'display_align' => 'vertical', |
| 137 |
'tooltip' => __( 'Add your own custom code here. If you\'re adding CSS, make sure to wrap it inside <style> tags.', 'cartflows' ), |
| 138 |
); |
| 139 |
} |
| 140 |
|
| 141 |
$settings = array( |
| 142 |
'settings' => array( |
| 143 |
'shortcode' => array( |
| 144 |
'title' => __( 'Shortcode', 'cartflows' ), |
| 145 |
'slug' => 'shortcode', |
| 146 |
'priority' => 20, |
| 147 |
'fields' => array( |
| 148 |
'landing-shortcode' => array( |
| 149 |
'type' => 'text', |
| 150 |
'name' => 'thankyou-shortcode', |
| 151 |
'label' => __( 'Next Step Link', 'cartflows' ), |
| 152 |
'value' => $next_step_link, |
| 153 |
'readonly' => true, |
| 154 |
'display_align' => 'vertical', |
| 155 |
), |
| 156 |
), |
| 157 |
), |
| 158 |
'general' => array( |
| 159 |
'title' => __( 'General', 'cartflows' ), |
| 160 |
'slug' => 'general', |
| 161 |
'priority' => 10, |
| 162 |
'fields' => $general_fields, |
| 163 |
), |
| 164 |
), |
| 165 |
); |
| 166 |
|
| 167 |
if ( wcf_show_deprecated_step_notes() ) { |
| 168 |
$settings['settings']['general']['fields']['step-note'] = array( |
| 169 |
'type' => 'textarea', |
| 170 |
'name' => 'wcf-step-note', |
| 171 |
'label' => __( 'Step Note', 'cartflows' ), |
| 172 |
'value' => get_post_meta( $step_id, 'wcf-step-note', true ), |
| 173 |
'rows' => 2, |
| 174 |
'cols' => 38, |
| 175 |
'display_align' => 'vertical', |
| 176 |
); |
| 177 |
} |
| 178 |
|
| 179 |
return $settings; |
| 180 |
} |
| 181 |
|
| 182 |
/** |
| 183 |
* Get data. |
| 184 |
* |
| 185 |
* @param int $step_id Post ID. |
| 186 |
*/ |
| 187 |
public function get_data( $step_id ) { |
| 188 |
|
| 189 |
$optin_data = array(); |
| 190 |
|
| 191 |
// Stored data. |
| 192 |
$stored_meta = get_post_meta( $step_id ); |
| 193 |
|
| 194 |
// Default. |
| 195 |
$default_data = self::get_meta_option( $step_id ); |
| 196 |
|
| 197 |
// Set stored and override defaults. |
| 198 |
foreach ( $default_data as $key => $value ) { |
| 199 |
if ( array_key_exists( $key, $stored_meta ) ) { |
| 200 |
$optin_data[ $key ] = ( isset( $stored_meta[ $key ][0] ) ) ? maybe_unserialize( $stored_meta[ $key ][0] ) : ''; |
| 201 |
} else { |
| 202 |
$optin_data[ $key ] = ( isset( $default_data[ $key ]['default'] ) ) ? $default_data[ $key ]['default'] : ''; |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
return $optin_data; |
| 207 |
} |
| 208 |
|
| 209 |
/** |
| 210 |
* Get meta. |
| 211 |
* |
| 212 |
* @param int $post_id Post ID. |
| 213 |
*/ |
| 214 |
public static function get_meta_option( $post_id ) { |
| 215 |
|
| 216 |
$meta_option = wcf()->options->get_landing_fields( $post_id ); |
| 217 |
|
| 218 |
return $meta_option; |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
/** |
| 223 |
* Kicking this off by calling 'get_instance()' method. |
| 224 |
*/ |
| 225 |
Cartflows_Landing_Meta_Data::get_instance(); |
| 226 |
|