PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.7.8
Post Grid Gutenberg Blocks – PostX v2.7.8
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 +291 -684 5.0.322.7.8 View file →
@@ -1,749 +1,356 @@
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(
69 + register_rest_route(
94 70 'ultp/v2',
95 - '/premade_wishlist_save/',
71 + '/template_page_insert/',
96 72 array(
97 73 array(
98 - 'methods' => 'POST',
99 - 'callback' => array( $this, 'premade_wishlist_save' ),
74 + 'methods' => 'POST',
75 + 'callback' => array($this, 'template_page_insert'),
100 76 'permission_callback' => function () {
101 - return current_user_can( 'edit_others_posts' );
77 + return current_user_can('edit_posts');
102 78 },
103 - 'args' => array(),
104 - ),
79 + 'args' => array()
80 + )
105 81 )
106 82 );
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 - }
83 + }
161 84
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.
85 + /**
86 + * Insert Post For Imported Template
87 + *
88 + * @since v.2.6.7
89 + * @param STRING
90 + * @return ARRAY | Inserted Post Url
170 91 */
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'] ) : '';
92 + public function template_page_insert($server) {
93 + $post = $server->get_params();
94 + $new_page = array(
95 + 'post_title' => $post['title'],
96 + 'post_type' => 'page',
97 + 'post_content' => $post['blockCode'],
98 + 'post_status' => 'draft',
99 + );
100 + $post_id = wp_insert_post( $new_page );
101 + return array( 'success' => true, 'link' => get_edit_post_link($post_id));
102 + }
177 103
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 104
198 -
199 -
200 - /**
201 - * Search_settings_action
202 - *
203 - * @param mixed $server .
204 - * @return array
205 - */
206 - public function search_settings_action( $server ) {
105 + public function search_settings_action($server) {
207 106 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 - }
107 + $post = $server->get_params();
220 108
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 - }
109 + switch ($post['type']) {
110 + case 'posts':
111 + case 'allpost':
112 + case 'postExclude':
113 + $post_type = array('post');
114 + if ($post['type'] == 'allpost') {
115 + $post_type = array_keys(ultimate_post()->get_post_type());
116 + } else if ($post['type'] == 'postExclude') {
117 + $post_type = array($post['condition']);
118 + }
119 + $args = array(
120 + 'post_type' => $post_type,
121 + 'post_status' => 'publish',
122 + 'posts_per_page' => 10,
123 + );
124 + if (is_numeric($post['term'])) {
125 + $args['p'] = $post['term'];
126 + } else {
127 + $args['s'] = $post['term'];
128 + }
241 129
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;
130 + $post_results = new \WP_Query($args);
131 + $data = [];
132 + if (!empty($post_results)) {
133 + while ( $post_results->have_posts() ) {
134 + $post_results->the_post();
135 + $id = get_the_ID();
136 + $title = html_entity_decode(get_the_title());
137 + $data[] = array('value'=>$id, 'title'=>($title?'[ID: '.$id.'] '.$title:('[ID: '.$id.']')));
138 + }
139 + wp_reset_postdata();
140 + }
141 + return ['success' => true, 'data' => $data];
142 + break;
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
144 + case 'author':
145 + $term = '%'. $wpdb->esc_like( $post['term'] ) .'%';
146 + $post_results = $wpdb->get_results(
147 + $wpdb->prepare(
148 + "SELECT ID, display_name
267 149 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;
150 + 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
151 + )
152 + );
153 + $data = [];
154 + if (!empty($post_results)) {
155 + foreach ($post_results as $key => $val) {
156 + $data[] = array('value'=>$val->ID, 'title'=>'[ID: '.$val->ID.'] '.$val->display_name);
157 + }
158 + }
159 + return ['success' => true, 'data' => $data];
160 + break;
290 161
291 - case 'taxvalue':
292 - $split = explode( '###', $condition_type );
293 - $condition = $split[1] != 'multiTaxonomy' ? array( $split[1] ) : get_object_taxonomies( $split[0] );
162 + case 'taxvalue':
163 + $split = explode('###', $post['condition']);
164 + $condition = $split[1] != 'multiTaxonomy' ? array($split[1]) : get_object_taxonomies($split[0]);
165 + $args = array(
166 + 'taxonomy' => $condition,
167 + 'fields' => 'all',
168 + 'orderby' => 'id',
169 + 'order' => 'ASC',
170 + 'name__like'=> $post['term']
171 + );
172 + if (is_numeric($post['term'])) {
173 + unset($args['name__like']);
174 + $args['include'] = array($post['term']);
175 + }
294 176
295 - if ( $post_type_condition && count( $post_type_condition ) ) {
296 - $condition = $post_type_condition;
297 - }
177 + $post_results = get_terms( $args );
178 + $data = [];
179 + if (!empty($post_results)) {
180 + foreach ($post_results as $key => $val) {
181 + if ($split[1] == 'multiTaxonomy') {
182 + $data[] = array('value'=>$val->taxonomy.'###'.$val->slug, 'title'=> '[ID: '.$val->term_id.'] '.$val->taxonomy.': '.$val->name);
183 + } else {
184 + $data[] = array('value'=>$val->slug, 'title'=>'[ID: '.$val->term_id.'] '.$val->name);
185 + }
186 + }
187 + }
188 + return ['success' => true, 'data' => $data];
189 + break;
298 190
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 - }
191 + case 'taxExclude':
192 + $condition = get_object_taxonomies($post['condition']);
193 + $args = array(
194 + 'taxonomy' => $condition,
195 + 'fields' => 'all',
196 + 'orderby' => 'id',
197 + 'order' => 'ASC',
198 + 'name__like'=> $post['term']
199 + );
200 + if (is_numeric($post['term'])) {
201 + unset($args['name__like']);
202 + $args['include'] = array($post['term']);
203 + }
204 + $post_results = get_terms( $args );
205 + $data = [];
206 + if (!empty($post_results)) {
207 + foreach ($post_results as $key => $val) {
208 + $data[] = array('value'=>$val->taxonomy.'###'.$val->slug, 'title'=> '[ID: '.$val->term_id.'] '.$val->taxonomy.': '.$val->name);
209 + }
210 + }
211 + return ['success' => true, 'data' => $data];
212 + break;
213 +
310 214
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 - }
215 + default:
216 + return ['success' => true, 'data' => [['value'=>'', 'title'=>'- Select -']]];
217 + break;
218 + }
393 219 }
394 220
395 - /**
221 + /**
396 222 * Post Data Response of REST API
397 - *
398 - * @since v.1.0.0
399 - * @param MIXED | $prams (ARRAY), Local (BOOLEAN).
223 + *
224 + * @since v.1.0.0
225 + * @param MIXED | Pram (ARRAY), Local (BOOLEAN)
400 226 * @return ARRAY | Response Image Size as Array
401 227 */
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;
228 + public function ultp_route_post_data($prams,$local=false) {
229 + if (!wp_verify_nonce(wp_unslash($_REQUEST['wpnonce']), 'ultp-nonce') && $local){
230 + return ;
231 + }
410 232
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;
233 + $prams = $prams->get_params();
234 +
235 + $data = [];
236 + $loop = new \WP_Query( ultimate_post()->get_query($prams) );
237 +
238 + if ($loop->have_posts()) {
239 + while($loop->have_posts()) {
240 + $loop->the_post();
241 + $var = array();
242 + $post_id = get_the_ID();
243 + $user_id = get_the_author_meta('ID');
244 + $content_data = get_the_content();
245 + $var['ID'] = $post_id;
246 + $var['title'] = get_the_title();
247 + $var['permalink'] = get_permalink();
248 + $var['seo_meta'] = ultimate_post()->get_excerpt($post_id, 1);
249 + $var['excerpt'] = strip_tags($content_data);
250 + $var['excerpt_full']= strip_tags(get_the_excerpt());
251 + $var['time'] = (int)get_the_date('U')*1000;
252 + $var['timeModified']= (int)get_the_modified_date('U')*1000;
253 + $var['post_time'] = human_time_diff(get_the_time('U'),current_time('U'));
254 + $var['view'] = get_post_meta(get_the_ID(),'__post_views_count', true);
255 + $var['comments'] = get_comments_number();
256 + $var['author_link'] = get_author_posts_url($user_id);
257 + $var['avatar_url'] = get_avatar_url($user_id);
258 + $var['display_name']= get_the_author_meta('display_name');
259 + $var['reading_time']= ceil(strlen($content_data)/1200);
260 +
261 + // image
262 + if (has_post_thumbnail()) {
263 + $thumb_id = get_post_thumbnail_id($post_id);
264 + $image_sizes = ultimate_post()->get_image_size();
265 + $image_src = array();
266 + foreach ($image_sizes as $key => $value) {
267 + $image_src[$key] = wp_get_attachment_image_src($thumb_id, $key, false)[0];
268 + }
269 + $var['image'] = $image_src;
270 + }
434 271
435 - if ( function_exists( 'get_field_objects' ) ) {
436 - $var['acf'] = get_field_objects();
437 - }
272 + // tag
273 + $tag = get_the_terms($post_id, (isset($prams['tag'])?esc_attr($prams['tag']):'post_tag'));
274 + if (!empty($tag)) {
275 + $v = array();
276 + foreach ($tag as $val) {
277 + $v[] = array('slug' => $val->slug, 'name' => $val->name, 'url' => get_term_link($val->term_id));
278 + }
279 + $var['tag'] = $v;
280 + }
438 281
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 - }
282 + // Taxonomy
283 + $cat = get_the_terms($post_id, (isset($prams['taxonomy'])?esc_attr($prams['taxonomy']):'category'));
284 + if(!empty($cat)){
285 + $v = array();
286 + foreach ($cat as $val) {
287 + $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));
288 + }
289 + $var['category'] = $v;
290 + }
291 + $data[] = $var;
292 + }
293 + wp_reset_postdata();
294 + }
463 295
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 - }
296 + return rest_ensure_response( $data );
297 + }
479 298
480 - // Taxonomy.
481 - $cat = get_the_terms( $post_id, ( isset( $prams['taxonomy'] ) ? esc_attr( $prams['taxonomy'] ) : 'category' ) );
482 299
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).
300 + /**
301 + * Taxonomy Data Response of REST API
302 + *
303 + * @since v.1.0.0
304 + * @param ARRAY | Parameter (ARRAY)
510 305 * @return ARRAY | Response Taxonomy List as Array
511 306 */
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 - }
307 + public function ultp_route_common_data($prams) {
308 + if (!wp_verify_nonce(wp_unslash($_REQUEST['wpnonce']), 'ultp-nonce')){
309 + return rest_ensure_response([]);
310 + }
311 +
312 + $all_post_type = ultimate_post()->get_post_type();
313 + $data = array();
314 + foreach ($all_post_type as $post_type_slug => $post_type ) {
315 + $data_term = array();
316 + $taxonomies = get_object_taxonomies($post_type_slug);
317 + foreach ($taxonomies as $key => $taxonomy_slug) {
318 + $taxonomy_value = get_terms(array(
319 + 'taxonomy' => $taxonomy_slug,
320 + 'hide_empty' => false
321 + ));
322 + if (!is_wp_error($taxonomy_value)) {
323 + $data_tax = array();
324 + foreach ($taxonomy_value as $k => $taxonomy) {
325 + $data_tax[urldecode_deep($taxonomy->slug)] = $taxonomy->name;
326 + }
327 + if (count($data_tax) > 0) {
328 + $data_term[$taxonomy_slug] = $data_tax;
329 + }
330 + }
331 + }
332 + $data[$post_type_slug] = $data_term;
333 + }
334 + // Global Customizer
335 + $global = get_option('postx_global', []);
336 + // Image Size
337 + $image_sizes = ultimate_post()->get_image_size();
516 338
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();
339 + return rest_ensure_response(['taxonomy' => $data, 'global' => $global, 'image' => json_encode($image_sizes), 'posttype' => json_encode($all_post_type)]);
340 + }
545 341
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 - /**
342 + /**
557 343 * Specific Taxonomy Data Response of REST API
558 - *
559 - * @since v.1.0.0
560 - * @param ARRAY | $prams .
344 + *
345 + * @since v.1.0.0
346 + * @param ARRAY | Parameter (ARRAY)
561 347 * @return ARRAY | Response Taxonomy List as Array
562 348 */
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'] ) : '';
349 + public function ultp_route_taxonomy_info_data($prams) {
350 + if (!wp_verify_nonce(wp_unslash($_REQUEST['wpnonce']), 'ultp-nonce')) {
351 + return rest_ensure_response([]);
352 + }
573 353
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 -}
354 + return rest_ensure_response( ultimate_post()->get_category_data(json_decode($prams['taxValue']), $prams['queryNumber'], $prams['taxType'], $prams['taxSlug']) );
355 + }
356 +}