PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 4.0.0
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v4.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 / settings / api.php
shopengine / core / settings Last commit date
screens 3 years ago action.php 3 years ago api.php 3 years ago base.php 3 years ago plugin-status.php 3 years ago
api.php
183 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 }
21
22
23 public function post_save() {
24
25 if( !wp_verify_nonce( $this->request->get_header('x_wp_nonce'), 'wp_rest') && !current_user_can( 'manage_options' ) ) {
26 return false;
27 }
28
29 $data = json_decode($this->request->get_body(), true);
30
31 if(!empty($data['widgets'])) {
32
33 Model::source('settings')->set_option('widgets', $data['widgets']);
34 }
35
36 if(!empty($data['modules'])) {
37
38 Model::source('settings')->set_option('modules', $data['modules']);
39 }
40
41 if(!empty($data['userdata'])) {
42
43 Model::source('settings')->set_option('userdata', $data['userdata']);
44 }
45
46 do_action('shopengine/core/settings/on_save', $data);
47
48 return [
49 'status' => 'success',
50 'message' => esc_html__('settings saved successfully.', 'shopengine'),
51 ];
52 }
53
54
55 public function get_fields() {
56 $fields = array_merge(
57 Action::instance()->get_fields(),
58 ['sample_designs' => \ShopEngine\Core\Sample_Designs\Base::instance()->get_designs()]
59 );
60
61 return apply_filters('shopengine/core/settings/return_fields', $fields);
62 }
63
64 public function get_data() {
65 $data = Action::instance()->get_data();
66
67 return apply_filters('shopengine/core/settings/return_data', $data);
68 }
69
70 public function get_our_others_plugin_install_api() {
71 $plugins = [
72 'elementskit-lite' => 'elementskit-lite.php',
73 'metform' => 'metform.php',
74 'wp-social' => 'wp-social.php',
75 'wp-ultimate-review' => 'wp-ultimate-review.php',
76 'wp-fundraising-donation' => 'wp-fundraising-donation.php',
77 'getgenie' => 'getgenie.php'
78 ];
79
80 $plugin_status = Plugin_Status::instance();
81 $plugins_data = [];
82
83 foreach($plugins as $slug => $file) {
84 $plugins_data[$slug] = $plugin_status->get_status($slug.'/'.$file);
85 }
86 return $plugins_data;
87 }
88
89 public function post_save_onboard() {
90 $data = $this->request->get_params();
91 $onboard = new Onboard();
92 return $onboard->submit($data);
93 }
94
95 public function get_categories() {
96
97 $data = $this->request->get_params();
98
99 $query_args = [
100 'taxonomy' => ['product_cat'], // taxonomy name
101 'orderby' => 'name',
102 'order' => 'DESC',
103 'hide_empty' => false,
104 'number' => 10
105 ];
106
107 if(isset($data['only_parent'])){
108 $query_args['parent'] = 0;
109 }
110
111 if(isset($data['ids'])){
112 $ids = explode(',', $data['ids']);
113 $query_args['include'] = $ids;
114 }
115 if(isset($data['s'])){
116 $query_args['name__like'] = $data['s'];
117 }
118
119 $product_cat = get_terms($query_args);
120 $product_categories = [];
121 foreach($product_cat as $category) {
122 $product_categories[$category->term_id] = $category->name;
123 }
124 return [
125 'status' => 'success',
126 'result' => $product_categories,
127 'message' => esc_html__('categories fetched', 'shopengine')
128 ];
129 }
130
131 public function get_posts() {
132
133 $data = $this->request->get_params();
134
135 if(empty($data['post_type'])) {
136 return [
137 'status' => 'failed'
138 ];
139 }
140
141 $search = isset($data['s']) ? $data['s'] : false;
142 $post_status = !empty($data['post_status']) ? $data['post_status'] : '';
143
144 global $wpdb;
145
146 $params = [
147 sanitize_text_field($data['post_type'])
148 ];
149
150 $post_status_array = ['publish'];
151 if($post_status === 'draft'){
152 $post_status_array[] = 'draft';
153 }
154
155 $escaped = array();
156 foreach($post_status_array as $status_item){
157 $escaped[] = $wpdb->prepare('%s', sanitize_text_field($status_item));
158 }
159 $post_status = implode(',', $escaped);
160
161 $post_search_statement = '';
162 if(!empty($search)){
163 $post_search_statement = 'AND post_title LIKE %s';
164 array_push($params, '%'. $wpdb->esc_like( $search ) .'%');
165 }
166
167 //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Already applied prepare method in top
168 $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) );
169
170 $post_items = [];
171 foreach($posts as $post) {
172 array_push($post_items, ['id' => $post->ID, 'text' => $post->post_title]);
173 }
174
175 return [
176 'status' => 'success',
177 'results' => $post_items,
178 ];
179 }
180 }
181
182
183