PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.5.6
Post Grid Gutenberg Blocks – PostX v2.5.6
5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 2.1.2 All 237 releases
← All changes | classes/REST_API.php +255 -696 5.0.302.5.6 View file →
@@ -1,749 +1,308 @@
1 1 <?php
2 2 /**
3 3 * REST API Action.
4 - *
4 + *
5 5 * @package ULTP\REST_API
6 6 * @since v.1.0.0
7 7 */
8 -
9 8 namespace ULTP;
10 9
11 -defined( 'ABSPATH' ) || exit;
10 +defined('ABSPATH') || exit;
12 11
13 12 /**
14 - * REST API class.
15 - *
16 - * Handles custom REST API endpoints for Ultimate Post plugin.
17 - *
18 - * @package ULTP\REST_API
19 - * @since 4.0.0
13 + * Styles class.
20 14 */
21 -class REST_API {
22 -
23 - /**
15 +class REST_API{
16 +
17 + /**
24 18 * Setup class.
25 19 *
26 20 * @since v.1.0.0
27 21 */
28 - public function __construct() {
29 - add_action( 'rest_api_init', array( $this, 'ultp_register_route' ) );
30 - }
22 + public function __construct() {
23 + add_action( 'rest_api_init', array($this, 'ultp_register_route') );
24 + }
31 25
32 - /**
26 +
27 + /**
33 28 * REST API Action
34 - *
35 - * @since v.1.0.0
36 - * @return void
29 + *
30 + * @since v.1.0.0
31 + * @return NULL
37 32 */
38 - public function ultp_register_route() {
39 - register_rest_route(
40 - 'ultp',
41 - 'common_data',
42 - array(
43 - 'methods' => \WP_REST_Server::READABLE,
44 - 'args' => array( 'wpnonce' => array() ),
45 - 'callback' => array( $this, 'ultp_route_common_data' ),
46 - 'permission_callback' => function () {
47 - return current_user_can( 'edit_posts' );
48 - },
49 - )
50 - );
51 - register_rest_route(
52 - 'ultp',
53 - '/fetch_posts/',
54 - array(
55 - array(
56 - 'methods' => 'POST',
57 - 'args' => array(),
58 - 'callback' => array( $this, 'ultp_route_post_data' ),
59 - 'permission_callback' => function () {
60 - return current_user_can( 'edit_posts' );
61 - },
62 - ),
63 - )
64 - );
65 - register_rest_route(
66 - 'ultp',
67 - '/specific_taxonomy/',
68 - array(
69 - array(
70 - 'methods' => 'POST',
71 - 'args' => array(),
72 - 'callback' => array( $this, 'ultp_route_taxonomy_info_data' ),
73 - 'permission_callback' => function () {
74 - return current_user_can( 'edit_others_posts' );
75 - },
76 - ),
77 - )
78 - );
79 - register_rest_route(
33 + public function ultp_register_route() {
34 + register_rest_route( 'ultp', 'posts', array(
35 + 'methods' => \WP_REST_Server::READABLE,
36 + 'args' => array(),
37 + 'callback' => array($this,'ultp_route_post_data'),
38 + 'permission_callback' => '__return_true'
39 + )
40 + );
41 + register_rest_route( 'ultp', 'common', array(
42 + 'methods' => \WP_REST_Server::READABLE,
43 + 'args' => array('wpnonce' => []),
44 + 'callback' => array($this,'ultp_route_common_data'),
45 + 'permission_callback' => '__return_true'
46 + )
47 + );
48 + register_rest_route( 'ultp', 'specific_taxonomy', array(
49 + 'methods' => \WP_REST_Server::READABLE,
50 + 'args' => array('taxType' => [], 'taxSlug' => [], 'taxValue' => [], 'queryNumber' => [], 'wpnonce' => []),
51 + 'callback' => array($this,'ultp_route_taxonomy_info_data'),
52 + 'permission_callback' => '__return_true'
53 + )
54 + );
55 + register_rest_route(
80 56 'ultp/v1',
81 57 '/search/',
82 58 array(
83 59 array(
84 - 'methods' => 'POST',
85 - 'callback' => array( $this, 'search_settings_action' ),
60 + 'methods' => 'POST',
61 + 'callback' => array($this, 'search_settings_action'),
86 62 'permission_callback' => function () {
87 - return current_user_can( 'edit_others_posts' );
63 + return current_user_can('edit_posts');
88 64 },
89 - 'args' => array(),
90 - ),
65 + 'args' => array()
66 + )
91 67 )
92 68 );
93 - register_rest_route(
94 - 'ultp/v2',
95 - '/premade_wishlist_save/',
96 - array(
97 - array(
98 - 'methods' => 'POST',
99 - 'callback' => array( $this, 'premade_wishlist_save' ),
100 - 'permission_callback' => function () {
101 - return current_user_can( 'edit_others_posts' );
102 - },
103 - 'args' => array(),
104 - ),
105 - )
106 - );
107 - register_rest_route(
108 - 'ultp',
109 - '/ultp_search_data/',
110 - array(
111 - array(
112 - 'methods' => 'POST',
113 - 'callback' => array( $this, 'ultp_search_result' ),
114 - 'permission_callback' => '__return_true',
115 - ),
116 - )
117 - );
118 - register_rest_route(
119 - 'ultp/v2',
120 - '/custom_tax/',
121 - array(
122 - array(
123 - 'methods' => 'POST',
124 - 'callback' => array( $this, 'custom_tax_callback' ),
125 - 'permission_callback' => function () {
126 - return current_user_can( 'manage_options' );
127 - },
128 - 'args' => array(),
129 - ),
130 - )
131 - );
132 - register_rest_route(
133 - 'ultp/v2',
134 - '/init_site_dark_logo/',
135 - array(
136 - array(
137 - 'methods' => 'POST',
138 - 'callback' => array( $this, 'init_site_dark_logo_callback' ),
139 - 'permission_callback' => function () {
140 - return current_user_can( 'edit_others_posts' );
141 - },
142 - 'args' => array(),
143 - ),
144 - )
145 - );
146 - register_rest_route(
147 - 'ultp/v2',
148 - '/get_ultp_image_size/',
149 - array(
150 - array(
151 - 'methods' => 'POST',
152 - 'callback' => array( $this, 'get_custom_image_size' ),
153 - 'permission_callback' => function () {
154 - return current_user_can( 'edit_posts' );
155 - },
156 - 'args' => array(),
157 - ),
158 - )
159 - );
160 - }
69 + }
161 70
162 - /**
163 - * Save and get premade_wishlist_save
164 - *
165 - * Handle REST API request.
166 - *
167 - * @since 4.0.0
168 - * @param ARRAY $server $request The REST request object.
169 - * @return array The response data.
170 - */
171 - public function premade_wishlist_save( $server ) {
172 - $post = $server->get_params();
173 - $id = isset( $post['id'] ) ? ultimate_post()->ultp_rest_sanitize_params( $post['id'] ) : '';
174 - $action = isset( $post['action'] ) ? ultimate_post()->ultp_rest_sanitize_params( $post['action'] ) : '';
175 - $wishListArr = get_option( 'ultp_premade_wishlist', array() );
176 - $request_type = isset( $post['type'] ) ? ultimate_post()->ultp_rest_sanitize_params( $post['type'] ) : '';
177 -
178 - if ( $id && $request_type != 'fetchData' ) {
179 - if ( $action == 'remove' ) {
180 - $index = array_search( $id, $wishListArr );
181 - if ( $index !== false ) {
182 - unset( $wishListArr[ $index ] );
183 - }
184 - } elseif ( ! in_array( $id, $wishListArr ) ) {
185 - array_push( $wishListArr, $id );
186 - }
187 - update_option( 'ultp_premade_wishlist', $wishListArr );
188 - }
189 - return rest_ensure_response(
190 - array(
191 - 'success' => true,
192 - 'message' => $action == 'remove' ? __( 'Item has been removed from wishlist.', 'ultimate-post' ) : __( 'Item added to wishlist.', 'ultimate-post' ),
193 - 'wishListArr' => wp_json_encode( $wishListArr ),
194 - )
195 - );
196 - }
197 -
198 -
199 -
200 - /**
201 - * Search_settings_action
202 - *
203 - * @param mixed $server .
204 - * @return array
205 - */
206 - public function search_settings_action( $server ) {
71 + public function search_settings_action($server) {
207 72 global $wpdb;
208 - $post = $server->get_params();
209 - $request_type = isset( $post['type'] ) ? ultimate_post()->ultp_rest_sanitize_params( $post['type'] ) : '';
210 - $condition_type = isset( $post['condition'] ) ? ultimate_post()->ultp_rest_sanitize_params( $post['condition'] ) : '';
211 - $term_type = isset( $post['term'] ) ? ultimate_post()->ultp_rest_sanitize_params( $post['term'] ) : '';
212 - // get post type
213 - $get_multiple_post_type = isset( $post['postType'] ) ? ultimate_post()->ultp_rest_sanitize_params( $post['postType'] ) : array();
214 - $multiple_post_type = is_array( $get_multiple_post_type ) ? $get_multiple_post_type : json_decode( $get_multiple_post_type, true );
215 - $split = explode( '###', $condition_type );
216 - $post_type_condition = array();
217 - if ( $split[0] == 'customPostType' && count( $multiple_post_type ) ) {
218 - $post_type_condition = get_object_taxonomies( $multiple_post_type );
219 - }
73 + $post = $server->get_params();
220 74
221 - switch ( $request_type ) {
222 - case 'posts':
223 - case 'allpost':
224 - case 'postExclude':
225 - $post_type = array( 'post' );
226 - if ( $request_type == 'allpost' || $condition_type == 'customPostType' ) {
227 - $post_type = array_keys( ultimate_post()->get_post_type() );
228 - } elseif ( $request_type == 'postExclude' && $condition_type != 'customPostType' ) {
229 - $post_type = array( $condition_type );
230 - }
231 - $args = array(
232 - 'post_type' => $post_type,
233 - 'post_status' => 'publish',
234 - 'posts_per_page' => 10,
235 - );
236 - if ( is_numeric( $term_type ) ) {
237 - $args['p'] = $term_type;
238 - } else {
239 - $args['s'] = $term_type;
240 - }
75 + switch ($post['type']) {
76 + case 'posts':
77 + case 'allpost':
78 + case 'postExclude':
79 + $post_type = array('post');
80 + if ($post['type'] == 'allpost') {
81 + $post_type = array_keys(ultimate_post()->get_post_type());
82 + } else if ($post['type'] == 'postExclude') {
83 + $post_type = array($post['condition']);
84 + }
85 + $args = array(
86 + 'post_type' => $post_type,
87 + 'post_status' => 'publish',
88 + 's' => $post['term'],
89 + 'posts_per_page' => 10,
90 + );
91 + $post_results = new \WP_Query($args);
92 + $data = [];
93 + if (!empty($post_results)) {
94 + while ( $post_results->have_posts() ) {
95 + $post_results->the_post();
96 + $id = get_the_ID();
97 + $title = get_the_title();
98 + $data[] = array('value'=>$id, 'title'=>($title?$title:('##'.$id)));
99 + }
100 + wp_reset_postdata();
101 + }
102 + return ['success' => true, 'data' => $data];
103 + break;
241 104
242 - $post_results = new \WP_Query( $args );
243 - $data = array();
244 - if ( ! empty( $post_results ) ) {
245 - while ( $post_results->have_posts() ) {
246 - $post_results->the_post();
247 - $id = get_the_ID();
248 - $title = html_entity_decode( get_the_title() );
249 - $data[] = array(
250 - 'value' => $id,
251 - 'title' => ( $title ? '[ID: ' . $id . '] ' . $title : ( '[ID: ' . $id . ']' ) ),
252 - );
253 - }
254 - wp_reset_postdata();
255 - }
256 - return array(
257 - 'success' => true,
258 - 'data' => $data,
259 - );
260 - break;
261 -
262 - case 'author':
263 - $term = '%' . $wpdb->esc_like( $term_type ) . '%';
264 - $post_results = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
265 - $wpdb->prepare(
266 - "SELECT ID, display_name
105 + case 'author':
106 + $term = '%'. $wpdb->esc_like( $post['term'] ) .'%';
107 + $post_results = $wpdb->get_results(
108 + $wpdb->prepare(
109 + "SELECT ID, display_name
267 110 FROM $wpdb->users
268 - WHERE user_login LIKE %s OR ID LIKE %s OR user_nicename LIKE %s OR user_email LIKE %s OR display_name LIKE %s LIMIT 10",
269 - $term,
270 - $term,
271 - $term,
272 - $term,
273 - $term
274 - )
275 - );
276 - $data = array();
277 - if ( ! empty( $post_results ) ) {
278 - foreach ( $post_results as $key => $val ) {
279 - $data[] = array(
280 - 'value' => $val->ID,
281 - 'title' => '[ID: ' . $val->ID . '] ' . $val->display_name,
282 - );
283 - }
284 - }
285 - return array(
286 - 'success' => true,
287 - 'data' => $data,
288 - );
289 - break;
111 + WHERE user_login LIKE '%s' OR ID LIKE '%s' OR user_nicename LIKE '%s' OR user_email LIKE '%s' OR display_name LIKE '%s' LIMIT 10", $term, $term, $term, $term, $term
112 + )
113 + );
114 + $data = [];
115 + if (!empty($post_results)) {
116 + foreach ($post_results as $key => $val) {
117 + $data[] = array('value'=>$val->ID, 'title'=>$val->display_name);
118 + }
119 + }
120 + return ['success' => true, 'data' => $data];
121 + break;
290 122
291 - case 'taxvalue':
292 - $split = explode( '###', $condition_type );
293 - $condition = $split[1] != 'multiTaxonomy' ? array( $split[1] ) : get_object_taxonomies( $split[0] );
123 + case 'taxvalue':
124 + $split = explode('###', $post['condition']);
125 + $condition = $split[1] != 'multiTaxonomy' ? array($split[1]) : get_object_taxonomies($split[0]);
126 + $args = array(
127 + 'taxonomy' => $condition,
128 + 'fields' => 'all',
129 + 'orderby' => 'id',
130 + 'order' => 'ASC',
131 + 'name__like'=> $post['term']
132 + );
133 + $post_results = get_terms( $args );
134 + $data = [];
135 + if (!empty($post_results)) {
136 + foreach ($post_results as $key => $val) {
137 + if ($split[1] == 'multiTaxonomy') {
138 + $data[] = array('value'=>$val->taxonomy.'###'.$val->slug, 'title'=> $val->taxonomy.': '.$val->name);
139 + } else {
140 + $data[] = array('value'=>$val->slug, 'title'=>$val->name);
141 + }
142 + }
143 + }
144 + return ['success' => true, 'data' => $data];
145 + break;
294 146
295 - if ( $post_type_condition && count( $post_type_condition ) ) {
296 - $condition = $post_type_condition;
297 - }
147 + case 'taxExclude':
148 + $condition = get_object_taxonomies($post['condition']);
149 + $args = array(
150 + 'taxonomy' => $condition,
151 + 'fields' => 'all',
152 + 'orderby' => 'id',
153 + 'order' => 'ASC',
154 + 'name__like'=> $post['term']
155 + );
156 + $post_results = get_terms( $args );
157 + $data = [];
158 + if (!empty($post_results)) {
159 + foreach ($post_results as $key => $val) {
160 + $data[] = array('value'=>$val->taxonomy.'###'.$val->slug, 'title'=> $val->taxonomy.': '.$val->name);
161 + }
162 + }
163 + return ['success' => true, 'data' => $data];
164 + break;
165 +
298 166
299 - $args = array(
300 - 'taxonomy' => $condition,
301 - 'fields' => 'all',
302 - 'orderby' => 'id',
303 - 'order' => 'ASC',
304 - 'name__like' => $term_type,
305 - );
306 - if ( is_numeric( $term_type ) ) {
307 - unset( $args['name__like'] );
308 - $args['include'] = array( $term_type );
309 - }
310 -
311 - $post_results = get_terms( $args );
312 - $data = array();
313 - if ( ! empty( $post_results ) ) {
314 - foreach ( $post_results as $key => $val ) {
315 - if ( $split[1] == 'multiTaxonomy' ) {
316 - $data[] = array(
317 - 'value' => $val->taxonomy . '###' . $val->slug,
318 - 'title' => '[ID: ' . $val->term_id . '] ' . $val->taxonomy . ': ' . $val->name,
319 - );
320 - } else {
321 - $data[] = array(
322 - 'value' => urldecode( $val->slug ),
323 - 'title' => '[ID: ' . $val->term_id . '] ' . $val->name,
324 - 'live_title' => $val->name,
325 - );
326 - }
327 - }
328 - }
329 - return array(
330 - 'success' => true,
331 - 'data' => $data,
332 - );
333 - break;
334 -
335 - case 'taxExclude':
336 - $condition = get_object_taxonomies( $condition_type );
337 - if ( $post_type_condition && count( $post_type_condition ) ) {
338 - $condition = $post_type_condition;
339 - }
340 - $args = array(
341 - 'taxonomy' => $condition,
342 - 'fields' => 'all',
343 - 'orderby' => 'id',
344 - 'order' => 'ASC',
345 - 'name__like' => $term_type,
346 - );
347 - if ( is_numeric( $term_type ) ) {
348 - unset( $args['name__like'] );
349 - $args['include'] = array( $term_type );
350 - }
351 - $post_results = get_terms( $args );
352 - $data = array();
353 - if ( ! empty( $post_results ) ) {
354 - foreach ( $post_results as $key => $val ) {
355 - $data[] = array(
356 - 'value' => $val->taxonomy . '###' . $val->slug,
357 - 'title' => '[ID: ' . $val->term_id . '] ' . $val->taxonomy . ': ' . $val->name,
358 - );
359 - }
360 - }
361 - return array(
362 - 'success' => true,
363 - 'data' => $data,
364 - );
365 - break;
366 - // allPostType
367 - case 'allPostType':
368 - $all_types = array_values( get_post_types( array( 'public' => true ), 'names' ) );
369 - $postType = array();
370 - foreach ( $all_types as $type ) {
371 - $postType[] = array(
372 - 'title' => $type,
373 - 'value' => $type,
374 - );
375 - }
376 -
377 - return array(
378 - 'success' => true,
379 - 'data' => $postType,
380 - );
381 - default:
382 - return array(
383 - 'success' => true,
384 - 'data' => array(
385 - array(
386 - 'value' => '',
387 - 'title' => '- Select -',
388 - ),
389 - ),
390 - );
391 - break;
392 - }
167 + default:
168 + return ['success' => true, 'data' => [['value'=>'', 'title'=>'- Select -']]];
169 + break;
170 + }
393 171 }
394 172
395 - /**
173 + /**
396 174 * Post Data Response of REST API
397 - *
398 - * @since v.1.0.0
399 - * @param MIXED | $prams (ARRAY), Local (BOOLEAN).
175 + *
176 + * @since v.1.0.0
177 + * @param MIXED | Pram (ARRAY), Local (BOOLEAN)
400 178 * @return ARRAY | Response Image Size as Array
401 179 */
402 - public function ultp_route_post_data( $prams ) {
403 - $prams = $prams->get_params();
404 - if ( ! ( isset( $prams['wpnonce'] ) && wp_verify_nonce( sanitize_key( wp_unslash( $prams['wpnonce'] ) ), 'ultp-nonce' ) ) ) {
405 - die();
406 - }
407 - $data = array();
408 - $loop = new \WP_Query( ultimate_post()->get_query( ultimate_post()->ultp_rest_sanitize_params( $prams ) ) );
409 - $max_tax = isset( $prams['maxTaxonomy'] ) && $prams['maxTaxonomy'] ? ( ultimate_post()->ultp_rest_sanitize_params( $prams['maxTaxonomy'] ) == '0' ? 0 : ultimate_post()->ultp_rest_sanitize_params( $prams['maxTaxonomy'] ) ) : 30;
180 + public function ultp_route_post_data($prams,$local=false) {
181 + if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
182 + return ;
183 + }
410 184
411 - if ( $loop->have_posts() ) {
412 - while ( $loop->have_posts() ) {
413 - $loop->the_post();
414 - $var = array();
415 - $post_id = get_the_ID();
416 - $user_id = get_the_author_meta( 'ID' );
417 - $content_data = get_the_content();
418 - $var['ID'] = $post_id;
419 - $var['title'] = get_the_title();
420 - $var['permalink'] = get_permalink();
421 - $var['seo_meta'] = ultimate_post()->get_excerpt( $post_id, 1 );
422 - $var['excerpt'] = wp_strip_all_tags( get_the_excerpt() );
423 - $var['excerpt_full'] = wp_strip_all_tags( get_the_excerpt() );
424 - $var['time'] = (int) get_the_date( 'U' ) * 1000;
425 - $var['timeModified'] = (int) get_the_modified_date( 'U' ) * 1000;
426 - $var['post_time'] = human_time_diff( get_the_time( 'U' ), current_time( 'U' ) );
427 - $var['view'] = get_post_meta( get_the_ID(), '__post_views_count', true );
428 - $var['comments'] = get_comments_number();
429 - $var['author_link'] = get_author_posts_url( $user_id );
430 - $var['avatar_url'] = get_avatar_url( $user_id );
431 - $var['display_name'] = get_the_author_meta( 'display_name' );
432 - $var['reading_time'] = ceil( strlen( $content_data ) / 1200 );
433 - $var['acf'] = null;
185 + $prams = $prams->get_params();
186 +
187 + $data = [];
188 + $loop = new \WP_Query( ultimate_post()->get_query($prams) );
189 +
190 + if($loop->have_posts()){
191 + while($loop->have_posts()) {
192 + $loop->the_post();
193 + $var = array();
194 + $post_id = get_the_ID();
195 + $user_id = get_the_author_meta('ID');
196 + $content_data = get_the_content();
197 + $var['ID'] = $post_id;
198 + $var['title'] = get_the_title();
199 + $var['permalink'] = get_permalink();
200 + $var['seo_meta'] = ultimate_post()->get_excerpt($post_id, 1);
201 + $var['excerpt'] = strip_tags($content_data);
202 + $var['excerpt_full']= strip_tags(get_the_excerpt());
203 + $var['time'] = (int)get_the_date('U')*1000;
204 + $var['timeModified']= (int)get_the_modified_date('U')*1000;
205 + $var['post_time'] = human_time_diff(get_the_time('U'),current_time('U'));
206 + $var['view'] = get_post_meta(get_the_ID(),'__post_views_count', true);
207 + $var['comments'] = get_comments_number();
208 + $var['author_link'] = get_author_posts_url($user_id);
209 + $var['avatar_url'] = get_avatar_url($user_id);
210 + $var['display_name']= get_the_author_meta('display_name');
211 + $var['reading_time']= ceil(strlen($content_data)/1200);
212 +
213 + // image
214 + if( has_post_thumbnail() ){
215 + $thumb_id = get_post_thumbnail_id($post_id);
216 + $image_sizes = ultimate_post()->get_image_size();
217 + $image_src = array();
218 + foreach ($image_sizes as $key => $value) {
219 + $image_src[$key] = wp_get_attachment_image_src($thumb_id, $key, false)[0];
220 + }
221 + $var['image'] = $image_src;
222 + }
434 223
435 - if ( function_exists( 'get_field_objects' ) ) {
436 - $var['acf'] = get_field_objects();
437 - }
224 + // tag
225 + $tag = get_the_terms($post_id, (isset($prams['tag'])?esc_attr($prams['tag']):'post_tag'));
226 + if(!empty($tag)){
227 + $v = array();
228 + foreach ($tag as $val) {
229 + $v[] = array('slug' => $val->slug, 'name' => $val->name, 'url' => get_term_link($val->term_id));
230 + }
231 + $var['tag'] = $v;
232 + }
438 233
439 - $post_video = get_post_meta( $post_id, '__builder_feature_video', true );
440 - // Video.
441 - if ( $post_video ) {
442 - $var['has_video'] = ultimate_post()->get_youtube_id( $post_video );
443 - }
444 - // image.
445 - $image_sizes = ultimate_post()->get_image_size();
446 - $image_src = array();
447 - if ( has_post_thumbnail() ) {
448 - $thumb_id = get_post_thumbnail_id( $post_id );
449 - foreach ( $image_sizes as $key => $value ) {
450 - $image = wp_get_attachment_image_src( $thumb_id, $key, false );
451 - if ( $image && is_array( $image ) ) {
452 - $image_src[ $key ] = $image[0];
453 - }
454 - }
455 - $var['image'] = $image_src;
456 - } elseif ( isset( $prams['fallbackImg']['id'] ) ) {
457 - foreach ( $image_sizes as $key => $value ) {
458 - $image_src[ $key ] = wp_get_attachment_image_src( esc_attr( $prams['fallbackImg']['id'] ), $key, false )[0];
459 - }
460 - $var['image'] = $image_src;
461 - $var['is_fallback'] = true;
462 - }
234 + // cat
235 + $cat = get_the_terms($post_id, (isset($prams['cat'])?esc_attr($prams['cat']):'category'));
236 + if(!empty($cat)){
237 + $v = array();
238 + foreach ($cat as $val) {
239 + $v[] = array('slug' => $val->slug, 'name' => $val->name, 'url' => get_term_link($val->term_id), 'color' => get_term_meta($val->term_id, 'ultp_category_color', true));
240 + }
241 + $var['category'] = $v;
242 + }
243 + $data[] = $var;
244 + }
245 + wp_reset_postdata();
246 + }
463 247
464 - // tag.
465 - $tag = get_the_terms( $post_id, ( isset( $prams['tag'] ) ? esc_attr( $prams['tag'] ) : 'post_tag' ) );
466 - if ( ! empty( $tag ) ) {
467 - $v = array();
468 - foreach ( $tag as $k => $val ) {
469 - if ( $k >= $max_tax ) {
470 - break; }
471 - $v[] = array(
472 - 'slug' => $val->slug,
473 - 'name' => $val->name,
474 - 'url' => get_term_link( $val->term_id ),
475 - );
476 - }
477 - $var['tag'] = $v;
478 - }
248 + return rest_ensure_response( $data );
249 + }
479 250
480 - // Taxonomy.
481 - $cat = get_the_terms( $post_id, ( isset( $prams['taxonomy'] ) ? esc_attr( $prams['taxonomy'] ) : 'category' ) );
482 251
483 - if ( ! empty( $cat ) ) {
484 - $v = array();
485 - foreach ( $cat as $k => $val ) {
486 - if ( $k >= $max_tax ) {
487 - break; }
488 - $v[] = array(
489 - 'slug' => $val->slug,
490 - 'name' => $val->name,
491 - 'url' => get_term_link( $val->term_id ),
492 - 'color' => get_term_meta( $val->term_id, 'ultp_category_color', true ),
493 - );
494 - }
495 - $var['category'] = $v;
496 - }
497 - $data[] = $var;
498 - }
499 - wp_reset_postdata();
500 - }
501 - return rest_ensure_response( $data );
502 - }
503 -
504 -
505 - /**
506 - * STaxonomy Data Response of REST API
507 - *
508 - * @since v.1.0.0
509 - * @param ARRAY | $prams (ARRAY).
252 + /**
253 + * Taxonomy Data Response of REST API
254 + *
255 + * @since v.1.0.0
256 + * @param ARRAY | Parameter (ARRAY)
510 257 * @return ARRAY | Response Taxonomy List as Array
511 258 */
512 - public function ultp_route_common_data( $prams ) {
513 - if ( ! ( isset( $_REQUEST['wpnonce'] ) && wp_verify_nonce( sanitize_key( wp_unslash( $_REQUEST['wpnonce'] ) ), 'ultp-nonce' ) ) ) {
514 - return rest_ensure_response( array() );
515 - }
259 + public function ultp_route_common_data($prams) {
260 + if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce')){
261 + return rest_ensure_response([]);
262 + }
263 +
264 + $all_post_type = ultimate_post()->get_post_type();
265 + $data = array();
266 + foreach ($all_post_type as $post_type_slug => $post_type ) {
267 + $data_term = array();
268 + $taxonomies = get_object_taxonomies($post_type_slug);
269 + foreach ($taxonomies as $key => $taxonomy_slug) {
270 + $taxonomy_value = get_terms(array(
271 + 'taxonomy' => $taxonomy_slug,
272 + 'hide_empty' => false
273 + ));
274 + if (!is_wp_error($taxonomy_value)) {
275 + $data_tax = array();
276 + foreach ($taxonomy_value as $k => $taxonomy) {
277 + $data_tax[urldecode_deep($taxonomy->slug)] = $taxonomy->name;
278 + }
279 + if (count($data_tax) > 0) {
280 + $data_term[$taxonomy_slug] = $data_tax;
281 + }
282 + }
283 + }
284 + $data[$post_type_slug] = $data_term;
285 + }
286 + // Global Customizer
287 + $global = get_option('ultp_global', []);
288 + // Image Size
289 + $image_sizes = ultimate_post()->get_image_size();
516 290
517 - $all_post_type = ultimate_post()->get_post_type();
518 - $data = array();
519 - foreach ( $all_post_type as $post_type_slug => $post_type ) {
520 - $data_term = array();
521 - $taxonomies = get_object_taxonomies( $post_type_slug );
522 - foreach ( $taxonomies as $key => $taxonomy_slug ) {
523 - $taxonomy_value = get_terms(
524 - array(
525 - 'taxonomy' => $taxonomy_slug,
526 - 'hide_empty' => false,
527 - )
528 - );
529 - if ( ! is_wp_error( $taxonomy_value ) ) {
530 - $data_tax = array();
531 - foreach ( $taxonomy_value as $k => $taxonomy ) {
532 - $data_tax[ urldecode_deep( $taxonomy->slug ) ] = $taxonomy->name;
533 - }
534 - if ( count( $data_tax ) > 0 ) {
535 - $data_term[ $taxonomy_slug ] = $data_tax;
536 - }
537 - }
538 - }
539 - $data[ $post_type_slug ] = $data_term;
540 - }
541 - // Global Customizer.
542 - $global = get_option( 'postx_global', array() );
543 - // Image Size.
544 - $image_sizes = ultimate_post()->get_image_size();
291 + return rest_ensure_response(['taxonomy' => $data, 'global' => $global, 'image' => json_encode($image_sizes), 'posttype' => json_encode($all_post_type)]);
292 + }
545 293
546 - return rest_ensure_response(
547 - array(
548 - 'taxonomy' => $data,
549 - 'global' => $global,
550 - 'image' => wp_json_encode( $image_sizes ),
551 - 'posttype' => wp_json_encode( $all_post_type ),
552 - )
553 - );
554 - }
555 -
556 - /**
294 + /**
557 295 * Specific Taxonomy Data Response of REST API
558 - *
559 - * @since v.1.0.0
560 - * @param ARRAY | $prams .
296 + *
297 + * @since v.1.0.0
298 + * @param ARRAY | Parameter (ARRAY)
561 299 * @return ARRAY | Response Taxonomy List as Array
562 300 */
563 - public function ultp_route_taxonomy_info_data( $prams ) {
564 - $prams = $prams->get_params();
565 - if ( ! ( isset( $prams['wpnonce'] ) && wp_verify_nonce( sanitize_key( wp_unslash( $prams['wpnonce'] ) ), 'ultp-nonce' ) ) ) {
566 - return rest_ensure_response( array() );
567 - }
568 - $taxValue = isset( $prams['taxValue'] ) ? ultimate_post()->ultp_rest_sanitize_params( $prams['taxValue'] ) : '';
569 - $queryNumber = isset( $prams['queryNumber'] ) ? ultimate_post()->ultp_rest_sanitize_params( $prams['queryNumber'] ) : '';
570 - $taxType = isset( $prams['taxType'] ) ? ultimate_post()->ultp_rest_sanitize_params( $prams['taxType'] ) : '';
571 - $taxSlug = isset( $prams['taxSlug'] ) ? ultimate_post()->ultp_rest_sanitize_params( $prams['taxSlug'] ) : '';
572 - $archiveBuilder = isset( $prams['archiveBuilder'] ) ? ultimate_post()->ultp_rest_sanitize_params( $prams['archiveBuilder'] ) : '';
301 + public function ultp_route_taxonomy_info_data($prams) {
302 + if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce')) {
303 + return rest_ensure_response([]);
304 + }
573 305
574 - return rest_ensure_response( ultimate_post()->get_category_data( json_decode( $taxValue ), $queryNumber, $taxType, $taxSlug, $archiveBuilder ) );
575 - }
576 -
577 - /**
578 - * Get Taxonomies for Custom Post Type
579 - *
580 - * @since v.3.2.8
581 - * @param array $prams .
582 - * @return array
583 - */
584 - public function custom_tax_callback( $prams ) {
585 -
586 - $post_types = isset( $prams['postTypes'] ) ? ultimate_post()->ultp_rest_sanitize_params( $prams['postTypes'] ) : array();
587 -
588 - if ( is_string( $post_types ) ) {
589 - $post_types = json_decode( $post_types, true );
590 - if ( ! is_array( $post_types ) ) {
591 - $post_types = array();
592 - }
593 - }
594 -
595 - $data = array(
596 - array(
597 - 'id' => '_all',
598 - 'name' => __( 'All', 'ultimate-post' ),
599 - ),
600 - );
601 -
602 - foreach ( $post_types as $post_type ) {
603 - $taxonomies = get_object_taxonomies( $post_type );
604 - foreach ( $taxonomies as $taxonomy ) {
605 - if ( 'category' !== $taxonomy && 'post_tag' !== $taxonomy ) {
606 - $terms = get_terms(
607 - array(
608 - 'taxonomy' => $taxonomy,
609 - 'hide_empty' => false,
610 - )
611 - );
612 - foreach ( $terms as $term ) {
613 - $data[] = array(
614 - 'id' => $term->slug,
615 - 'name' => $term->name,
616 - );
617 - }
618 - }
619 - }
620 - }
621 -
622 - return rest_ensure_response( $data );
623 - }
624 -
625 - /**
626 - * Search Block Data Showing
627 - *
628 - * @since v.2.9.9
629 - * @param STRING | $server .
630 - * @return ARRAY | Inserted Post Url
631 - */
632 - public function ultp_search_result( $server ) {
633 - $post = $server->get_params();
634 - $searchText = isset( $post['searchText'] ) ? ultimate_post()->ultp_rest_sanitize_params( $post['searchText'] ) : '';
635 - $paged = isset( $post['paged'] ) ? ultimate_post()->ultp_rest_sanitize_params( $post['paged'] ) : '';
636 - $postPerPage = isset( $post['postPerPage'] ) ? ultimate_post()->ultp_rest_sanitize_params( $post['postPerPage'] ) : '';
637 - $query_args = array(
638 - 's' => $searchText,
639 - 'paged' => $paged,
640 - 'compare' => 'LIKE',
641 - 'orderby' => 'relevance',
642 - 'posts_per_page' => $postPerPage,
643 - );
644 - if ( isset( $post['exclude'] ) && is_array( $post['exclude'] ) && count( $post['exclude'] ) > 0 ) {
645 - $post['exclude'] = ultimate_post()->ultp_rest_sanitize_params( $post['exclude'] );
646 - $post_exclude = array();
647 - foreach ( $post['exclude'] as $data ) {
648 - $post_exclude[ $data['title'] ] = $data['title'];
649 - }
650 - $all_types = get_post_types( array( 'public' => true ), 'names' );
651 - $post_type = array_diff_key( $all_types, $post_exclude );
652 - $query_args['post_type'] = $post_type;
653 - }
654 - $output = '';
655 - $query_result = new \WP_Query( $query_args );
656 -
657 - if ( $query_result->have_posts() ) {
658 - while ( $query_result->have_posts() ) {
659 - $query_result->the_post();
660 - $post_id = get_the_ID();
661 - $title = get_the_title();
662 -
663 - $output .= '<div class="ultp-search-result__item">';
664 - if ( $post['image'] == 1 && has_post_thumbnail() ) {
665 - $thumb_id = get_post_thumbnail_id( $post_id );
666 - $output .= '<img class="ultp-searchresult-image" src=' . wp_get_attachment_image_src( $thumb_id, 'thumbnail', false )[0] . ' alt="' . $title . '"/>';
667 - }
668 - $output .= '<div class="ultp-searchresult-content">';
669 - $output .= '<div class="ultp-rescontent-meta">';
670 - // Category.
671 - $post_cat = get_the_terms( $post_id, 'category' );
672 - if ( $post['category'] == 1 && $post_cat && count( $post_cat ) ) {
673 - $output .= '<div class="ultp-searchresult-category">';
674 - foreach ( $post_cat as $cat ) {
675 - $output .= '<a href="' . get_term_link( $cat->term_id ) . '">' . $cat->name . '</a>';
676 - }
677 - $output .= '</div>';
678 - }
679 - // Author.
680 - if ( $post['author'] == 1 ) {
681 - $user_id = get_the_author_meta( 'ID' );
682 - $output .= '<a href="' . get_author_posts_url( $user_id ) . '" class="ultp-searchresult-author">' . get_the_author_meta( 'display_name' ) . '</a>';
683 - }
684 - // Date.
685 - if ( $post['date'] == 1 ) {
686 - $output .= '<div class="ultp-searchresult-publishdate">' . get_the_date( 'F j, Y' ) . '</div>';
687 - }
688 - $output .= '</div>';
689 - $output .= '<a href="' . get_permalink() . '" class="ultp-searchresult-title">' . $title . '</a>';
690 - if ( $post['excerpt'] == 1 ) {
691 - $output .= '<div class="ultp-searchresult-excerpt">' . wp_trim_words( get_the_excerpt(), isset( $post['excerptLimit'] ) ? ultimate_post()->ultp_rest_sanitize_params( $post['excerptLimit'] ) : 55 ) . '</div>';
692 - }
693 - $output .= '</div>';
694 - $output .= '</div>';
695 - }
696 - }
697 -
698 - return array(
699 - 'post_data' => $output,
700 - 'post_count' => $query_result->found_posts,
701 - );
702 - }
703 -
704 - /**
705 - * PostX Site Dark Logo Init
706 - *
707 - * @since v.3.1.9
708 - * @param ARRAY | $server .
709 - * @return BOOOLEAN | Inserted Post Url
710 - */
711 - public function init_site_dark_logo_callback( $server ) {
712 - $logo_data = $server->get_params();
713 - $success = true;
714 - if ( isset( $logo_data['logo']['url'] ) ) {
715 - update_option( 'ultp_site_dark_logo', $logo_data['logo']['url'] );
716 - } else {
717 - $success = false;
718 - }
719 - return rest_ensure_response(
720 - array(
721 - 'success' => $success,
722 - )
723 - );
724 - }
725 -
726 -
727 - /**
728 - * Getting Image Size
729 - *
730 - * @since v.4.0.1
731 - * @param ARRAY | $server (number) .
732 - * @return ARRAY | Image Size List as Array
733 - */
734 - public function get_custom_image_size( $server ) {
735 - $img = $server->get_params();
736 - $image_src = array();
737 - $image_sizes = ultimate_post()->get_image_size();
738 - foreach ( $image_sizes as $key => $value ) {
739 - $image_src[ $key ] = wp_get_attachment_image_src( $img['id'], $key, false )[0];
740 - }
741 - return rest_ensure_response(
742 - array(
743 - 'success' => true,
744 - 'size' => $image_src,
745 - 'id' => $img,
746 - )
747 - );
748 - }
749 -}
306 + return rest_ensure_response( ultimate_post()->get_category_data(json_decode($prams['taxValue']), $prams['queryNumber'], $prams['taxType'], $prams['taxSlug']) );
307 + }
308 +}