PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 4.7.3
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v4.7.3
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 / libs / select-api / base.php
shopengine / libs / select-api Last commit date
base.php 1 year ago
base.php
213 lines
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 = 'shopengine_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' => apply_filters('shopengine_filterable_products_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 $attributes = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name LIKE %s ORDER BY attribute_name ASC LIMIT 10", "%{$search}%"));
169
170 $options = [];
171
172 foreach ($attributes as $attribute) {
173 $options[] = ['id' => 'pa_' .$attribute->attribute_name, 'text' => $attribute->attribute_label];
174 }
175
176 return ['results' => $options];
177 }
178
179 /**
180 * @param $taxonomies
181 * @param $hide_empty
182 */
183 public function terms($taxonomies, $hide_empty = false) {
184 $query_args = [
185 'taxonomy' => $taxonomies, // taxonomy name
186 'orderby' => 'name',
187 'order' => 'DESC',
188 'hide_empty' => $hide_empty,
189 'number' => 10
190 ];
191
192 if(isset($this->request['ids'])){
193 $ids = explode(',', $this->request['ids']);
194 $query_args['include'] = $ids;
195 }
196 if(isset($this->request['s'])){
197 $query_args['name__like'] = $this->request['s'];
198 }
199
200 $terms = get_terms( $query_args );
201
202
203 $options = [];
204
205 if(is_countable($terms) && count($terms) > 0):
206 foreach ($terms as $term) {
207 $options[] = [ 'id' => $term->term_id, 'text' => $term->name ];
208 }
209 endif;
210
211 return ['results' => $options];
212 }
213 }