PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 2.2.2
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v2.2.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 / libs / select-api / base.php
shopengine / libs / select-api Last commit date
base.php 4 years ago
base.php
205 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 = '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_pa_list() {
151
152 global $wpdb;
153
154 $search = '';
155 if(isset($this->request['s'])) {
156 $search = $this->request['s'];
157 }
158
159 $query = "SELECT * FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name LIKE '%{$search}%' ORDER BY attribute_name ASC LIMIT 10";
160 $attributes = $wpdb->get_results($query);
161
162 $options = [];
163
164 foreach ($attributes as $attribute) {
165 $options[] = ['id' => 'pa_' .$attribute->attribute_name, 'text' => $attribute->attribute_label];
166 }
167
168 return ['results' => $options];
169 }
170
171 /**
172 * @param $taxonomies
173 * @param $hide_empty
174 */
175 public function terms($taxonomies, $hide_empty = false) {
176 $query_args = [
177 'taxonomy' => $taxonomies, // taxonomy name
178 'orderby' => 'name',
179 'order' => 'DESC',
180 'hide_empty' => $hide_empty,
181 'number' => 10
182 ];
183
184 if(isset($this->request['ids'])){
185 $ids = explode(',', $this->request['ids']);
186 $query_args['include'] = $ids;
187 }
188 if(isset($this->request['s'])){
189 $query_args['name__like'] = $this->request['s'];
190 }
191
192 $terms = get_terms( $query_args );
193
194
195 $options = [];
196
197 if(is_countable($terms) && count($terms) > 0):
198 foreach ($terms as $term) {
199 $options[] = [ 'id' => $term->term_id, 'text' => $term->name ];
200 }
201 endif;
202
203 return ['results' => $options];
204 }
205 }