PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 1.3.4
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v1.3.4
4.9.2 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 4 years ago api.php 5 years ago base.php 4 years ago hooks.php 4 years ago templates.php 4 years ago
action.php
241 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 global $wp_rewrite; $wp_rewrite->flush_rules(); $wp_rewrite->init();
66 $this->insert();
67 } else {
68 $this->update();
69 }
70
71 return $this->response;
72 }
73
74
75 public function insert() {
76
77 $this->title = ($this->form_setting['form_title'] != '') ? $this->form_setting['form_title'] : 'New Template # ' . time();
78
79 $defaults = array(
80 'post_title' => $this->title,
81 'post_status' => 'publish',
82 'post_type' => $this->post_type,
83 );
84
85 $this->form_id = wp_insert_post($defaults);
86
87 // save custom meta data
88 update_post_meta($this->form_id, self::PK__SHOPENGINE_TEMPLATE, $this->form_setting);
89
90
91 //set default meta
92 $default = isset($this->form_setting['set_default']) ? $this->form_setting['set_default'] : 'No';
93 $type = isset($this->form_setting['form_type']) ? $this->form_setting['form_type'] : 'single';
94
95 update_post_meta($this->form_id, self::get_meta_key_for_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_header_footer' );
106 update_post_meta( $this->form_id, '_elementor_edit_mode', 'builder' );
107 update_post_meta( $this->form_id, '_elementor_version', '3.4.6' );
108 update_post_meta( $this->form_id, 'shopengine_template_uuid', time() . '-' . $this->form_id );
109
110 if(!empty($this->form_setting['sample_design'])){
111 $design_data = \ShopEngine\Core\Sample_Designs\Base::instance()->get_design_data($this->form_setting['sample_design']);
112 if(!is_null($design_data)){
113 update_post_meta($this->form_id, '_elementor_data', json_encode($design_data));
114 }
115 }
116
117 $this->response['saved'] = true;
118 $this->response['status'] = esc_html__('Template settings inserted', 'shopengine');
119
120 $this->response['data']['id'] = $this->form_id;
121 $this->response['data']['title'] = $this->title;
122 $this->response['data']['type'] = $this->post_type;
123 }
124
125
126 public function update() {
127
128 $this->title = ($this->form_setting['form_title'] != '') ? $this->form_setting['form_title'] : 'New Template # ' . time();
129
130 if(isset($this->form_setting['form_title'])) {
131 $update_post = array(
132 'ID' => $this->form_id,
133 'post_title' => $this->title,
134 'post_status' => 'publish',
135 );
136 wp_update_post($update_post);
137 }
138
139 // save custom meta data
140 update_post_meta($this->form_id, $this->key_form_settings, $this->form_setting);
141
142 //set default meta
143 $default = isset($this->form_setting['set_default']) ? $this->form_setting['set_default'] : 'No';
144 $type = isset($this->form_setting['form_type']) ? $this->form_setting['form_type'] : 'single';
145
146 update_post_meta($this->form_id, $this->key_form_settings . '__type', $type);
147
148 // check options key value
149 $keyType = $this->key_form_settings . '__' . $type;
150
151 if($default == 'Yes') {
152 update_option($keyType, $this->form_id);
153 }
154
155 if($default == 'No') {
156 update_option($keyType, 0);
157 }
158
159 $this->response['saved'] = true;
160 $this->response['status'] = esc_html__('Template settings updated', 'shopengine');
161
162 $this->response['data']['id'] = $this->form_id;
163 $this->response['data']['title'] = $this->title;
164 $this->response['data']['type'] = $this->post_type;
165 }
166
167
168 /**
169 *
170 * @return array
171 */
172 public function get_fields() {
173
174 return [
175
176 'form_title' => [
177 'name' => 'form_title',
178 ],
179 'form_type' => [
180 'name' => 'form_type',
181 ],
182 'set_default' => [
183 'name' => 'set_default',
184 ],
185 'sample_design' => [
186 'name' => 'sample_design',
187 ],
188 ];
189 }
190
191
192 /**
193 *
194 * @param $form_setting
195 * @param null $fields
196 */
197 public function set_values($form_setting, $fields = null) {
198
199 if($fields == null) {
200 $fields = $this->fields;
201 }
202
203 foreach($form_setting as $key => $value) {
204
205 if(isset($fields[$key])) {
206 $this->form_setting[$key] = $value;
207 }
208 }
209 }
210
211
212 /**
213 *
214 * @param $post_id
215 *
216 * @return mixed
217 */
218 public function get_all_data($post_id) {
219
220 $post = get_post($post_id);
221 $data = get_post_meta($post->ID, $this->key_form_settings, true);
222 $type = isset($data['form_type']) ? $data['form_type'] : 'single';
223
224
225 $data['form_title'] = get_the_title($post_id);
226 $data['set_default'] = 'No';
227
228 if(Templates::get_registered_template_id($type) == $post->ID) {
229 $data['set_default'] = 'Yes';
230 }
231
232 return $data;
233 }
234
235
236 public static function get_meta_key_for_type() {
237
238 return self::PK__SHOPENGINE_TEMPLATE.'__type';
239 }
240 }
241