PluginProbe
Post Grid Gutenberg Blocks – PostX / 1.2.2
Post Grid Gutenberg Blocks – PostX v1.2.2
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 +168 -728 5.0.201.2.2 View file →
@@ -1,749 +1,189 @@
1 1 <?php
2 -/**
3 - * REST API Action.
4 - *
5 - * @package ULTP\REST_API
6 - * @since v.1.0.0
7 - */
2 +defined('ABSPATH') || exit;
8 3
9 -namespace ULTP;
10 4
11 -defined( 'ABSPATH' ) || exit;
5 +// ------------- Custom Endpoint Start ----------
12 6
13 -/**
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
20 - */
21 -class REST_API {
7 +add_action( 'rest_api_init', 'ultp_register_route' );
8 +function ultp_register_route() {
9 + register_rest_route( 'ultp', 'posts', array(
10 + 'methods' => WP_REST_Server::READABLE,
11 + 'args' => array('post_type', 'taxonomy', 'include', 'exclude', 'order', 'orderby', 'count', 'size', 'tag', 'cat', 'meta_key', 'wpnonce'),
12 + 'callback' => 'ultp_route_post_data',
13 + )
14 + );
15 + register_rest_route( 'ultp', 'taxonomy', array(
16 + 'methods' => WP_REST_Server::READABLE,
17 + 'args' => array('taxonomy', 'wpnonce'),
18 + 'callback' => 'ultp_route_taxonomy_data',
19 + )
20 + );
21 + register_rest_route( 'ultp', 'imagesize', array(
22 + 'methods' => WP_REST_Server::READABLE,
23 + 'args' => array('taxonomy', 'wpnonce'),
24 + 'callback' => 'ultp_route_imagesize_data',
25 + )
26 + );
27 + register_rest_route( 'ultp', 'posttype', array(
28 + 'methods' => WP_REST_Server::READABLE,
29 + 'args' => array('wpnonce'),
30 + 'callback' => 'ultp_route_posttype_data',
31 + )
32 + );
33 + register_rest_route( 'ultp', 'tax_info', array(
34 + 'methods' => WP_REST_Server::READABLE,
35 + 'args' => array('taxonomy', 'wpnonce'),
36 + 'callback' => 'ultp_route_taxonomy_info_data',
37 + )
38 + );
39 +}
22 40
23 - /**
24 - * Setup class.
25 - *
26 - * @since v.1.0.0
27 - */
28 - public function __construct() {
29 - add_action( 'rest_api_init', array( $this, 'ultp_register_route' ) );
30 - }
41 +function ultp_route_posttype_data() {
42 + if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
43 + return ;
44 + }
45 +
46 + return ultimate_post()->get_post_type();
47 +}
31 48
32 - /**
33 - * REST API Action
34 - *
35 - * @since v.1.0.0
36 - * @return void
37 - */
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(
80 - 'ultp/v1',
81 - '/search/',
82 - array(
83 - array(
84 - 'methods' => 'POST',
85 - 'callback' => array( $this, 'search_settings_action' ),
86 - 'permission_callback' => function () {
87 - return current_user_can( 'edit_others_posts' );
88 - },
89 - 'args' => array(),
90 - ),
91 - )
92 - );
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 - }
49 +function ultp_route_imagesize_data() {
50 + if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
51 + return ;
52 + }
53 +
54 + return ultimate_post()->get_image_size();
55 +}
161 56
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'] ) : '';
57 +function ultp_route_post_data($prams,$local=false) {
58 + if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
59 + return ;
60 + }
177 61
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 - }
62 + // Query Builder
63 + $args = array(
64 + 'post_type' => 'post',
65 + 'orderby' => 'date',
66 + 'post_status' => 'publish',
67 + 'order' => 'DESC',
68 + );
197 69
70 + if(isset($prams['count'])){ $args['posts_per_page'] = esc_attr($prams['count']); }
71 + if(isset($prams['post_type'])){ $args['post_type'] = esc_attr( $prams['post_type'] ); }
198 72
73 + if(isset($prams['taxonomy'])){ // taxonomy slug__val__slug__val
74 + $tax_arr = array('relation' => 'OR');
75 + $tax = explode('__', esc_attr($prams['taxonomy']));
76 + if(!empty($tax)){
77 + for($i=0; $i < count($tax) ; $i++){
78 + if($i%2 == 0){
79 + $tax_arr[] = array('taxonomy'=>$tax[$i], 'field' => 'slug', 'terms' => array($tax[$i+1]));
80 + }
81 + }
82 + }
83 + if(!empty($tax_arr)){
84 + $args['tax_query'] = $tax_arr;
85 + }
86 + }
199 87
200 - /**
201 - * Search_settings_action
202 - *
203 - * @param mixed $server .
204 - * @return array
205 - */
206 - public function search_settings_action( $server ) {
207 - 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 - }
88 + if(isset($prams['include'])){ $args['post__in'] = explode('__', esc_attr($prams['include'])); }
89 + if(isset($prams['exclude'])){ $args['post__not_in'] = explode('__', esc_attr($prams['exclude'])); }
90 + if(isset($prams['orderby'])){ $args['orderby'] = esc_attr($prams['orderby']); }
91 + if(isset($prams['order'])){ $args['order'] = esc_attr($prams['order']); }
92 + if(isset($prams['offset'])){ $args['offset'] = esc_attr($prams['offset']); }
93 + if(isset($prams['paged'])){ $args['paged'] = esc_attr($prams['paged']); }
220 94
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 - }
95 + if(isset($prams['orderby']) && isset($prams['meta_key'])){
96 + if($prams['orderby'] == 'meta_value_num') {
97 + $args['meta_key'] = $prams['meta_key'];
98 + }
99 + }
100 +
101 + $data = [];
102 + $loop = new WP_Query($args);
103 +
104 + if($loop->have_posts()){
105 + while($loop->have_posts()) {
106 + $loop->the_post();
107 + $var = array();
108 + $post_id = get_the_ID();
109 + $user_id = get_the_author_meta('ID');
110 + $var['title'] = get_the_title();
111 + $var['permalink'] = get_permalink();
112 + $var['excerpt'] = strip_tags(get_the_content());
113 + $var['excerpt_full']= strip_tags(get_the_excerpt());
114 + $var['time'] = get_the_date();
115 + $var['post_time'] = human_time_diff(get_the_time('U'),current_time('U'));
116 + $var['view'] = get_post_meta(get_the_ID(),'__post_views_count', true);
117 + $var['comments'] = get_comments_number();
118 + $var['author_link'] = get_author_posts_url($user_id);
119 + $var['avatar_url'] = get_avatar_url($user_id);
120 + $var['display_name']= get_the_author_meta('display_name');
121 + $var['reading_time']= ceil(strlen(get_the_content())/1200).__(' min read', 'ultimate-post');
122 +
123 + // image
124 + if( has_post_thumbnail() ){
125 + $thumb_id = get_post_thumbnail_id($post_id);
126 + $image_sizes = ultimate_post()->get_image_size();
127 + $image_src = array();
128 + foreach ($image_sizes as $key => $value) {
129 + $image_src[$key] = wp_get_attachment_image_src($thumb_id, $key, false)[0];
130 + }
131 + $var['image'] = $image_src;
132 + }
241 133
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;
134 + // tag
135 + $tag = get_the_terms($post_id, (isset($prams['tag'])?esc_attr($prams['tag']):'post_tag'));
136 + if(!empty($tag)){
137 + $v = array();
138 + foreach ($tag as $val) {
139 + $v[] = array('slug' => $val->slug, 'name' => $val->name, 'url' => get_term_link($val->term_id));
140 + }
141 + $var['tag'] = $v;
142 + }
261 143
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
267 - 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;
144 + // cat
145 + $cat = get_the_terms($post_id, (isset($prams['cat'])?esc_attr($prams['cat']):'category'));
146 + if(!empty($cat)){
147 + $v = array();
148 + foreach ($cat as $val) {
149 + $v[] = array('slug' => $val->slug, 'name' => $val->name, 'url' => get_term_link($val->term_id));
150 + }
151 + $var['category'] = $v;
152 + }
153 + $data[] = $var;
154 + }
155 + wp_reset_postdata();
156 + }
290 157
291 - case 'taxvalue':
292 - $split = explode( '###', $condition_type );
293 - $condition = $split[1] != 'multiTaxonomy' ? array( $split[1] ) : get_object_taxonomies( $split[0] );
158 + return rest_ensure_response( $data );
159 +}
294 160
295 - if ( $post_type_condition && count( $post_type_condition ) ) {
296 - $condition = $post_type_condition;
297 - }
298 161
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 162
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;
163 +function ultp_route_taxonomy_data($prams) {
164 + if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce')){
165 + return rest_ensure_response([]);
166 + }
167 + return rest_ensure_response(ultimate_post()->taxonomy($prams['taxonomy']));
168 +}
334 169
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 - }
170 +function ultp_route_taxonomy_info_data($prams) {
171 + if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce')){
172 + return rest_ensure_response([]);
173 + }
376 174
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 - }
393 - }
175 + $data = array();
176 + $terms = get_terms( $prams, array(
177 + 'hide_empty' => true,
178 + ));
179 + if( !empty($terms) ){
180 + foreach ($terms as $val) {
181 + $data['name'] = $val->name;
182 + $data['count'] = $val->count;
183 + $data['url'] = get_term_link($val->term_id);
184 + $data['color'] = get_term_meta($val->term_id, '_background', true);
185 + }
186 + }
394 187
395 - /**
396 - * Post Data Response of REST API
397 - *
398 - * @since v.1.0.0
399 - * @param MIXED | $prams (ARRAY), Local (BOOLEAN).
400 - * @return ARRAY | Response Image Size as Array
401 - */
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;
410 -
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;
434 -
435 - if ( function_exists( 'get_field_objects' ) ) {
436 - $var['acf'] = get_field_objects();
437 - }
438 -
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 - }
463 -
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 - }
479 -
480 - // Taxonomy.
481 - $cat = get_the_terms( $post_id, ( isset( $prams['taxonomy'] ) ? esc_attr( $prams['taxonomy'] ) : 'category' ) );
482 -
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).
510 - * @return ARRAY | Response Taxonomy List as Array
511 - */
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 - }
516 -
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();
545 -
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 - /**
557 - * Specific Taxonomy Data Response of REST API
558 - *
559 - * @since v.1.0.0
560 - * @param ARRAY | $prams .
561 - * @return ARRAY | Response Taxonomy List as Array
562 - */
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'] ) : '';
573 -
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 -}
188 + return rest_ensure_response($data);
189 +}