PluginProbe
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution with eCommerce Templates & Woo Widgets / 3.0.0
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution with eCommerce Templates & Woo Widgets v3.0.0
4.9.5 4.9.4 4.9.3 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 All 85 releases
shopengine / libs / select-api / base.php
base.php
214 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ShopEngine\Libs\Select_Api;
3
4 defined('ABSPATH') || exit;
5
6 /**
7 * Class Api
8 *
9 * @package ShopEngine\Core\Builders
10 */
11 class Base extends \ShopEngine\Base\Api {
12
13 public function config() {
14
15 $this->prefix = 'ajaxselect2';
16 }
17
18 public function get_post_list(){
19
20 if(!current_user_can('edit_posts')){
21 return;
22 }
23
24 $query_args = [
25 'post_type' => 'post',
26 'post_status' => 'publish',
27 'posts_per_page' => 15,
28 ];
29
30 if(isset($this->request['ids'])){
31 $ids = explode(',', $this->request['ids']);
32 $query_args['post__in'] = $ids;
33 }
34 if(isset($this->request['s'])){
35 $query_args['s'] = $this->request['s'];
36 }
37
38 $query = new \WP_Query($query_args);
39 $options = [];
40 if($query->have_posts()):
41 while ($query->have_posts()) {
42 $query->the_post();
43 $options[] = [ 'id' => get_the_ID(), 'text' => get_the_title() ];
44 }
45 endif;
46
47 return ['results' => $options];
48 wp_reset_postdata();
49 }
50
51 public function get_page_list(){
52 if(!current_user_can('edit_posts')){
53 return;
54 }
55 $query_args = [
56 'post_type' => 'page',
57 'post_status' => 'publish',
58 'posts_per_page' => 15,
59 ];
60
61 if(isset($this->request['ids'])){
62 $ids = explode(',', $this->request['ids']);
63 $query_args['post__in'] = $ids;
64 }
65 if(isset($this->request['s'])){
66 $query_args['s'] = $this->request['s'];
67 }
68
69 $query = new \WP_Query($query_args);
70 $options = [];
71 if($query->have_posts()):
72 while ($query->have_posts()) {
73 $query->the_post();
74 $options[] = [ 'id' => get_the_ID(), 'text' => get_the_title() ];
75 }
76 endif;
77
78 return ['results' => $options];
79 wp_reset_postdata();
80 }
81
82 public function get_singular_list(){
83 $query_args = [
84 'post_status' => 'publish',
85 'posts_per_page' => 15,
86 'post_type' => 'any'
87 ];
88
89 if(isset($this->request['ids'])){
90 $ids = explode(',', $this->request['ids']);
91 $query_args['post__in'] = $ids;
92 }
93 if(isset($this->request['s'])){
94 $query_args['s'] = $this->request['s'];
95 }
96
97 $query = new \WP_Query($query_args);
98 $options = [];
99 if($query->have_posts()):
100 while ($query->have_posts()) {
101 $query->the_post();
102 $options[] = [ 'id' => get_the_ID(), 'text' => get_the_title() ];
103 }
104 endif;
105
106 return ['results' => $options];
107 wp_reset_postdata();
108 }
109
110 public function get_product_list(){
111 $query_args = [
112 'post_type' => 'product',
113 'post_status' => 'publish',
114 'posts_per_page' => 15,
115 ];
116
117 if(isset($this->request['ids'])){
118 $ids = explode(',', $this->request['ids']);
119 $query_args['post__in'] = $ids;
120 }
121 if(isset($this->request['s'])){
122 $query_args['s'] = $this->request['s'];
123 }
124
125 $query = new \WP_Query($query_args);
126 $options = [];
127 if($query->have_posts()):
128 while ($query->have_posts()) {
129 $query->the_post();
130 $options[] = [ 'id' => get_the_ID(), 'text' => get_the_title() ];
131 }
132 endif;
133
134 return ['results' => $options];
135 wp_reset_postdata();
136 }
137
138 public function get_category(){
139 return $this->terms(['category'], true);
140 }
141
142 public function get_product_cat(){
143 return $this->terms(['product_cat']);
144 }
145
146 public function get_product_tags() {
147 return $this->terms(['product_tag']);
148 }
149
150 public function get_product_terms() {
151 if(isset($this->request['taxonomy'])){
152 return $this->terms([$this->request['taxonomy']]);
153 } elseif(isset($this->request['ids'])) {
154 return $this->terms([]);
155 }
156 return ['results' => []];
157 }
158
159 public function get_product_pa_list() {
160
161 global $wpdb;
162
163 $search = '';
164 if(isset($this->request['s'])) {
165 $search = $this->request['s'];
166 }
167
168 $query = "SELECT * FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name LIKE '%{$search}%' ORDER BY attribute_name ASC LIMIT 10";
169 $attributes = $wpdb->get_results($query);
170
171 $options = [];
172
173 foreach ($attributes as $attribute) {
174 $options[] = ['id' => 'pa_' .$attribute->attribute_name, 'text' => $attribute->attribute_label];
175 }
176
177 return ['results' => $options];
178 }
179
180 /**
181 * @param $taxonomies
182 * @param $hide_empty
183 */
184 public function terms($taxonomies, $hide_empty = false) {
185 $query_args = [
186 'taxonomy' => $taxonomies, // taxonomy name
187 'orderby' => 'name',
188 'order' => 'DESC',
189 'hide_empty' => $hide_empty,
190 'number' => 10
191 ];
192
193 if(isset($this->request['ids'])){
194 $ids = explode(',', $this->request['ids']);
195 $query_args['include'] = $ids;
196 }
197 if(isset($this->request['s'])){
198 $query_args['name__like'] = $this->request['s'];
199 }
200
201 $terms = get_terms( $query_args );
202
203
204 $options = [];
205
206 if(is_countable($terms) && count($terms) > 0):
207 foreach ($terms as $term) {
208 $options[] = [ 'id' => $term->term_id, 'text' => $term->name ];
209 }
210 endif;
211
212 return ['results' => $options];
213 }
214 }