PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.11
Post Grid Gutenberg Blocks – PostX v5.0.11
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
ultimate-post / classes / REST_API.php

REST_API.php in Post Grid Gutenberg Blocks – PostX 5.0.11, at classes/REST_API.php

735 lines 23.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * REST API Action.
4 *
5 * @package ULTP\REST_API
6 * @since v.1.0.0
7 */
8
9 namespace ULTP;
10
11 defined( 'ABSPATH' ) || exit;
12
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 {
22
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 }
31
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 }
161
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 ) {
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 }
220
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 } else if ($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 }
241
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
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;
290
291 case 'taxvalue':
292 $split = explode('###', $condition_type);
293 $condition = $split[1] != 'multiTaxonomy' ? array($split[1]) : get_object_taxonomies($split[0]);
294
295 if($post_type_condition && count($post_type_condition)) {
296 $condition = $post_type_condition;
297 }
298
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 = [];
353 if (!empty($post_results)) {
354 foreach ($post_results as $key => $val) {
355 $data[] = array('value'=>$val->taxonomy.'###'.$val->slug, 'title'=> '[ID: '.$val->term_id.'] '.$val->taxonomy.': '.$val->name);
356 }
357 }
358 return ['success' => true, 'data' => $data];
359 break;
360 // allPostType
361 case 'allPostType':
362 $all_types = array_values(get_post_types( array( 'public' => true ), 'names' ));
363 $postType = array();
364 foreach($all_types as $type){
365 $postType[] = array(
366 'title' => $type,
367 'value' => $type,
368 );
369 };
370
371 return array(
372 'success' => true,
373 'data' => $postType,
374 );
375 default:
376 return array(
377 'success' => true,
378 'data' => array(
379 array(
380 'value' => '',
381 'title' => '- Select -',
382 ),
383 ),
384 );
385 break;
386 }
387 }
388
389 /**
390 * Post Data Response of REST API
391 *
392 * @since v.1.0.0
393 * @param MIXED | $prams (ARRAY), Local (BOOLEAN).
394 * @return ARRAY | Response Image Size as Array
395 */
396 public function ultp_route_post_data( $prams ) {
397 $prams = $prams->get_params();
398 if ( ! ( isset( $prams['wpnonce'] ) && wp_verify_nonce( sanitize_key( wp_unslash( $prams['wpnonce'] ) ), 'ultp-nonce' ) ) ) {
399 die();
400 }
401 $data = array();
402 $loop = new \WP_Query( ultimate_post()->get_query( ultimate_post()->ultp_rest_sanitize_params( $prams ) ) );
403 $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;
404
405 if ( $loop->have_posts() ) {
406 while ( $loop->have_posts() ) {
407 $loop->the_post();
408 $var = array();
409 $post_id = get_the_ID();
410 $user_id = get_the_author_meta( 'ID' );
411 $content_data = get_the_content();
412 $var['ID'] = $post_id;
413 $var['title'] = get_the_title();
414 $var['permalink'] = get_permalink();
415 $var['seo_meta'] = ultimate_post()->get_excerpt( $post_id, 1 );
416 $var['excerpt'] = wp_strip_all_tags( get_the_excerpt() );
417 $var['excerpt_full'] = wp_strip_all_tags( get_the_excerpt() );
418 $var['time'] = (int) get_the_date( 'U' ) * 1000;
419 $var['timeModified'] = (int) get_the_modified_date( 'U' ) * 1000;
420 $var['post_time'] = human_time_diff( get_the_time( 'U' ), current_time( 'U' ) );
421 $var['view'] = get_post_meta( get_the_ID(), '__post_views_count', true );
422 $var['comments'] = get_comments_number();
423 $var['author_link'] = get_author_posts_url( $user_id );
424 $var['avatar_url'] = get_avatar_url( $user_id );
425 $var['display_name'] = get_the_author_meta( 'display_name' );
426 $var['reading_time'] = ceil( strlen( $content_data ) / 1200 );
427 $var['acf'] = null;
428
429 if ( function_exists( 'get_field_objects' ) ) {
430 $var['acf'] = get_field_objects();
431 }
432
433 $post_video = get_post_meta( $post_id, '__builder_feature_video', true );
434 // Video.
435 if ( $post_video ) {
436 $var['has_video'] = ultimate_post()->get_youtube_id( $post_video );
437 }
438 // image.
439 $image_sizes = ultimate_post()->get_image_size();
440 $image_src = array();
441 if ( has_post_thumbnail() ) {
442 $thumb_id = get_post_thumbnail_id( $post_id );
443 foreach ( $image_sizes as $key => $value ) {
444 $image = wp_get_attachment_image_src( $thumb_id, $key, false );
445 if ( $image && is_array( $image ) ) {
446 $image_src[ $key ] = $image[0];
447 }
448 }
449 $var['image'] = $image_src;
450 } elseif ( isset( $prams['fallbackImg']['id'] ) ) {
451 foreach ( $image_sizes as $key => $value ) {
452 $image_src[ $key ] = wp_get_attachment_image_src( esc_attr( $prams['fallbackImg']['id'] ), $key, false )[0];
453 }
454 $var['image'] = $image_src;
455 $var['is_fallback'] = true;
456 }
457
458 // tag.
459 $tag = get_the_terms( $post_id, ( isset( $prams['tag'] ) ? esc_attr( $prams['tag'] ) : 'post_tag' ) );
460 if ( ! empty( $tag ) ) {
461 $v = array();
462 foreach ( $tag as $k => $val ) {
463 if ( $k >= $max_tax ) {
464 break; }
465 $v[] = array(
466 'slug' => $val->slug,
467 'name' => $val->name,
468 'url' => get_term_link( $val->term_id ),
469 );
470 }
471 $var['tag'] = $v;
472 }
473
474 // Taxonomy.
475 $cat = get_the_terms( $post_id, ( isset( $prams['taxonomy'] ) ? esc_attr( $prams['taxonomy'] ) : 'category' ) );
476
477 if ( ! empty( $cat ) ) {
478 $v = array();
479 foreach ( $cat as $k => $val ) {
480 if ( $k >= $max_tax ) {
481 break; }
482 $v[] = array(
483 'slug' => $val->slug,
484 'name' => $val->name,
485 'url' => get_term_link( $val->term_id ),
486 'color' => get_term_meta( $val->term_id, 'ultp_category_color', true ),
487 );
488 }
489 $var['category'] = $v;
490 }
491 $data[] = $var;
492 }
493 wp_reset_postdata();
494 }
495 return rest_ensure_response( $data );
496 }
497
498
499 /**
500 * STaxonomy Data Response of REST API
501 *
502 * @since v.1.0.0
503 * @param ARRAY | $prams (ARRAY).
504 * @return ARRAY | Response Taxonomy List as Array
505 */
506 public function ultp_route_common_data( $prams ) {
507 if ( ! ( isset( $_REQUEST['wpnonce'] ) && wp_verify_nonce( sanitize_key( wp_unslash( $_REQUEST['wpnonce'] ) ), 'ultp-nonce' ) ) ) {
508 return rest_ensure_response( array() );
509 }
510
511 $all_post_type = ultimate_post()->get_post_type();
512 $data = array();
513 foreach ( $all_post_type as $post_type_slug => $post_type ) {
514 $data_term = array();
515 $taxonomies = get_object_taxonomies( $post_type_slug );
516 foreach ( $taxonomies as $key => $taxonomy_slug ) {
517 $taxonomy_value = get_terms(
518 array(
519 'taxonomy' => $taxonomy_slug,
520 'hide_empty' => false,
521 )
522 );
523 if ( ! is_wp_error( $taxonomy_value ) ) {
524 $data_tax = array();
525 foreach ( $taxonomy_value as $k => $taxonomy ) {
526 $data_tax[ urldecode_deep( $taxonomy->slug ) ] = $taxonomy->name;
527 }
528 if ( count( $data_tax ) > 0 ) {
529 $data_term[ $taxonomy_slug ] = $data_tax;
530 }
531 }
532 }
533 $data[ $post_type_slug ] = $data_term;
534 }
535 // Global Customizer.
536 $global = get_option( 'postx_global', array() );
537 // Image Size.
538 $image_sizes = ultimate_post()->get_image_size();
539
540 return rest_ensure_response(
541 array(
542 'taxonomy' => $data,
543 'global' => $global,
544 'image' => wp_json_encode( $image_sizes ),
545 'posttype' => wp_json_encode( $all_post_type ),
546 )
547 );
548 }
549
550 /**
551 * Specific Taxonomy Data Response of REST API
552 *
553 * @since v.1.0.0
554 * @param ARRAY | $prams .
555 * @return ARRAY | Response Taxonomy List as Array
556 */
557 public function ultp_route_taxonomy_info_data( $prams ) {
558 $prams = $prams->get_params();
559 if ( ! ( isset( $prams['wpnonce'] ) && wp_verify_nonce( sanitize_key( wp_unslash( $prams['wpnonce'] ) ), 'ultp-nonce' ) ) ) {
560 return rest_ensure_response( array() );
561 }
562 $taxValue = isset( $prams['taxValue'] ) ? ultimate_post()->ultp_rest_sanitize_params( $prams['taxValue'] ) : '';
563 $queryNumber = isset( $prams['queryNumber'] ) ? ultimate_post()->ultp_rest_sanitize_params( $prams['queryNumber'] ) : '';
564 $taxType = isset( $prams['taxType'] ) ? ultimate_post()->ultp_rest_sanitize_params( $prams['taxType'] ) : '';
565 $taxSlug = isset( $prams['taxSlug'] ) ? ultimate_post()->ultp_rest_sanitize_params( $prams['taxSlug'] ) : '';
566 $archiveBuilder = isset( $prams['archiveBuilder'] ) ? ultimate_post()->ultp_rest_sanitize_params( $prams['archiveBuilder'] ) : '';
567
568 return rest_ensure_response( ultimate_post()->get_category_data( json_decode( $taxValue ), $queryNumber, $taxType, $taxSlug, $archiveBuilder ) );
569 }
570
571 /**
572 * Get Taxonomies for Custom Post Type
573 *
574 * @since v.3.2.8
575 * @param array $prams .
576 * @return array
577 */
578 public function custom_tax_callback( $prams ) {
579
580 $post_types = isset( $prams['postTypes'] ) ? ultimate_post()->ultp_rest_sanitize_params( $prams['postTypes'] ) : array();
581
582 $data = array(
583 array(
584 'id' => '_all',
585 'name' => __( 'All', 'ultimate-post' ),
586 ),
587 );
588
589 foreach ( $post_types as $post_type ) {
590 $taxonomies = get_object_taxonomies( $post_type );
591 foreach ( $taxonomies as $taxonomy ) {
592 $terms = get_terms(
593 array(
594 'taxonomy' => $taxonomy,
595 'hide_empty' => false,
596 )
597 );
598 foreach ( $terms as $term ) {
599 $data[] = array(
600 'id' => $term->slug,
601 'name' => $term->name,
602 );
603 }
604 }
605 }
606
607 return rest_ensure_response( $data );
608 }
609
610 /**
611 * Search Block Data Showing
612 *
613 * @since v.2.9.9
614 * @param STRING | $server .
615 * @return ARRAY | Inserted Post Url
616 */
617 public function ultp_search_result( $server ) {
618 $post = $server->get_params();
619 $searchText = isset( $post['searchText'] ) ? ultimate_post()->ultp_rest_sanitize_params( $post['searchText'] ) : '';
620 $paged = isset( $post['paged'] ) ? ultimate_post()->ultp_rest_sanitize_params( $post['paged'] ) : '';
621 $postPerPage = isset( $post['postPerPage'] ) ? ultimate_post()->ultp_rest_sanitize_params( $post['postPerPage'] ) : '';
622 $query_args = array(
623 's' => $searchText,
624 'paged' => $paged,
625 'compare' => 'LIKE',
626 'orderby' => 'relevance',
627 'posts_per_page' => $postPerPage,
628 );
629 if ( isset( $post['exclude'] ) && is_array( $post['exclude'] ) && count( $post['exclude'] ) > 0 ) {
630 $post['exclude'] = ultimate_post()->ultp_rest_sanitize_params( $post['exclude'] );
631 $post_exclude = array();
632 foreach ( $post['exclude'] as $data ) {
633 $post_exclude[ $data['title'] ] = $data['title'];
634 }
635 $all_types = get_post_types( array( 'public' => true ), 'names' );
636 $post_type = array_diff_key( $all_types, $post_exclude );
637 $query_args['post_type'] = $post_type;
638 }
639 $output = '';
640 $query_result = new \WP_Query( $query_args );
641
642 if ( $query_result->have_posts() ) {
643 while ( $query_result->have_posts() ) {
644 $query_result->the_post();
645 $post_id = get_the_ID();
646 $title = get_the_title();
647
648 $output .= '<div class="ultp-search-result__item">';
649 if ( $post['image'] == 1 && has_post_thumbnail() ) {
650 $thumb_id = get_post_thumbnail_id( $post_id );
651 $output .= '<img class="ultp-searchresult-image" src=' . wp_get_attachment_image_src( $thumb_id, 'thumbnail', false )[0] . ' alt="' . $title . '"/>';
652 }
653 $output .= '<div class="ultp-searchresult-content">';
654 $output .= '<div class="ultp-rescontent-meta">';
655 // Category.
656 $post_cat = get_the_terms( $post_id, 'category' );
657 if ( $post['category'] == 1 && $post_cat && count( $post_cat ) ) {
658 $output .= '<div class="ultp-searchresult-category">';
659 foreach ( $post_cat as $cat ) {
660 $output .= '<a href="' . get_term_link( $cat->term_id ) . '">' . $cat->name . '</a>';
661 }
662 $output .= '</div>';
663 }
664 // Author.
665 if ( $post['author'] == 1 ) {
666 $user_id = get_the_author_meta( 'ID' );
667 $output .= '<a href="' . get_author_posts_url( $user_id ) . '" class="ultp-searchresult-author">' . get_the_author_meta( 'display_name' ) . '</a>';
668 }
669 // Date.
670 if ( $post['date'] == 1 ) {
671 $output .= '<div class="ultp-searchresult-publishdate">' . get_the_date( 'F j, Y' ) . '</div>';
672 }
673 $output .= '</div>';
674 $output .= '<a href="' . get_permalink() . '" class="ultp-searchresult-title">' . $title . '</a>';
675 if ( $post['excerpt'] == 1 ) {
676 $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>';
677 }
678 $output .= '</div>';
679 $output .= '</div>';
680 }
681 }
682
683 return array(
684 'post_data' => $output,
685 'post_count' => $query_result->found_posts,
686 );
687 }
688
689 /**
690 * PostX Site Dark Logo Init
691 *
692 * @since v.3.1.9
693 * @param ARRAY | $server .
694 * @return BOOOLEAN | Inserted Post Url
695 */
696 public function init_site_dark_logo_callback( $server ) {
697 $logo_data = $server->get_params();
698 $success = true;
699 if ( isset( $logo_data['logo']['url'] ) ) {
700 update_option( 'ultp_site_dark_logo', $logo_data['logo']['url'] );
701 } else {
702 $success = false;
703 }
704 return rest_ensure_response(
705 array(
706 'success' => $success,
707 )
708 );
709 }
710
711
712 /**
713 * Getting Image Size
714 *
715 * @since v.4.0.1
716 * @param ARRAY | $server (number) .
717 * @return ARRAY | Image Size List as Array
718 */
719 public function get_custom_image_size( $server ) {
720 $img = $server->get_params();
721 $image_src = array();
722 $image_sizes = ultimate_post()->get_image_size();
723 foreach ( $image_sizes as $key => $value ) {
724 $image_src[ $key ] = wp_get_attachment_image_src( $img['id'], $key, false )[0];
725 }
726 return rest_ensure_response(
727 array(
728 'success' => true,
729 'size' => $image_src,
730 'id' => $img,
731 )
732 );
733 }
734 }
735