PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 1.0.0
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v1.0.0
4.9.1 4.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.1 3.0.0 3.1.0 3.1.1 4.0.0 4.0.1 4.1.0 4.1.1 4.2.0 4.2.1 4.3.0 4.3.1 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.6.8 4.6.9 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.8.9 trunk 0.1.2-beta 0.1.3-beta 0.1.4-beta 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.5.0 1.5.1 1.6.0 1.6.1 1.7.0 1.8.0 1.8.1 1.9.0
shopengine / core / builders / action.php
shopengine / core / builders Last commit date
action.php 5 years ago api.php 5 years ago base.php 5 years ago hooks.php 5 years ago templates.php 5 years ago
action.php
233 lines
1 <?php
2
3 namespace ShopEngine\Core\Builders;
4
5 defined('ABSPATH') || exit;
6
7 use ShopEngine\Core\Template_Cpt;
8 use ShopEngine\Traits\Singleton;
9
10 /**
11 * Action Class.
12 * for post insert, update and get data.
13 *
14 * @since 1.0.0
15 */
16 class Action {
17
18 use Singleton;
19
20 const PK__SHOPENGINE_TEMPLATE = 'shopengine_template__post_meta';
21
22 public $key_form_settings;
23 private $post_type;
24
25 private $fields;
26 private $form_id;
27 private $form_setting;
28 private $title;
29 private $response = [];
30
31
32 /**
33 * Public function __construct.
34 * call function for all
35 *
36 * @since 1.0.0
37 */
38 public function __construct() {
39
40 $this->post_type = Template_Cpt::TYPE;
41
42 $this->key_form_settings = self::PK__SHOPENGINE_TEMPLATE;
43
44 $this->response = [
45 'saved' => false,
46 'status' => esc_html__("Something went wrong.", 'shopengine'),
47 'data' => [],
48 ];
49 }
50
51
52 /**
53 * Public function store.
54 * store data for post
55 *
56 * @since 1.0.0
57 */
58 public function store($form_id, $form_setting) {
59
60 $this->fields = $this->get_fields();
61 $this->set_values($form_setting);
62 $this->form_id = $form_id;
63
64 if($this->form_id == 0) {
65 $this->insert();
66 } else {
67 $this->update();
68 }
69
70 return $this->response;
71 }
72
73
74 public function insert() {
75
76 $this->title = ($this->form_setting['form_title'] != '') ? $this->form_setting['form_title'] : 'New Template # ' . time();
77
78 $defaults = array(
79 'post_title' => $this->title,
80 'post_status' => 'publish',
81 'post_type' => $this->post_type,
82 );
83
84 $this->form_id = wp_insert_post($defaults);
85
86 // save custom meta data
87 update_post_meta($this->form_id, self::PK__SHOPENGINE_TEMPLATE, $this->form_setting);
88
89
90
91 //set default meta
92 $default = isset($this->form_setting['set_defalut']) ? $this->form_setting['set_defalut'] : 'No';
93 $type = isset($this->form_setting['form_type']) ? $this->form_setting['form_type'] : 'single';
94
95 update_post_meta($this->form_id, self::PK__SHOPENGINE_TEMPLATE . '__type', $type);
96
97 // check options key value
98 $keyType = self::PK__SHOPENGINE_TEMPLATE . '__' . $type;
99
100 if($default == 'Yes') {
101 update_option($keyType, $this->form_id);
102 }
103
104 // auto elementor canvas style
105 update_post_meta($this->form_id, '_wp_page_template', 'elementor_canvas');
106 update_post_meta( $this->form_id, '_elementor_edit_mode', 'builder');
107
108 if(!empty($this->form_setting['sample_design'])){
109 $design_data = \ShopEngine\Core\Sample_Designs\Base::instance()->get_design_data($this->form_setting['sample_design']);
110 if(!is_null($design_data)){
111 update_post_meta($this->form_id, '_elementor_data', json_encode($design_data));
112 }
113 }
114
115 $this->response['saved'] = true;
116 $this->response['status'] = esc_html__('Template settings inserted', 'shopengine');
117
118 $this->response['data']['id'] = $this->form_id;
119 $this->response['data']['title'] = $this->title;
120 $this->response['data']['type'] = $this->post_type;
121 }
122
123
124 public function update() {
125
126 $this->title = ($this->form_setting['form_title'] != '') ? $this->form_setting['form_title'] : 'New Template # ' . time();
127
128 if(isset($this->form_setting['form_title'])) {
129 $update_post = array(
130 'ID' => $this->form_id,
131 'post_title' => $this->title,
132 );
133 wp_update_post($update_post);
134 }
135
136 // save custom meta data
137 update_post_meta($this->form_id, $this->key_form_settings, $this->form_setting);
138
139 //set default meta
140 $default = isset($this->form_setting['set_defalut']) ? $this->form_setting['set_defalut'] : 'No';
141 $type = isset($this->form_setting['form_type']) ? $this->form_setting['form_type'] : 'single';
142
143 update_post_meta($this->form_id, $this->key_form_settings . '__type', $type);
144
145 // check options key value
146 $keyType = $this->key_form_settings . '__' . $type;
147
148 $getSetDefault = get_option($keyType, 0);
149 if($default == 'Yes') {
150 update_option($keyType, $this->form_id);
151 } elseif($this->form_id == $getSetDefault) {
152 update_option($keyType, 0);
153 }
154
155 //auto elementor canvas style
156 update_post_meta($this->form_id, '_wp_page_template', 'elementor_canvas');
157
158 $this->response['saved'] = true;
159 $this->response['status'] = esc_html__('Template settings updated', 'shopengine');
160
161 $this->response['data']['id'] = $this->form_id;
162 $this->response['data']['title'] = $this->title;
163 $this->response['data']['type'] = $this->post_type;
164 }
165
166
167 /**
168 *
169 * @return array
170 */
171 public function get_fields() {
172
173 return [
174
175 'form_title' => [
176 'name' => 'form_title',
177 ],
178 'form_type' => [
179 'name' => 'form_type',
180 ],
181 'set_defalut' => [
182 'name' => 'set_defalut',
183 ],
184 'sample_design' => [
185 'name' => 'sample_design',
186 ],
187 ];
188 }
189
190
191 /**
192 *
193 * @param $form_setting
194 * @param null $fields
195 */
196 public function set_values($form_setting, $fields = null) {
197
198 if($fields == null) {
199 $fields = $this->fields;
200 }
201
202 foreach($form_setting as $key => $value) {
203
204 if(isset($fields[$key])) {
205 $this->form_setting[$key] = $value;
206 }
207 }
208 }
209
210
211 /**
212 *
213 * @param $post_id
214 *
215 * @return mixed
216 */
217 public function get_all_data($post_id) {
218
219 $post = get_post($post_id);
220 $data = get_post_meta($post->ID, $this->key_form_settings, true);
221 $type = isset($data['form_type']) ? $data['form_type'] : 'single';
222
223
224 $data['form_title'] = get_the_title($post_id);
225 $data['set_defalut'] = 'No';
226
227 if(Templates::get_default_template_id_for_type($type) == $post->ID) {
228 $data['set_defalut'] = 'Yes';
229 }
230
231 return $data;
232 }
233 }