PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 4.9.2
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v4.9.2
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 / settings / api.php
shopengine / core / settings Last commit date
screens 4 years ago action.php 2 years ago api.php 1 week ago base.php 1 week ago plugin-status.php 4 years ago
api.php
275 lines
1 <?php
2 namespace ShopEngine\Core\Settings;
3
4 use ShopEngine\Core\Onboard\Onboard;
5 use ShopEngine\Core\Register\Model;
6
7 defined('ABSPATH') || exit;
8
9 /**
10 * Class Api
11 *
12 * @package ShopEngine\Core\Builders
13 */
14 class Api extends \ShopEngine\Base\Api {
15
16 public function config() {
17
18 $this->prefix = 'settings';
19 $this->param = "";
20 $this->only_admin = true;
21 }
22
23
24 public function post_save() {
25
26 if( !wp_verify_nonce( $this->request->get_header('x_wp_nonce'), 'wp_rest') || !current_user_can( 'manage_options' ) ) {
27 return false;
28 }
29
30 $data = json_decode($this->request->get_body(), true);
31
32 if(!empty($data['widgets'])) {
33
34 Model::source('settings')->set_option('widgets', $data['widgets']);
35 }
36
37 if(!empty($data['modules'])) {
38
39 Model::source('settings')->set_option('modules', $data['modules']);
40 }
41
42 if(!empty($data['userdata'])) {
43
44 Model::source('settings')->set_option('userdata', $data['userdata']);
45 }
46
47 do_action('shopengine/core/settings/on_save', $data);
48
49 return [
50 'status' => 'success',
51 'message' => esc_html__('settings saved successfully.', 'shopengine'),
52 ];
53 }
54
55
56 public function get_fields() {
57 $fields = array_merge(
58 Action::instance()->get_fields(),
59 ['sample_designs' => \ShopEngine\Core\Sample_Designs\Base::instance()->get_designs()]
60 );
61
62 return apply_filters('shopengine/core/settings/return_fields', $fields);
63 }
64
65 public function get_data() {
66 $data = Action::instance()->get_data();
67
68 return apply_filters('shopengine/core/settings/return_data', $data);
69 }
70
71 public function get_our_others_plugin_install_api() {
72 $plugins = [
73 'elementskit-lite' => 'elementskit-lite.php',
74 'metform' => 'metform.php',
75 'gutenkit-blocks-addon' => 'gutenkit-blocks-addon.php',
76 'popup-builder-block' => 'popup-builder-block.php',
77 'emailkit' => 'EmailKit.php',
78 'getgenie' => 'getgenie.php',
79 ];
80
81 $plugin_status = Plugin_Status::instance();
82 $plugins_data = [];
83
84 foreach($plugins as $slug => $file) {
85 $plugins_data[$slug] = $plugin_status->get_status($slug.'/'.$file);
86 }
87 return $plugins_data;
88 }
89
90 public function post_save_onboard() {
91 $data = $this->request->get_params();
92 $onboard = new Onboard();
93 return $onboard->submit($data);
94 }
95
96 public function get_categories() {
97
98 $data = $this->request->get_params();
99
100 $query_args = [
101 'taxonomy' => ['product_cat'], // taxonomy name
102 'orderby' => 'name',
103 'order' => 'DESC',
104 'hide_empty' => false,
105 'number' => isset($data['number']) ? absint($data['number']) : 0 // limit number of terms, 0 = no limit
106 ];
107
108 if(isset($data['only_parent'])){
109 $query_args['parent'] = 0;
110 }
111
112 // Allow requesting children for a specific parent id
113 if (isset($data['parent'])) {
114 $query_args['parent'] = absint($data['parent']);
115 }
116
117 if(isset($data['ids'])){
118 $ids = explode(',', $data['ids']);
119 $query_args['include'] = $ids;
120 }
121 if(isset($data['s'])){
122 $query_args['name__like'] = $data['s'];
123 }
124
125 $product_cat = get_terms($query_args);
126 $product_categories = [];
127 $categories_with_children_info = [];
128
129 foreach($product_cat as $category) {
130 $product_categories[$category->term_id] = $category->name;
131
132 // Check if this category has children
133 $children_count = get_terms([
134 'taxonomy' => 'product_cat',
135 'parent' => $category->term_id,
136 'hide_empty' => false,
137 'fields' => 'count'
138 ]);
139
140 $categories_with_children_info[$category->term_id] = [
141 'name' => $category->name,
142 'has_children' => $children_count > 0
143 ];
144 }
145
146 // If a number limit is provided, also report if there are more children available
147 $more = 0;
148 if (!empty($data['number'])) {
149 // If parent is set, count total children for that parent; otherwise count top-level if only_parent
150 $count_args = $query_args;
151 // remove number limit for counting
152 unset($count_args['number']);
153 $all_terms = get_terms($count_args);
154 $total = is_array($all_terms) ? count($all_terms) : 0;
155 $more = max(0, $total - intval($data['number']));
156 }
157
158 return [
159 'status' => 'success',
160 'result' => $product_categories,
161 'result_with_children' => $categories_with_children_info,
162 'more' => $more,
163 'message' => esc_html__('categories fetched', 'shopengine')
164 ];
165 }
166
167 public function get_posts() {
168
169 $data = $this->request->get_params();
170
171 if(empty($data['post_type'])) {
172 return [
173 'status' => 'failed'
174 ];
175 }
176
177 $search = isset($data['s']) ? $data['s'] : false;
178 $post_status = !empty($data['post_status']) ? $data['post_status'] : '';
179
180 global $wpdb;
181
182 $params = [
183 sanitize_text_field($data['post_type'])
184 ];
185
186 $post_status_array = ['publish'];
187 if($post_status === 'draft'){
188 $post_status_array[] = 'draft';
189 }
190
191 $escaped = array();
192 foreach($post_status_array as $status_item){
193 $escaped[] = $wpdb->prepare('%s', sanitize_text_field($status_item));
194 }
195 $post_status = implode(',', $escaped);
196
197 $post_search_statement = '';
198 if(!empty($search)){
199 $post_search_statement = 'AND post_title LIKE %s';
200 array_push($params, '%'. $wpdb->esc_like( $search ) .'%');
201 }
202
203 //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Already applied prepare method in top
204 $posts = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->posts WHERE post_type=%s AND post_status IN ($post_status) $post_search_statement LIMIT 10", $params) );
205
206 $post_items = [];
207 foreach($posts as $post) {
208 array_push($post_items, ['id' => $post->ID, 'text' => $post->post_title]);
209 }
210
211 return [
212 'status' => 'success',
213 'results' => $post_items,
214 ];
215 }
216 public function post_onboard_plugins() {
217
218 // Get plugin_slug directly from request parameters
219 $plugin_slug = $this->request->get_param('plugin_slug');
220
221 if (empty($plugin_slug)) {
222 return [
223 'success' => false,
224 'message' => 'Plugin slug is required'
225 ];
226 }
227
228 if (!current_user_can('install_plugins')) {
229 return [
230 'success' => false,
231 'message' => 'Insufficient permissions to install plugins'
232 ];
233 }
234
235
236 $status = \ShopEngine\Utils\Onboard\Plugin_Installer::single_install_and_activate($plugin_slug);
237
238 if ($status === false) {
239 return [
240 'success' => false,
241 'message' => 'Plugin installation failed'
242 ];
243 } else {
244 return [
245 'success' => true,
246 'data' => [
247 'message' => self::plugin_activate_message($plugin_slug)
248 ]
249 ];
250 }
251 }
252
253 public static function plugin_activate_message($plugin_slug) {
254 $plugins_message = [
255 'setup_configurations' => esc_html__('Setup Configurations', 'shopengine'),
256 'elementskit-lite/elementskit-lite.php' => esc_html__('Page Builder Elements Activated', 'shopengine'),
257 'getgenie/getgenie.php' => esc_html__('AI Content & SEO Tool Activated', 'shopengine'),
258 'shopengine/shopengine.php' => esc_html__('WooCommerce Builder Activated', 'shopengine'),
259 'metform/metform.php' => esc_html__('Form Builder Activated', 'shopengine'),
260 'emailkit/EmailKit.php' => esc_html__('Email Customizer Activated', 'shopengine'),
261 'gutenkit-blocks-addon/gutenkit-blocks-addon.php' => esc_html__('Page Builder Blocks Activated', 'shopengine'),
262 'popup-builder-block/popup-builder-block.php' => esc_html__('Popup Builder Activated', 'shopengine'),
263 'table-builder-block/table-builder-block.php' => esc_html__('Table Builder Activated', 'shopengine'),
264 ];
265
266 if ( array_key_exists( $plugin_slug, $plugins_message ) ) {
267 return esc_html( $plugins_message[$plugin_slug] );
268 } else {
269 return esc_html__( 'Plugin Activated', 'shopengine' );
270 }
271 }
272 }
273
274
275