| 1 |
<?php |
| 2 |
/** |
| 3 |
* REST API Action. |
| 4 |
* |
| 5 |
* @package ULTP\REST_API |
| 6 |
* @since v.1.0.0 |
| 7 |
*/ |
| 8 |
namespace ULTP; |
| 9 |
|
| 10 |
defined('ABSPATH') || exit; |
| 11 |
|
| 12 |
/** |
| 13 |
* Styles class. |
| 14 |
*/ |
| 15 |
class REST_API{ |
| 16 |
|
| 17 |
/** |
| 18 |
* Setup class. |
| 19 |
* |
| 20 |
* @since v.1.0.0 |
| 21 |
*/ |
| 22 |
public function __construct() { |
| 23 |
add_action( 'rest_api_init', array($this, 'ultp_register_route') ); |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
/** |
| 28 |
* REST API Action |
| 29 |
* |
| 30 |
* @since v.1.0.0 |
| 31 |
* @return NULL |
| 32 |
*/ |
| 33 |
public function ultp_register_route() { |
| 34 |
register_rest_route( 'ultp', 'posts', array( |
| 35 |
'args' => array(), |
| 36 |
'callback' => array($this,'ultp_route_post_data'), |
| 37 |
'permission_callback' => '__return_true' |
| 38 |
) |
| 39 |
); |
| 40 |
register_rest_route( 'ultp', 'common', array( |
| 41 |
'methods' => \WP_REST_Server::READABLE, |
| 42 |
'args' => array('wpnonce' => []), |
| 43 |
'callback' => array($this,'ultp_route_common_data'), |
| 44 |
'permission_callback' => '__return_true' |
| 45 |
) |
| 46 |
); |
| 47 |
register_rest_route( 'ultp', 'specific_taxonomy', array( |
| 48 |
'methods' => \WP_REST_Server::READABLE, |
| 49 |
'args' => array('taxType' => [], 'taxSlug' => [], 'taxValue' => [], 'queryNumber' => [], 'wpnonce' => [], 'archiveBuilder' => []), |
| 50 |
'callback' => array($this,'ultp_route_taxonomy_info_data'), |
| 51 |
'permission_callback' => '__return_true' |
| 52 |
) |
| 53 |
); |
| 54 |
register_rest_route( |
| 55 |
'ultp/v1', |
| 56 |
'/search/', |
| 57 |
array( |
| 58 |
array( |
| 59 |
'methods' => 'POST', |
| 60 |
'callback' => array($this, 'search_settings_action'), |
| 61 |
'permission_callback' => function () { |
| 62 |
return current_user_can('edit_posts'); |
| 63 |
}, |
| 64 |
'args' => array() |
| 65 |
) |
| 66 |
) |
| 67 |
); |
| 68 |
register_rest_route( |
| 69 |
'ultp/v2', |
| 70 |
'/template_page_insert/', |
| 71 |
array( |
| 72 |
array( |
| 73 |
'methods' => 'POST', |
| 74 |
'callback' => array($this, 'template_page_insert'), |
| 75 |
'permission_callback' => function () { |
| 76 |
return current_user_can('manage_options'); |
| 77 |
}, |
| 78 |
'args' => array() |
| 79 |
) |
| 80 |
) |
| 81 |
); |
| 82 |
register_rest_route( |
| 83 |
'ultp/v2', |
| 84 |
'/addon_block_action/', |
| 85 |
array( |
| 86 |
array( |
| 87 |
'methods' => 'POST', |
| 88 |
'callback' => array($this, 'addon_block_action'), |
| 89 |
'permission_callback' => function () { |
| 90 |
return current_user_can('manage_options'); |
| 91 |
}, |
| 92 |
'args' => array() |
| 93 |
) |
| 94 |
) |
| 95 |
); |
| 96 |
register_rest_route( |
| 97 |
'ultp/v2', |
| 98 |
'/premade_wishlist_save/', |
| 99 |
array( |
| 100 |
array( |
| 101 |
'methods' => 'POST', |
| 102 |
'callback' => array($this, 'premade_wishlist_save'), |
| 103 |
'permission_callback' => function () { |
| 104 |
return current_user_can('edit_posts'); |
| 105 |
}, |
| 106 |
'args' => array() |
| 107 |
) |
| 108 |
) |
| 109 |
); |
| 110 |
register_rest_route( |
| 111 |
'ultp/v2', |
| 112 |
'/save_plugin_settings/', |
| 113 |
array( |
| 114 |
array( |
| 115 |
'methods' => 'POST', |
| 116 |
'callback' => array($this, 'save_plugin_settings'), |
| 117 |
'permission_callback' => function () { |
| 118 |
return current_user_can('manage_options'); |
| 119 |
}, |
| 120 |
'args' => array() |
| 121 |
) |
| 122 |
) |
| 123 |
); |
| 124 |
register_rest_route( |
| 125 |
'ultp', |
| 126 |
'/ultp_search_data/', |
| 127 |
array( |
| 128 |
array( |
| 129 |
'methods' => 'POST', |
| 130 |
'callback' => array($this, 'ultp_search_result'), |
| 131 |
'permission_callback' => '__return_true' |
| 132 |
) |
| 133 |
) |
| 134 |
); |
| 135 |
register_rest_route( |
| 136 |
'ultp/v2', |
| 137 |
'/get_all_settings/', |
| 138 |
array( |
| 139 |
array( |
| 140 |
'methods' => 'POST', |
| 141 |
'callback' => array($this, 'get_all_settings'), |
| 142 |
'permission_callback' => function () { |
| 143 |
return current_user_can('manage_options'); |
| 144 |
}, |
| 145 |
'args' => array() |
| 146 |
) |
| 147 |
) |
| 148 |
); |
| 149 |
register_rest_route( |
| 150 |
'ultp/v2', |
| 151 |
'/dashborad/', |
| 152 |
array( |
| 153 |
array( |
| 154 |
'methods' => 'POST', |
| 155 |
'callback' => array( $this, 'get_dashboard_callback'), |
| 156 |
'permission_callback' => function () { |
| 157 |
return current_user_can( 'manage_options' ); |
| 158 |
}, |
| 159 |
'args' => array() |
| 160 |
) |
| 161 |
) |
| 162 |
); |
| 163 |
register_rest_route( |
| 164 |
'ultp/v2', |
| 165 |
'/wizard_site_status/', |
| 166 |
array( |
| 167 |
array( |
| 168 |
'methods' => 'POST', |
| 169 |
'callback' => array( $this, 'wizard_site_status_callback'), |
| 170 |
'permission_callback' => function () { |
| 171 |
return current_user_can( 'manage_options' ); |
| 172 |
}, |
| 173 |
'args' => array() |
| 174 |
) |
| 175 |
) |
| 176 |
); |
| 177 |
register_rest_route( |
| 178 |
'ultp/v2', |
| 179 |
'/send_initial_plugin_data/', |
| 180 |
array( |
| 181 |
array( |
| 182 |
'methods' => 'POST', |
| 183 |
'callback' => array( $this, 'send_initial_plugin_data_callback'), |
| 184 |
'permission_callback' => function () { |
| 185 |
return current_user_can( 'manage_options' ); |
| 186 |
}, |
| 187 |
'args' => array() |
| 188 |
) |
| 189 |
) |
| 190 |
); |
| 191 |
register_rest_route( |
| 192 |
'ultp/v2', |
| 193 |
'/initial_setup_complete/', |
| 194 |
array( |
| 195 |
array( |
| 196 |
'methods' => 'POST', |
| 197 |
'callback' => array( $this, 'initial_setup_complete_callback'), |
| 198 |
'permission_callback' => function () { |
| 199 |
return current_user_can( 'manage_options' ); |
| 200 |
}, |
| 201 |
'args' => array() |
| 202 |
) |
| 203 |
) |
| 204 |
); |
| 205 |
register_rest_route( |
| 206 |
'ultp/v2', |
| 207 |
'/init_site_dark_logo/', |
| 208 |
array( |
| 209 |
array( |
| 210 |
'methods' => 'POST', |
| 211 |
'callback' => array( $this, 'init_site_dark_logo_callback'), |
| 212 |
'permission_callback' => function () { |
| 213 |
return current_user_can( 'manage_options' ); |
| 214 |
}, |
| 215 |
'args' => array() |
| 216 |
) |
| 217 |
) |
| 218 |
); |
| 219 |
register_rest_route( |
| 220 |
'ultp/v2', |
| 221 |
'/init_site_dark_logo/', |
| 222 |
array( |
| 223 |
array( |
| 224 |
'methods' => 'POST', |
| 225 |
'callback' => array( $this, 'init_site_dark_logo_callback'), |
| 226 |
'permission_callback' => function () { |
| 227 |
return current_user_can( 'edit_posts' ); |
| 228 |
}, |
| 229 |
'args' => array() |
| 230 |
) |
| 231 |
) |
| 232 |
); |
| 233 |
register_rest_route( |
| 234 |
'ultp/v2', |
| 235 |
'/get_ultp_image_size/', |
| 236 |
array( |
| 237 |
array( |
| 238 |
'methods' => 'POST', |
| 239 |
'callback' => array( $this, 'get_custom_image_size'), |
| 240 |
'permission_callback' => '__return_true', |
| 241 |
'args' => array() |
| 242 |
) |
| 243 |
) |
| 244 |
); |
| 245 |
} |
| 246 |
|
| 247 |
/** |
| 248 |
* Initial Plugin Setup Complete |
| 249 |
* |
| 250 |
* * @since v.2.8.1 |
| 251 |
* @return STRING |
| 252 |
*/ |
| 253 |
public static function initial_setup_complete_callback($server) { |
| 254 |
$post = $server->get_params(); |
| 255 |
if ( ! (isset($post['wpnonce']) && wp_verify_nonce( sanitize_key(wp_unslash($post['wpnonce'])), 'ultp-nonce' )) ) { |
| 256 |
die(); |
| 257 |
} |
| 258 |
ultimate_post()->set_setting('init_setup', 'yes'); |
| 259 |
return rest_ensure_response([ |
| 260 |
'success' => true, |
| 261 |
'redirect' => admin_url('admin.php?page=ultp-settings'), |
| 262 |
]); |
| 263 |
} |
| 264 |
|
| 265 |
/** |
| 266 |
* Send Plugin Data When Initial Setup |
| 267 |
* |
| 268 |
* * @since v.2.8.1 |
| 269 |
* @return STRING |
| 270 |
*/ |
| 271 |
public function send_initial_plugin_data_callback($server) { |
| 272 |
$post = $server->get_params(); |
| 273 |
if ( ! (isset($post['wpnonce']) && wp_verify_nonce( sanitize_key(wp_unslash($post['wpnonce'])), 'ultp-nonce' )) ) { |
| 274 |
die(); |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
$site = isset($post['site']) ? ultimate_post()->ultp_rest_sanitize_params( $post['site'] ) : ''; |
| 279 |
|
| 280 |
require_once ULTP_PATH.'classes/Deactive.php'; |
| 281 |
$obj = new \ULTP\Deactive(); |
| 282 |
$obj->send_plugin_data('postx_wizard', $site); |
| 283 |
} |
| 284 |
|
| 285 |
/** |
| 286 |
* wizard_site_status_callback |
| 287 |
* |
| 288 |
* * @since v.3.0.0 |
| 289 |
* @return STRING |
| 290 |
*/ |
| 291 |
public static function wizard_site_status_callback() { |
| 292 |
if ( ! (isset($_POST['wpnonce']) && wp_verify_nonce( sanitize_key(wp_unslash($_POST['wpnonce'])), 'ultp-nonce' )) ) { |
| 293 |
die(); |
| 294 |
} |
| 295 |
if ( isset( $_FILES['siteIcon'],$_FILES['siteIcon']['name'] ) ) { |
| 296 |
$file_extension = strtolower( pathinfo( $_FILES['siteIcon']['name'], PATHINFO_EXTENSION ) ); //phpcs:ignore |
| 297 |
$allowed_extenstion = array( 'jpg', 'jpeg', 'png', 'gif', 'webp', 'ico' ); |
| 298 |
if ( in_array( $file_extension, $allowed_extenstion ) ) { |
| 299 |
require_once ABSPATH . 'wp-admin/includes/image.php'; |
| 300 |
require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 301 |
require_once ABSPATH . 'wp-admin/includes/media.php'; |
| 302 |
$file_id = media_handle_upload( 'siteIcon', 0 ); |
| 303 |
if ( $file_id ) { |
| 304 |
update_option( 'site_icon', $file_id ); |
| 305 |
} |
| 306 |
} |
| 307 |
} |
| 308 |
if ( isset( $_POST['siteName'] ) ) { |
| 309 |
$site_name = ultimate_post()->ultp_rest_sanitize_params( $_POST['siteName'] ); |
| 310 |
update_option( 'blogname', $site_name ); |
| 311 |
} |
| 312 |
if ( isset( $_POST['siteType'] ) ) { |
| 313 |
$site_type = ultimate_post()->ultp_rest_sanitize_params( $_POST['siteType'] ); |
| 314 |
update_option( '__ultp_site_type', $site_type ); |
| 315 |
} |
| 316 |
return rest_ensure_response( ['success' => true ]); |
| 317 |
} |
| 318 |
|
| 319 |
/** |
| 320 |
* Save Settings of Option Panel |
| 321 |
* |
| 322 |
* @since v.3.0.0 |
| 323 |
* @return NULL |
| 324 |
*/ |
| 325 |
public function get_all_settings($server) { |
| 326 |
return rest_ensure_response(['success' => true, 'settings' => ultimate_post()->get_setting()]); |
| 327 |
} |
| 328 |
/** |
| 329 |
* Save Settings of Option Panel |
| 330 |
* |
| 331 |
* @since v.3.0.0 |
| 332 |
* @return NULL |
| 333 |
*/ |
| 334 |
public function save_plugin_settings($server) { |
| 335 |
$post = $server->get_params(); |
| 336 |
$data = ultimate_post()->ultp_rest_sanitize_params($post['settings']); |
| 337 |
if (count($data) > 0) { |
| 338 |
foreach ($data as $key => $val) { |
| 339 |
ultimate_post()->set_setting($key, $val); |
| 340 |
} |
| 341 |
do_action('ultimate_post_after_setting_save'); |
| 342 |
} |
| 343 |
return rest_ensure_response([ |
| 344 |
'success' => true, |
| 345 |
'message' => __('You have successfully saved the settings data.', 'ultimate-post') , |
| 346 |
'wishListArr' => wp_json_encode($data)]); |
| 347 |
} |
| 348 |
|
| 349 |
/** |
| 350 |
* Save and get premade_wishlist_save |
| 351 |
* |
| 352 |
* @since v.3.0.0 |
| 353 |
* @param STRING |
| 354 |
* @return ARRAY | Inserted Post Url |
| 355 |
*/ |
| 356 |
public function premade_wishlist_save($server) { |
| 357 |
$post = $server->get_params(); |
| 358 |
$id = isset($post['id'])? ultimate_post()->ultp_rest_sanitize_params($post['id']):''; |
| 359 |
$action = isset($post['action'])? ultimate_post()->ultp_rest_sanitize_params($post['action']):''; |
| 360 |
$wishListArr = get_option('ultp_premade_wishlist', []); |
| 361 |
$request_type = isset($post['type'])?ultimate_post()->ultp_rest_sanitize_params($post['type']):''; |
| 362 |
|
| 363 |
if ($id && $request_type != 'fetchData') { |
| 364 |
if($action == 'remove') { |
| 365 |
$index = array_search($id, $wishListArr); |
| 366 |
if ($index !== false) { |
| 367 |
unset($wishListArr[$index]); |
| 368 |
} |
| 369 |
} else { |
| 370 |
if (!in_array($id, $wishListArr)) { |
| 371 |
array_push($wishListArr, $id ); |
| 372 |
} |
| 373 |
} |
| 374 |
update_option('ultp_premade_wishlist', $wishListArr); |
| 375 |
} |
| 376 |
return rest_ensure_response([ |
| 377 |
'success' => true, |
| 378 |
'message' => $action == 'remove' ? __('Item has been removed from wishlist.', 'ultimate-post') : __('Item added to wishlist.', 'ultimate-post'), |
| 379 |
'wishListArr' => wp_json_encode($wishListArr)] |
| 380 |
); |
| 381 |
} |
| 382 |
/** |
| 383 |
* Save addon / blocks on/off data |
| 384 |
* |
| 385 |
* @since v.3.0.0 |
| 386 |
* @param STRING |
| 387 |
* @return ARRAY | Inserted Post Url |
| 388 |
*/ |
| 389 |
public function addon_block_action($server) { |
| 390 |
$post = $server->get_params(); |
| 391 |
$addon_name = isset($post['key'])? ultimate_post()->ultp_rest_sanitize_params($post['key']):''; |
| 392 |
$addon_value = isset($post['value'])? ultimate_post()->ultp_rest_sanitize_params($post['value']):''; |
| 393 |
if ($addon_name) { |
| 394 |
$addon_data = ultimate_post()->get_setting(); |
| 395 |
$addon_data[$addon_name] = $addon_value; |
| 396 |
$GLOBALS['ultp_settings'][$addon_name] = $addon_value; |
| 397 |
update_option('ultp_options', $addon_data); |
| 398 |
} |
| 399 |
return array( |
| 400 |
'success' => true, |
| 401 |
'message' => ($addon_value == 'true' || $addon_value == 'false') ? ($addon_value == 'true' ? __('The addon has been enabled.', 'ultimate-post') : __('The addon has been disabled.', 'ultimate-post') ) : ($addon_value == 'yes' ? __('The block has been enabled.', 'ultimate-post') : __('The block has been disabled.', 'ultimate-post')) |
| 402 |
); |
| 403 |
} |
| 404 |
/** |
| 405 |
* Saved Template & Custom Font Actions |
| 406 |
* |
| 407 |
* @since v.3.0.0 |
| 408 |
* @param STRING |
| 409 |
* @return ARRAY | Inserted Post Url |
| 410 |
*/ |
| 411 |
public function get_dashboard_callback($server) { |
| 412 |
$post = $server->get_params(); |
| 413 |
$request_type = isset($post['type'])?ultimate_post()->ultp_rest_sanitize_params($post['type']):''; |
| 414 |
$pType = isset($post['pType'])?ultimate_post()->ultp_rest_sanitize_params($post['pType']):''; |
| 415 |
switch ($request_type) { |
| 416 |
|
| 417 |
case 'saved_templates': |
| 418 |
$post_per_page = 10; |
| 419 |
$data = []; |
| 420 |
$args = array( |
| 421 |
'post_type' => $pType, |
| 422 |
'post_status' => array('publish', 'draft'), |
| 423 |
'posts_per_page' => $post_per_page, |
| 424 |
'paged' => isset($post['pages'])?ultimate_post()->ultp_rest_sanitize_params($post['pages']):1 |
| 425 |
); |
| 426 |
|
| 427 |
if (isset($post['search'])) { |
| 428 |
$args['paged'] = 1; |
| 429 |
$args['s'] = ultimate_post()->ultp_rest_sanitize_params($post['search']); |
| 430 |
} |
| 431 |
|
| 432 |
$the_query = new \WP_Query( $args ); |
| 433 |
if ( $the_query->have_posts() ) { |
| 434 |
while ( $the_query->have_posts() ) { |
| 435 |
$the_query->the_post(); |
| 436 |
$final = [ |
| 437 |
'id' => get_the_ID(), |
| 438 |
'title' => get_the_title(), |
| 439 |
'date' => get_the_modified_date('Y/m/d h:i a'), |
| 440 |
'status' => get_post_status(), |
| 441 |
'edit' => get_edit_post_link() |
| 442 |
]; |
| 443 |
|
| 444 |
if ($pType == 'ultp_custom_font') { |
| 445 |
$final = array_merge($final ,['woff' => false,'woff2' => false,'ttf' => false,'svg' => false,'eot' => false]); |
| 446 |
$settings = get_post_meta( get_the_ID(), '__font_settings', true ); |
| 447 |
foreach ($settings as $key => $value) { |
| 448 |
if ($value['ttf']) { $final['ttf'] = true; } |
| 449 |
if ($value['svg']) { $final['svg'] = true; } |
| 450 |
if ($value['eot']) { $final['eot'] = true; } |
| 451 |
if ($value['woff']) { $final['woff'] = true; } |
| 452 |
if ($value['woff2']) { $final['woff2'] = true; } |
| 453 |
} |
| 454 |
$final['font_settings'] = $settings; |
| 455 |
} |
| 456 |
$data[] = $final; |
| 457 |
} |
| 458 |
} |
| 459 |
wp_reset_postdata(); |
| 460 |
return array( |
| 461 |
'success' => true, |
| 462 |
'data' => $data, |
| 463 |
'new' => ($pType == 'ultp_custom_font' ? admin_url('post-new.php?post_type=ultp_custom_font') : admin_url('post-new.php?post_type=ultp_templates')), |
| 464 |
'found' => $the_query->found_posts, |
| 465 |
'pages' => $the_query->max_num_pages |
| 466 |
); |
| 467 |
break; |
| 468 |
|
| 469 |
case 'action_draft': |
| 470 |
case 'action_publish': |
| 471 |
if (isset($post['ids']) && is_array($post['ids'])) { |
| 472 |
$post_ids = ultimate_post()->ultp_rest_sanitize_params($post['ids']); |
| 473 |
foreach ($post_ids as $id) { |
| 474 |
wp_update_post(array( |
| 475 |
'ID' => $id, |
| 476 |
'post_status' => str_replace('action_', '',$request_type) |
| 477 |
)); |
| 478 |
} |
| 479 |
return array( |
| 480 |
'success' => true, |
| 481 |
'message' => __('Status changed for selected items.', 'ultimate-post') |
| 482 |
); |
| 483 |
} |
| 484 |
break; |
| 485 |
|
| 486 |
case 'license_action': |
| 487 |
$message = ''; |
| 488 |
|
| 489 |
if ( isset($post['edd_ultp_license_key']) && function_exists('ultimate_post_pro') ) { |
| 490 |
$is_success = false; |
| 491 |
$license = trim( ultimate_post()->ultp_rest_sanitize_params( $post['edd_ultp_license_key'] ) ); |
| 492 |
|
| 493 |
if ($license && $license != '******************') { |
| 494 |
update_option( 'edd_ultp_license_key', $license); |
| 495 |
$api_params = array( |
| 496 |
'edd_action' => 'activate_license', |
| 497 |
'license' => $license, |
| 498 |
'item_id' => 181, |
| 499 |
'url' => home_url() |
| 500 |
); |
| 501 |
|
| 502 |
$response = wp_remote_post( |
| 503 |
'https://www.wpxpo.com', |
| 504 |
array( |
| 505 |
'timeout' => 15, |
| 506 |
'sslverify' => false, |
| 507 |
'body' => $api_params |
| 508 |
) |
| 509 |
); |
| 510 |
|
| 511 |
if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { |
| 512 |
$message = ( is_wp_error( $response ) && ! empty( $response->get_error_message() ) ) ? $response->get_error_message() : __('An error occurred, please try again.', 'ultimate-post-pro'); |
| 513 |
} else { |
| 514 |
$license_data = json_decode( wp_remote_retrieve_body( $response ) ); |
| 515 |
if ( false === $license_data->success ) { |
| 516 |
update_option( 'edd_ultp_license_key', ''); |
| 517 |
switch( $license_data->error ) { |
| 518 |
case 'expired' : |
| 519 |
$message = sprintf( |
| 520 |
__('Your license key expired on %s.', 'ultimate-post'), |
| 521 |
date_i18n( get_option( 'date_format' ), strtotime( $license_data->expires, current_time( 'timestamp' ) ) ) |
| 522 |
); |
| 523 |
break; |
| 524 |
case 'revoked' : |
| 525 |
$message = __('Your license key has been disabled.', 'ultimate-post'); |
| 526 |
break; |
| 527 |
case 'missing' : |
| 528 |
$message = __('Invalid license.', 'ultimate-post'); |
| 529 |
break; |
| 530 |
case 'invalid' : |
| 531 |
case 'site_inactive': |
| 532 |
$message = __( 'Your license is not active for this URL.', 'ultimate-post' ); |
| 533 |
break; |
| 534 |
case 'item_name_mismatch': |
| 535 |
$message = __( 'This appears to be an invalid license key.', 'ultimate-post' ); |
| 536 |
break; |
| 537 |
case 'no_activations_left': |
| 538 |
$message = __( 'Your license key has reached its activation limit.', 'ultimate-post' ); |
| 539 |
break; |
| 540 |
default : |
| 541 |
$message = __( 'An error occurred, please try again.', 'ultimate-post' ); |
| 542 |
break; |
| 543 |
} |
| 544 |
} else { |
| 545 |
$message = __('Your license key has been updated.', 'ultimate-post'); |
| 546 |
$is_success = true; |
| 547 |
} |
| 548 |
update_option( 'edd_ultp_license_status', $license_data->license ); |
| 549 |
update_option( 'edd_ultp_license_expire', $license_data->expires ); |
| 550 |
update_option( 'edd_ultp_activations_left', $license_data->activations_left ); |
| 551 |
|
| 552 |
} |
| 553 |
} else { |
| 554 |
$message = __( 'Invalid license.', 'ultimate-post' ); |
| 555 |
} |
| 556 |
} else { |
| 557 |
$message = __( 'Invalid license.', 'ultimate-post' ); |
| 558 |
if (!function_exists('ultimate_post_pro')) { |
| 559 |
$message = __( 'Install & Acivate PostX Pro plugin.', 'ultimate-post' ); |
| 560 |
} |
| 561 |
} |
| 562 |
return array('success' => $is_success, 'message' => $message); |
| 563 |
break; |
| 564 |
|
| 565 |
case 'action_delete': |
| 566 |
if (isset($post['ids']) && is_array($post['ids'])) { |
| 567 |
$post_ids = ultimate_post()->ultp_rest_sanitize_params($post['ids']); |
| 568 |
foreach ($post_ids as $id) { |
| 569 |
wp_delete_post( $id, true); |
| 570 |
} |
| 571 |
} |
| 572 |
return array( |
| 573 |
'success' => true, |
| 574 |
'message' => __('The selected item is deleted.', 'ultimate-post') |
| 575 |
); |
| 576 |
|
| 577 |
case 'support_data': |
| 578 |
$user_info = get_userdata( get_current_user_id() ); |
| 579 |
$name = $user_info->first_name . ($user_info->last_name ? ' ' . $user_info->last_name : ''); |
| 580 |
return array( |
| 581 |
'success' => true, |
| 582 |
'data' => array( |
| 583 |
'name' => $name ? $name : $user_info->user_login, |
| 584 |
'email' => $user_info->user_email |
| 585 |
) |
| 586 |
); |
| 587 |
|
| 588 |
case 'support_action': |
| 589 |
$api_params = array( |
| 590 |
'user_name' => isset($post['name'])? ultimate_post()->ultp_rest_sanitize_params($post['name']):'', |
| 591 |
'user_email' =>isset($post['email'])? sanitize_email($post['email']):'', |
| 592 |
'subject' => isset($post['subject'])? ultimate_post()->ultp_rest_sanitize_params($post['subject']):'', |
| 593 |
'desc' => isset($post['desc'])? sanitize_textarea_field($post['desc']):'', |
| 594 |
); |
| 595 |
$response = wp_remote_get( |
| 596 |
'https://wpxpo.com/wp-json/v2/support_mail', |
| 597 |
array( |
| 598 |
'method' => 'POST', |
| 599 |
'timeout' => 120, |
| 600 |
'body' => $api_params |
| 601 |
) |
| 602 |
); |
| 603 |
$response_data = json_decode($response['body']); |
| 604 |
$success = ( isset($response_data->success) && $response_data->success ) ? true : false; |
| 605 |
|
| 606 |
return array( |
| 607 |
'success' => $success, |
| 608 |
'message' => $success ? __('New Support Ticket has been Created.', 'ultimate-post') : __('New Support Ticket is not Created Due to Some Issues.', 'ultimate-post') |
| 609 |
); |
| 610 |
break; |
| 611 |
|
| 612 |
case 'helloBarAction': |
| 613 |
set_transient( 'ultp_helloBar'.ULTP_HELLOBAR, 'hide', 1296000); |
| 614 |
return array( |
| 615 |
'success' => true, |
| 616 |
'message' => __('Notice is removed.', 'ultimate-post') |
| 617 |
); |
| 618 |
break; |
| 619 |
case 'generalDiscountAction': |
| 620 |
set_transient( 'ultp_generalDiscount', 'hide', 60 * DAY_IN_SECONDS); |
| 621 |
return array( |
| 622 |
'success' => true, |
| 623 |
'message' => __('Notice is removed.', 'ultimate-post') |
| 624 |
); |
| 625 |
break; |
| 626 |
|
| 627 |
default: |
| 628 |
# code... |
| 629 |
break; |
| 630 |
} |
| 631 |
|
| 632 |
} |
| 633 |
|
| 634 |
/** |
| 635 |
* Insert Post For Imported Template |
| 636 |
* |
| 637 |
* @since v.2.6.7 |
| 638 |
* @param STRING |
| 639 |
* @return ARRAY | Inserted Post Url |
| 640 |
*/ |
| 641 |
public function template_page_insert($server) { |
| 642 |
$post = $server->get_params(); |
| 643 |
$new_page = array( |
| 644 |
'post_title' => isset($post['title'])?ultimate_post()->ultp_rest_sanitize_params($post['title']):'', |
| 645 |
'post_type' => 'page', |
| 646 |
'post_content' => $post['blockCode'], |
| 647 |
'post_status' => 'draft', |
| 648 |
); |
| 649 |
$post_id = wp_insert_post( $new_page ); |
| 650 |
return array( 'success' => true, 'link' => get_edit_post_link($post_id)); |
| 651 |
} |
| 652 |
|
| 653 |
|
| 654 |
public function search_settings_action($server) { |
| 655 |
global $wpdb; |
| 656 |
$post = $server->get_params(); |
| 657 |
$request_type = isset($post['type'])?ultimate_post()->ultp_rest_sanitize_params($post['type']):''; |
| 658 |
$condition_type = isset($post['condition'])?ultimate_post()->ultp_rest_sanitize_params($post['condition']):''; |
| 659 |
$term_type = isset($post['term'])?ultimate_post()->ultp_rest_sanitize_params( $post['term'] ):''; |
| 660 |
switch ($request_type) { |
| 661 |
case 'posts': |
| 662 |
case 'allpost': |
| 663 |
case 'postExclude': |
| 664 |
$post_type = array('post'); |
| 665 |
if ($request_type == 'allpost') { |
| 666 |
$post_type = array_keys(ultimate_post()->get_post_type()); |
| 667 |
} else if ($request_type == 'postExclude') { |
| 668 |
$post_type = array($condition_type); |
| 669 |
} |
| 670 |
$args = array( |
| 671 |
'post_type' => $post_type, |
| 672 |
'post_status' => 'publish', |
| 673 |
'posts_per_page' => 10, |
| 674 |
); |
| 675 |
if (is_numeric($term_type)) { |
| 676 |
$args['p'] = $term_type; |
| 677 |
} else { |
| 678 |
$args['s'] = $term_type; |
| 679 |
} |
| 680 |
|
| 681 |
$post_results = new \WP_Query($args); |
| 682 |
$data = []; |
| 683 |
if (!empty($post_results)) { |
| 684 |
while ( $post_results->have_posts() ) { |
| 685 |
$post_results->the_post(); |
| 686 |
$id = get_the_ID(); |
| 687 |
$title = html_entity_decode(get_the_title()); |
| 688 |
$data[] = array('value'=>$id, 'title'=>($title?'[ID: '.$id.'] '.$title:('[ID: '.$id.']'))); |
| 689 |
} |
| 690 |
wp_reset_postdata(); |
| 691 |
} |
| 692 |
return ['success' => true, 'data' => $data]; |
| 693 |
break; |
| 694 |
|
| 695 |
case 'author': |
| 696 |
$term = '%'. $wpdb->esc_like( $term_type ) .'%'; |
| 697 |
$post_results = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching |
| 698 |
$wpdb->prepare( |
| 699 |
"SELECT ID, display_name |
| 700 |
FROM $wpdb->users |
| 701 |
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 |
| 702 |
) |
| 703 |
); |
| 704 |
$data = []; |
| 705 |
if (!empty($post_results)) { |
| 706 |
foreach ($post_results as $key => $val) { |
| 707 |
$data[] = array('value'=>$val->ID, 'title'=>'[ID: '.$val->ID.'] '.$val->display_name); |
| 708 |
} |
| 709 |
} |
| 710 |
return ['success' => true, 'data' => $data]; |
| 711 |
break; |
| 712 |
|
| 713 |
case 'taxvalue': |
| 714 |
$split = explode('###', $condition_type); |
| 715 |
$condition = $split[1] != 'multiTaxonomy' ? array($split[1]) : get_object_taxonomies($split[0]); |
| 716 |
$args = array( |
| 717 |
'taxonomy' => $condition, |
| 718 |
'fields' => 'all', |
| 719 |
'orderby' => 'id', |
| 720 |
'order' => 'ASC', |
| 721 |
'name__like'=> $term_type |
| 722 |
); |
| 723 |
if (is_numeric($term_type)) { |
| 724 |
unset($args['name__like']); |
| 725 |
$args['include'] = array($term_type); |
| 726 |
} |
| 727 |
|
| 728 |
$post_results = get_terms( $args ); |
| 729 |
$data = []; |
| 730 |
if (!empty($post_results)) { |
| 731 |
foreach ($post_results as $key => $val) { |
| 732 |
if ($split[1] == 'multiTaxonomy') { |
| 733 |
$data[] = array('value'=>$val->taxonomy.'###'.$val->slug, 'title'=> '[ID: '.$val->term_id.'] '.$val->taxonomy.': '.$val->name); |
| 734 |
} else { |
| 735 |
$data[] = array('value'=>urldecode($val->slug), 'title'=>'[ID: '.$val->term_id.'] '.$val->name, 'live_title'=> $val->name); |
| 736 |
} |
| 737 |
} |
| 738 |
} |
| 739 |
return ['success' => true, 'data' => $data]; |
| 740 |
break; |
| 741 |
|
| 742 |
case 'taxExclude': |
| 743 |
$condition = get_object_taxonomies($condition_type); |
| 744 |
$args = array( |
| 745 |
'taxonomy' => $condition, |
| 746 |
'fields' => 'all', |
| 747 |
'orderby' => 'id', |
| 748 |
'order' => 'ASC', |
| 749 |
'name__like'=> $term_type |
| 750 |
); |
| 751 |
if (is_numeric($term_type)) { |
| 752 |
unset($args['name__like']); |
| 753 |
$args['include'] = array($term_type); |
| 754 |
} |
| 755 |
$post_results = get_terms( $args ); |
| 756 |
$data = []; |
| 757 |
if (!empty($post_results)) { |
| 758 |
foreach ($post_results as $key => $val) { |
| 759 |
$data[] = array('value'=>$val->taxonomy.'###'.$val->slug, 'title'=> '[ID: '.$val->term_id.'] '.$val->taxonomy.': '.$val->name); |
| 760 |
} |
| 761 |
} |
| 762 |
return ['success' => true, 'data' => $data]; |
| 763 |
break; |
| 764 |
// allPostType |
| 765 |
case 'allPostType': |
| 766 |
$all_types = array_values(get_post_types( array( 'public' => true ), 'names' )); |
| 767 |
$postType = array(); |
| 768 |
foreach($all_types as $type){ |
| 769 |
$postType[] = array( |
| 770 |
'title' => $type, |
| 771 |
'value' => $type, |
| 772 |
); |
| 773 |
}; |
| 774 |
|
| 775 |
return ['success' => true, 'data' => $postType ]; |
| 776 |
default: |
| 777 |
return ['success' => true, 'data' => [['value'=>'', 'title'=>'- Select -']]]; |
| 778 |
break; |
| 779 |
} |
| 780 |
} |
| 781 |
|
| 782 |
/** |
| 783 |
* Post Data Response of REST API |
| 784 |
* |
| 785 |
* @since v.1.0.0 |
| 786 |
* @param MIXED | Pram (ARRAY), Local (BOOLEAN) |
| 787 |
* @return ARRAY | Response Image Size as Array |
| 788 |
*/ |
| 789 |
public function ultp_route_post_data($prams) { |
| 790 |
if ( ! (isset($_REQUEST['wpnonce']) && wp_verify_nonce( sanitize_key(wp_unslash($_REQUEST['wpnonce'])), 'ultp-nonce' )) ) { |
| 791 |
die(); |
| 792 |
} |
| 793 |
$prams = $prams->get_params(); |
| 794 |
$data = []; |
| 795 |
$loop = new \WP_Query( ultimate_post()->get_query(ultimate_post()->ultp_rest_sanitize_params($prams)) ); |
| 796 |
$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 ; |
| 797 |
|
| 798 |
|
| 799 |
if ($loop->have_posts()) { |
| 800 |
while($loop->have_posts()) { |
| 801 |
$loop->the_post(); |
| 802 |
$var = array(); |
| 803 |
$post_id = get_the_ID(); |
| 804 |
$user_id = get_the_author_meta('ID'); |
| 805 |
$content_data = get_the_content(); |
| 806 |
$var['ID'] = $post_id; |
| 807 |
$var['title'] = get_the_title(); |
| 808 |
$var['permalink'] = get_permalink(); |
| 809 |
$var['seo_meta'] = ultimate_post()->get_excerpt($post_id, 1); |
| 810 |
$var['excerpt'] = wp_strip_all_tags($content_data); |
| 811 |
$var['excerpt_full']= wp_strip_all_tags(get_the_excerpt()); |
| 812 |
$var['time'] = (int)get_the_date('U')*1000; |
| 813 |
$var['timeModified']= (int)get_the_modified_date('U')*1000; |
| 814 |
$var['post_time'] = human_time_diff(get_the_time('U'),current_time('U')); |
| 815 |
$var['view'] = get_post_meta(get_the_ID(),'__post_views_count', true); |
| 816 |
$var['comments'] = get_comments_number(); |
| 817 |
$var['author_link'] = get_author_posts_url($user_id); |
| 818 |
$var['avatar_url'] = get_avatar_url($user_id); |
| 819 |
$var['display_name']= get_the_author_meta('display_name'); |
| 820 |
$var['reading_time']= ceil(strlen($content_data)/1200); |
| 821 |
$post_video = get_post_meta($post_id, '__builder_feature_video', true); |
| 822 |
// Video |
| 823 |
if ($post_video) { |
| 824 |
$var['has_video'] = ultimate_post()->get_youtube_id($post_video); |
| 825 |
} |
| 826 |
// image |
| 827 |
$image_sizes = ultimate_post()->get_image_size(); |
| 828 |
$image_src = array(); |
| 829 |
if (has_post_thumbnail()) { |
| 830 |
$thumb_id = get_post_thumbnail_id($post_id); |
| 831 |
foreach ($image_sizes as $key => $value) { |
| 832 |
$image_src[$key] = wp_get_attachment_image_src($thumb_id, $key, false)[0]; |
| 833 |
} |
| 834 |
$var['image'] = $image_src; |
| 835 |
} elseif(isset($prams['fallbackImg']['id'])) { |
| 836 |
foreach ($image_sizes as $key => $value) { |
| 837 |
$image_src[$key] = wp_get_attachment_image_src(esc_attr($prams['fallbackImg']['id']), $key, false)[0]; |
| 838 |
} |
| 839 |
$var['image'] = $image_src; |
| 840 |
$var['is_fallback'] = true; |
| 841 |
} |
| 842 |
|
| 843 |
// tag |
| 844 |
$tag = get_the_terms($post_id, (isset($prams['tag'])?esc_attr($prams['tag']):'post_tag')); |
| 845 |
if (!empty($tag)) { |
| 846 |
$v = array(); |
| 847 |
foreach ($tag as $k => $val) { |
| 848 |
if ($k >= $max_tax) { break; } |
| 849 |
$v[] = array('slug' => $val->slug, 'name' => $val->name, 'url' => get_term_link($val->term_id)); |
| 850 |
} |
| 851 |
$var['tag'] = $v; |
| 852 |
} |
| 853 |
|
| 854 |
// Taxonomy |
| 855 |
$cat = get_the_terms($post_id, (isset($prams['taxonomy'])?esc_attr($prams['taxonomy']):'category')); |
| 856 |
|
| 857 |
if(!empty($cat)){ |
| 858 |
$v = array(); |
| 859 |
foreach ($cat as $k => $val) { |
| 860 |
if ($k >= $max_tax) { break; } |
| 861 |
$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)); |
| 862 |
} |
| 863 |
$var['category'] = $v; |
| 864 |
} |
| 865 |
$data[] = $var; |
| 866 |
} |
| 867 |
wp_reset_postdata(); |
| 868 |
} |
| 869 |
return rest_ensure_response( $data); |
| 870 |
} |
| 871 |
|
| 872 |
|
| 873 |
/** |
| 874 |
* Taxonomy Data Response of REST API |
| 875 |
* |
| 876 |
* @since v.1.0.0 |
| 877 |
* @param ARRAY | Parameter (ARRAY) |
| 878 |
* @return ARRAY | Response Taxonomy List as Array |
| 879 |
*/ |
| 880 |
public function ultp_route_common_data($prams) { |
| 881 |
if ( ! (isset($_REQUEST['wpnonce']) && wp_verify_nonce( sanitize_key(wp_unslash($_REQUEST['wpnonce'])), 'ultp-nonce' )) ) { |
| 882 |
return rest_ensure_response([]); |
| 883 |
} |
| 884 |
|
| 885 |
$all_post_type = ultimate_post()->get_post_type(); |
| 886 |
$data = array(); |
| 887 |
foreach ($all_post_type as $post_type_slug => $post_type ) { |
| 888 |
$data_term = array(); |
| 889 |
$taxonomies = get_object_taxonomies($post_type_slug); |
| 890 |
foreach ($taxonomies as $key => $taxonomy_slug) { |
| 891 |
$taxonomy_value = get_terms(array( |
| 892 |
'taxonomy' => $taxonomy_slug, |
| 893 |
'hide_empty' => false |
| 894 |
)); |
| 895 |
if (!is_wp_error($taxonomy_value)) { |
| 896 |
$data_tax = array(); |
| 897 |
foreach ($taxonomy_value as $k => $taxonomy) { |
| 898 |
$data_tax[urldecode_deep($taxonomy->slug)] = $taxonomy->name; |
| 899 |
} |
| 900 |
if (count($data_tax) > 0) { |
| 901 |
$data_term[$taxonomy_slug] = $data_tax; |
| 902 |
} |
| 903 |
} |
| 904 |
} |
| 905 |
$data[$post_type_slug] = $data_term; |
| 906 |
} |
| 907 |
// Global Customizer |
| 908 |
$global = get_option('postx_global', []); |
| 909 |
// Image Size |
| 910 |
$image_sizes = ultimate_post()->get_image_size(); |
| 911 |
|
| 912 |
return rest_ensure_response(['taxonomy' => $data, 'global' => $global, 'image' => wp_json_encode($image_sizes), 'posttype' => wp_json_encode($all_post_type)]); |
| 913 |
} |
| 914 |
|
| 915 |
/** |
| 916 |
* Specific Taxonomy Data Response of REST API |
| 917 |
* |
| 918 |
* @since v.1.0.0 |
| 919 |
* @param ARRAY | Parameter (ARRAY) |
| 920 |
* @return ARRAY | Response Taxonomy List as Array |
| 921 |
*/ |
| 922 |
public function ultp_route_taxonomy_info_data($prams) { |
| 923 |
if ( ! (isset($_REQUEST['wpnonce']) && wp_verify_nonce( sanitize_key(wp_unslash($_REQUEST['wpnonce'])), 'ultp-nonce' )) ) { |
| 924 |
return rest_ensure_response([]); |
| 925 |
} |
| 926 |
$taxValue = isset($prams['taxValue'])?ultimate_post()->ultp_rest_sanitize_params($prams['taxValue']):''; |
| 927 |
$queryNumber = isset($prams['queryNumber'])?ultimate_post()->ultp_rest_sanitize_params($prams['queryNumber']):''; |
| 928 |
$taxType = isset($prams['taxType'])?ultimate_post()->ultp_rest_sanitize_params($prams['taxType']):''; |
| 929 |
$taxSlug = isset($prams['taxSlug'])?ultimate_post()->ultp_rest_sanitize_params($prams['taxSlug']):''; |
| 930 |
$archiveBuilder = isset($prams['archiveBuilder'])?ultimate_post()->ultp_rest_sanitize_params($prams['archiveBuilder']):''; |
| 931 |
|
| 932 |
return rest_ensure_response( ultimate_post()->get_category_data(json_decode($taxValue), $queryNumber, $taxType, $taxSlug, $archiveBuilder) ); |
| 933 |
} |
| 934 |
|
| 935 |
/** |
| 936 |
* Search Block Data Showing |
| 937 |
* |
| 938 |
* @since v.2.9.9 |
| 939 |
* @param STRING |
| 940 |
* @return ARRAY | Inserted Post Url |
| 941 |
*/ |
| 942 |
public function ultp_search_result($server) { |
| 943 |
$post = $server->get_params(); |
| 944 |
$searchText = isset($post['searchText'])?ultimate_post()->ultp_rest_sanitize_params($post['searchText']):''; |
| 945 |
$paged = isset($post['paged'])?ultimate_post()->ultp_rest_sanitize_params($post['paged']):''; |
| 946 |
$postPerPage = isset($post['postPerPage'])?ultimate_post()->ultp_rest_sanitize_params($post['postPerPage']):''; |
| 947 |
$query_args = array( |
| 948 |
's' => $searchText, |
| 949 |
'paged' => $paged, |
| 950 |
'compare' => 'LIKE', |
| 951 |
'orderby' => 'relevance', |
| 952 |
'posts_per_page' => $postPerPage, |
| 953 |
); |
| 954 |
if(isset($post['exclude']) && is_array($post['exclude']) && count($post['exclude']) > 0) { |
| 955 |
$post['exclude'] = ultimate_post()->ultp_rest_sanitize_params($post['exclude']); |
| 956 |
$post_exclude = array(); |
| 957 |
foreach( $post['exclude'] as $data ){ |
| 958 |
$post_exclude[$data['title']] = $data['title']; |
| 959 |
} |
| 960 |
$all_types = get_post_types( array( 'public' => true ), 'names' ); |
| 961 |
$post_type = array_diff_key($all_types, $post_exclude); |
| 962 |
$query_args['post_type'] = $post_type; |
| 963 |
} |
| 964 |
$output = ''; |
| 965 |
$query_result = new \WP_Query($query_args); |
| 966 |
|
| 967 |
if ($query_result->have_posts()) { |
| 968 |
while ($query_result->have_posts()) { |
| 969 |
$query_result->the_post(); |
| 970 |
$post_id = get_the_ID(); |
| 971 |
$title = get_the_title(); |
| 972 |
|
| 973 |
$output .= '<div class="ultp-search-result__item">'; |
| 974 |
if ($post['image'] == 1 && has_post_thumbnail()) { |
| 975 |
$thumb_id = get_post_thumbnail_id($post_id); |
| 976 |
$output .= '<img class="ultp-searchresult-image" src='.wp_get_attachment_image_src($thumb_id, 'thumbnail', false)[0].' alt="'.$title.'"/>'; |
| 977 |
} |
| 978 |
$output .= '<div class="ultp-searchresult-content">'; |
| 979 |
$output .= '<div class="ultp-rescontent-meta">'; |
| 980 |
// Category |
| 981 |
$post_cat = get_the_terms($post_id, 'category'); |
| 982 |
if ($post['category'] == 1 && $post_cat && count($post_cat)) { |
| 983 |
$output .= '<div class="ultp-searchresult-category">'; |
| 984 |
foreach($post_cat as $cat){ |
| 985 |
$output .= '<a href="'.get_term_link($cat->term_id).'">'.$cat->name.'</a>'; |
| 986 |
} |
| 987 |
$output .= '</div>'; |
| 988 |
} |
| 989 |
// Author |
| 990 |
if ($post['author'] == 1) { |
| 991 |
$user_id = get_the_author_meta('ID'); |
| 992 |
$output .= '<a href="'.get_author_posts_url($user_id).'" class="ultp-searchresult-author">'.get_the_author_meta('display_name').'</a>'; |
| 993 |
} |
| 994 |
// Date |
| 995 |
if ($post['date'] == 1) { |
| 996 |
$output .= '<div class="ultp-searchresult-publishdate">'.get_the_date('F j, Y').'</div>'; |
| 997 |
} |
| 998 |
$output .= '</div>'; |
| 999 |
$output .= '<a href="'.get_permalink().'" class="ultp-searchresult-title">'.$title.'</a>'; |
| 1000 |
if ($post['excerpt'] == 1) { |
| 1001 |
$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>'; |
| 1002 |
} |
| 1003 |
$output .= '</div>'; |
| 1004 |
$output .= '</div>'; |
| 1005 |
} |
| 1006 |
} |
| 1007 |
|
| 1008 |
return array('post_data' => $output, 'post_count' => $query_result->found_posts); |
| 1009 |
} |
| 1010 |
|
| 1011 |
/** |
| 1012 |
* PostX Site Dark Logo Init |
| 1013 |
* |
| 1014 |
* @since v.3.1.9 |
| 1015 |
* @param ARRAY |
| 1016 |
* @return BOOOLEAN | Inserted Post Url |
| 1017 |
*/ |
| 1018 |
public function init_site_dark_logo_callback ($server) { |
| 1019 |
$logo_data = $server->get_params(); |
| 1020 |
$success = true; |
| 1021 |
if( isset($logo_data['logo']['url'] ) ){ |
| 1022 |
update_option( 'ultp_site_dark_logo', $logo_data['logo']['url'] ); |
| 1023 |
} else { |
| 1024 |
$success = false; |
| 1025 |
} |
| 1026 |
return rest_ensure_response([ |
| 1027 |
'success' => $success, |
| 1028 |
]); |
| 1029 |
} |
| 1030 |
|
| 1031 |
|
| 1032 |
/** |
| 1033 |
* Getting Image Size |
| 1034 |
* |
| 1035 |
* @since v.4.0.1 |
| 1036 |
* @param ARRAY | Parameter (number) |
| 1037 |
* @return ARRAY | Image Size List as Array |
| 1038 |
*/ |
| 1039 |
public function get_custom_image_size($server) { |
| 1040 |
$img = $server->get_params(); |
| 1041 |
$image_src = array(); |
| 1042 |
$image_sizes = ultimate_post()->get_image_size(); |
| 1043 |
foreach ($image_sizes as $key => $value) { |
| 1044 |
$image_src[$key] = wp_get_attachment_image_src($img['id'], $key, false)[0]; |
| 1045 |
} |
| 1046 |
return rest_ensure_response( ['success' => true, 'size' => $image_src, 'id' => $img ]); |
| 1047 |
} |
| 1048 |
} |