API
3 weeks ago
Admin
1 month ago
Ajax
1 week ago
ExportImport
1 week ago
FormValidator
4 months ago
Frontend
4 days ago
Manager
1 week ago
API.php
1 month ago
Admin.php
4 months ago
Ajax.php
1 week ago
Apps.php
1 month ago
ContentManager.php
4 months ago
DbQueryUtils.php
3 months ago
ElementVisibilityConditions.php
4 months ago
Frontend.php
4 months ago
HelperFunctions.php
1 week ago
KirkiBase.php
1 month ago
PostsQueryUtils.php
4 months ago
Staging.php
4 weeks ago
View.php
2 months ago
Ajax.php
937 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * All Ajax/API calls will goes here |
| 5 | * |
| 6 | * @package kirki |
| 7 | */ |
| 8 | |
| 9 | namespace Kirki; |
| 10 | |
| 11 | if (!defined('ABSPATH')) { |
| 12 | exit; // Exit if accessed directly. |
| 13 | } |
| 14 | |
| 15 | use Kirki\Ajax\Apps; |
| 16 | use Kirki\Ajax\Collaboration\Collaboration; |
| 17 | use Kirki\Ajax\DynamicContent; |
| 18 | use Kirki\Ajax\Media; |
| 19 | use Kirki\Ajax\Page; |
| 20 | use Kirki\Ajax\PageSettings; |
| 21 | use Kirki\Ajax\Symbol; |
| 22 | use Kirki\Ajax\UserData; |
| 23 | use Kirki\Ajax\Walkthrough; |
| 24 | use Kirki\Ajax\WordpressData; |
| 25 | use Kirki\Ajax\Collection; |
| 26 | use Kirki\Ajax\ExportImport; |
| 27 | use Kirki\Ajax\Comments; |
| 28 | use Kirki\Ajax\WpAdmin; |
| 29 | use Kirki\Ajax\Form; |
| 30 | use Kirki\Ajax\RBAC; |
| 31 | use Kirki\Ajax\Taxonomy; |
| 32 | use Kirki\Ajax\Users; |
| 33 | use Kirki\Ajax\TemplateExportImport; |
| 34 | |
| 35 | /** |
| 36 | * Kirki Ajax handler |
| 37 | */ |
| 38 | class Ajax |
| 39 | { |
| 40 | |
| 41 | |
| 42 | /** |
| 43 | * Initialize the class |
| 44 | * |
| 45 | * @return void |
| 46 | */ |
| 47 | public function __construct() |
| 48 | { |
| 49 | /** |
| 50 | * Manage Post API call's from Builder |
| 51 | */ |
| 52 | add_action('wp_ajax_kirki_get_apis', array($this, 'kirki_get_apis')); |
| 53 | add_action('wp_ajax_kirki_post_apis', array($this, 'kirki_post_apis')); |
| 54 | |
| 55 | // add_action('wp_ajax_nopriv_kirki_post_apis_nopriv', array($this, 'kirki_post_apis_nopriv')); |
| 56 | add_action('wp_ajax_nopriv_kirki_get_apis', array($this, 'kirki_get_apis')); |
| 57 | /** |
| 58 | * Manage Post API call's from WP Admin |
| 59 | */ |
| 60 | add_action('wp_ajax_kirki_wp_admin_get_apis', array($this, 'kirki_wp_admin_get_apis')); |
| 61 | add_action('wp_ajax_kirki_wp_admin_post_apis', array($this, 'kirki_wp_admin_post_apis')); |
| 62 | add_action('wp_ajax_nopriv_kirki_wp_admin_get_apis', array($this, 'kirki_wp_admin_unauthorized')); |
| 63 | add_action('wp_ajax_nopriv_kirki_wp_admin_post_apis', array($this, 'kirki_wp_admin_unauthorized')); |
| 64 | |
| 65 | /** |
| 66 | * Manage Post API call's from Frontend (logged in not required) |
| 67 | */ |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Initialize post api |
| 72 | * |
| 73 | * @return void |
| 74 | */ |
| 75 | // public function kirki_post_apis_nopriv() |
| 76 | // { //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 77 | // $endpoint = HelperFunctions::sanitize_text(isset($_POST['endpoint']) ? $_POST['endpoint'] : null); |
| 78 | // if (!HelperFunctions::is_api_header_post_editor_preview_token_valid()) { |
| 79 | // wp_send_json_error('Not authorized'); |
| 80 | // } |
| 81 | // /** |
| 82 | // * Single SYMBOL API |
| 83 | // */ |
| 84 | // if ($endpoint === 'get-single-symbol') { |
| 85 | // Symbol::fetch_symbol(); |
| 86 | // die(); |
| 87 | // } |
| 88 | // } |
| 89 | |
| 90 | /** |
| 91 | * Initialize post api |
| 92 | * |
| 93 | * @return void |
| 94 | */ |
| 95 | public function kirki_post_apis() |
| 96 | { |
| 97 | HelperFunctions::verify_nonce('wp_rest'); |
| 98 | if (!is_admin()) { |
| 99 | wp_send_json_error('Not authorized'); |
| 100 | } |
| 101 | /** |
| 102 | * PAGE APIS |
| 103 | */ |
| 104 | |
| 105 | //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 106 | $endpoint = HelperFunctions::sanitize_text(isset($_POST['endpoint']) ? $_POST['endpoint'] : null); |
| 107 | |
| 108 | if (HelperFunctions::user_has_post_edit_access()) { |
| 109 | /** |
| 110 | * @deprecated |
| 111 | * @see POST /pages/{page_id}/{page_content_type} |
| 112 | */ |
| 113 | // if ( 'save-page-data' === $endpoint ) { |
| 114 | // Page::save_page_data(); |
| 115 | // } |
| 116 | |
| 117 | /** |
| 118 | * @deprecated |
| 119 | * @see POST /pages |
| 120 | */ |
| 121 | // if ( $endpoint === 'add-new-page' && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) { |
| 122 | // Page::add_new_page(); |
| 123 | // } |
| 124 | |
| 125 | /** |
| 126 | * @deprecated |
| 127 | * @see PUT /pages/{page_id} |
| 128 | * @see PUT /popups/{popup_id} |
| 129 | */ |
| 130 | // if ( $endpoint === 'update-page-data' ) { |
| 131 | // Page::update_page_data(); |
| 132 | // } |
| 133 | |
| 134 | /** |
| 135 | * @deprecated |
| 136 | * @see POST /toggle-disabled-page-symbols |
| 137 | */ |
| 138 | // if ( $endpoint === 'toggle-disabled-page-symbols' && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) { |
| 139 | // Page::toggle_disabled_page_symbols(); |
| 140 | // } |
| 141 | |
| 142 | // if ( $endpoint === 'remove-unused-style-block-from-db' && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) { |
| 143 | // Page::remove_unused_style_block_from_db(); |
| 144 | // } |
| 145 | |
| 146 | /** |
| 147 | * @deprecated |
| 148 | * @see POST /pages/{page_id}/duplicate |
| 149 | */ |
| 150 | // if ( $endpoint === 'duplicate-page' && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) { |
| 151 | // Page::duplicate_page(); |
| 152 | // } |
| 153 | |
| 154 | /** |
| 155 | * @deprecated |
| 156 | * @see DELETE /pages/{page_id} |
| 157 | */ |
| 158 | // if ( $endpoint === 'delete-page' && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) { |
| 159 | // Page::delete_page(); |
| 160 | // } |
| 161 | |
| 162 | /** |
| 163 | * @deprecated |
| 164 | * @see POST /back-to-kirki-editor |
| 165 | */ |
| 166 | // if ( $endpoint === 'back-to-kirki-editor' && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) { |
| 167 | // Page::back_to_kirki_editor(); |
| 168 | // } |
| 169 | |
| 170 | /** |
| 171 | * @deprecated |
| 172 | * @see POST /back-to-wordpress-editor |
| 173 | */ |
| 174 | // if ( $endpoint === 'back-to-wordpress-editor' && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) { |
| 175 | // Page::back_to_wordpress_editor(); |
| 176 | // } |
| 177 | |
| 178 | /** |
| 179 | * PAGE SETTINGS |
| 180 | * |
| 181 | * @deprecated |
| 182 | * @see PUT /pages/{page_id}/settings |
| 183 | */ |
| 184 | // if ( 'save-page-settings-data' === $endpoint && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) { |
| 185 | // PageSettings::save_page_setting_data(); |
| 186 | // } |
| 187 | |
| 188 | /** |
| 189 | * PAGE SETTINGS |
| 190 | * @deprecated |
| 191 | * @see PUT /custom-code-data |
| 192 | */ |
| 193 | // if ( 'save-custom-code-data' === $endpoint && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) { |
| 194 | // PageSettings::save_custom_code(); |
| 195 | // } |
| 196 | |
| 197 | /** |
| 198 | * USER APIS |
| 199 | */ |
| 200 | |
| 201 | /** |
| 202 | * @deprecated |
| 203 | * @see PUT /global-ui-controller |
| 204 | */ |
| 205 | // if ( $endpoint === 'save-user-controller' ) { |
| 206 | // UserData::save_user_controller(); |
| 207 | // } |
| 208 | |
| 209 | /** |
| 210 | * @deprecated |
| 211 | * @see PUT /global-ui-saved-data |
| 212 | */ |
| 213 | // if ( $endpoint === 'save-user-saved-data' ) { |
| 214 | // UserData::save_user_saved_data(); |
| 215 | // } |
| 216 | |
| 217 | /** |
| 218 | * @deprecated |
| 219 | * @see PUT /global-custom-fonts |
| 220 | */ |
| 221 | // if ( $endpoint === 'save-user-custom-fonts-data' && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) { |
| 222 | // UserData::save_user_custom_fonts_data(); |
| 223 | // } |
| 224 | |
| 225 | /** |
| 226 | * @deprecated |
| 227 | * @see POST /download-google-font-offline |
| 228 | */ |
| 229 | // if ( $endpoint === 'download-google-font-offline' && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) { |
| 230 | // UserData::make_google_font_offline(); |
| 231 | // } |
| 232 | |
| 233 | /** |
| 234 | * @deprecated |
| 235 | * @see DELETE /remove-google-font-offline |
| 236 | */ |
| 237 | // if ( $endpoint === 'remove-google-font-offline' && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) { |
| 238 | // UserData::remove_google_font_offline(); |
| 239 | // } |
| 240 | |
| 241 | /** |
| 242 | * SYMBOL SAVE API |
| 243 | */ |
| 244 | if ($endpoint === 'save-user-saved-symbol-data') { |
| 245 | Symbol::save(); |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * SYMBOL UPDATE API |
| 250 | */ |
| 251 | if ($endpoint === 'update-user-saved-symbol-data') { |
| 252 | Symbol::update(); |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * SYMBOL DELETE API |
| 257 | */ |
| 258 | if ($endpoint === 'delete-user-saved-symbol-data' && HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) { |
| 259 | Symbol::delete(); |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * MEDIA APIS |
| 264 | */ |
| 265 | if ($endpoint === 'upload-media') { |
| 266 | Media::upload_media(); |
| 267 | } |
| 268 | |
| 269 | if ($endpoint === 'upload-font' && HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) { |
| 270 | Media::upload_fonts(); |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * @deprecated |
| 275 | * @see DELETE /remove-custom-font-permanently |
| 276 | */ |
| 277 | // if ( $endpoint === 'remove-custom-font-folder-from-server' && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) { |
| 278 | // Media::remove_custom_font_folder_from_server(); |
| 279 | // } |
| 280 | |
| 281 | if ($endpoint === 'upload-base64-img') { |
| 282 | Media::upload_base64_img(); |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * WALKTHROUGH |
| 287 | * @deprecated |
| 288 | * @see PUT /walkthrough-shown-state |
| 289 | */ |
| 290 | if ('set-walkthrough-shown-state' === $endpoint) { |
| 291 | Walkthrough::set_walkthrough_state(); |
| 292 | } |
| 293 | |
| 294 | /** |
| 295 | * Collaboration data save |
| 296 | * @deprecated |
| 297 | * @see POST /collaboration-actions |
| 298 | */ |
| 299 | if ('save-collaboration-actions' === $endpoint) { |
| 300 | Collaboration::save_actions(); |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Collaboration data save |
| 305 | * @deprecated |
| 306 | * @see POST /install-app |
| 307 | */ |
| 308 | // if ( 'install-app' === $endpoint && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) { |
| 309 | // Apps::install_app(); |
| 310 | // } |
| 311 | |
| 312 | /** |
| 313 | * @deprecated |
| 314 | * @see PUT /app-settings |
| 315 | */ |
| 316 | // if ( 'save-app-settings-using-slug' === $endpoint && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) { |
| 317 | // Apps::save_app_settings_using_slug(); |
| 318 | // } |
| 319 | |
| 320 | /** |
| 321 | * @deprecated |
| 322 | * @see DELETE /remove-app |
| 323 | */ |
| 324 | // if ( 'delete-app-using-slug' === $endpoint && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) { |
| 325 | // Apps::delete_app_using_slug(); |
| 326 | // } |
| 327 | |
| 328 | /** |
| 329 | * @deprecated |
| 330 | * @see PUT /update-app |
| 331 | */ |
| 332 | // if ( 'update-app' === $endpoint && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) { |
| 333 | // Apps::update_app(); |
| 334 | // } |
| 335 | |
| 336 | /** |
| 337 | * Export page data |
| 338 | */ |
| 339 | if ('import-page-data' === $endpoint && HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) { |
| 340 | ExportImport::import(); |
| 341 | } |
| 342 | /** |
| 343 | * Export template data |
| 344 | */ |
| 345 | if ('import-template-data' === $endpoint && HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) { |
| 346 | ExportImport::template_import(); |
| 347 | |
| 348 | } |
| 349 | |
| 350 | /** |
| 351 | * Export page dat |
| 352 | */ |
| 353 | if ('export-page-data' === $endpoint) { |
| 354 | ExportImport::export(); |
| 355 | } |
| 356 | if ($endpoint === 'import-template-using-url' && HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) { |
| 357 | TemplateExportImport::import_using_url(); |
| 358 | } |
| 359 | if ($endpoint === 'process-imported-template' && HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) { |
| 360 | TemplateExportImport::processImport(); |
| 361 | } |
| 362 | if ($endpoint === 'check-existing-template-data' && HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) { |
| 363 | TemplateExportImport::check_existing_template_data(); |
| 364 | } |
| 365 | |
| 366 | /** |
| 367 | * @deprecated |
| 368 | * @see PUT /pages/{page_id}/rename-staging-version |
| 369 | */ |
| 370 | // if ( $endpoint === 'rename-staging-version' && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) { |
| 371 | // Staging::rename_stage_version(); |
| 372 | // } |
| 373 | |
| 374 | /** |
| 375 | * @deprecated |
| 376 | * @see DELETE /pages/{page_id}/remove-staging-version |
| 377 | */ |
| 378 | // if ( $endpoint === 'delete-staging-version' && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) { |
| 379 | // Staging::delete_stage_version(); |
| 380 | // } |
| 381 | |
| 382 | /** |
| 383 | * @deprecated |
| 384 | * @see POST /pages/{page_id}/publish-staging-version |
| 385 | */ |
| 386 | // if ( $endpoint === 'publish-staging-version' && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) { |
| 387 | // Staging::publish_stage_version(); |
| 388 | // } |
| 389 | |
| 390 | /** |
| 391 | * @deprecated |
| 392 | * @see POST /pages/{page_id}/restore-staging-version |
| 393 | */ |
| 394 | // if ( $endpoint === 'restore-staging-version' && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) { |
| 395 | // Staging::restore_stage_version(); |
| 396 | // } |
| 397 | |
| 398 | if ($endpoint === 'get-dynamic-content-batch') { |
| 399 | DynamicContent::get_dynamic_element_data_batch(); |
| 400 | } |
| 401 | |
| 402 | if ($endpoint === 'get-collection-batch') { |
| 403 | Collection::get_collection_batch(); |
| 404 | } |
| 405 | |
| 406 | if ($endpoint === 'get-single-symbol') { |
| 407 | Symbol::fetch_symbol(); |
| 408 | } |
| 409 | |
| 410 | } |
| 411 | |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * Initialize the get apis |
| 416 | * |
| 417 | * @return void |
| 418 | */ |
| 419 | public function kirki_get_apis() |
| 420 | { |
| 421 | HelperFunctions::verify_nonce('wp_rest'); |
| 422 | |
| 423 | if (!$this->user_can_access_get_apis()) { |
| 424 | wp_send_json_error('Not authorized'); |
| 425 | } |
| 426 | |
| 427 | //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 428 | $endpoint = HelperFunctions::sanitize_text(isset($_GET['endpoint']) ? $_GET['endpoint'] : null); |
| 429 | |
| 430 | /** |
| 431 | * PAGE APIS |
| 432 | * @deprecated |
| 433 | * @see GET /pages/{page_id} |
| 434 | */ |
| 435 | // if ($endpoint === 'get-page-data') { |
| 436 | // Page::get_page_blocks_and_styles(); |
| 437 | // } |
| 438 | |
| 439 | /** |
| 440 | * @deprecated |
| 441 | * @see GET /wp-posts/{post_id} |
| 442 | */ |
| 443 | // if ($endpoint === 'get-wp-single-post') { |
| 444 | // if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) { |
| 445 | // wp_send_json_error('Not authorized', 401); |
| 446 | // } |
| 447 | // $post_id = (int) HelperFunctions::sanitize_text(isset($_GET['post_id']) ? $_GET['post_id'] : null); |
| 448 | // $post = get_post($post_id); |
| 449 | |
| 450 | // if (!$post) { |
| 451 | // wp_send_json_error('Post not found'); |
| 452 | // } |
| 453 | |
| 454 | // wp_send_json_success($post); |
| 455 | // } |
| 456 | |
| 457 | /** |
| 458 | * @deprecated |
| 459 | * @see GET /pages |
| 460 | */ |
| 461 | if ($endpoint === 'get-pages-list') { |
| 462 | Page::fetch_list_api(); |
| 463 | } |
| 464 | |
| 465 | /** |
| 466 | * @deprecated |
| 467 | * @see GET /page-panel-pages |
| 468 | */ |
| 469 | if ($endpoint === 'get-pages-for-pages-panel') { |
| 470 | Page::get_pages_for_pages_panel(); |
| 471 | } |
| 472 | /** |
| 473 | * @deprecated |
| 474 | * @see GET /data-list-for-template-edit-search-flyout |
| 475 | */ |
| 476 | // if ($endpoint === 'get-data-list-for-template-edit-search-flyout') { |
| 477 | // Page::get_data_list_for_template_edit_search_flyout(); |
| 478 | // } |
| 479 | if ($endpoint === 'get-posts-list') { |
| 480 | Page::fetch_post_list_data_post_type_wise(); |
| 481 | } |
| 482 | |
| 483 | /** |
| 484 | * @deprecated |
| 485 | * @see GET /current-page/{page_id} |
| 486 | */ |
| 487 | // if ($endpoint === 'get-current-page-data') { |
| 488 | // Page::get_current_page_data(); |
| 489 | // } |
| 490 | if ($endpoint === 'get-unused-class-info-from-db') { |
| 491 | Page::get_unused_class_info_from_db(); |
| 492 | } |
| 493 | /** |
| 494 | * @deprecated |
| 495 | * @see GET /validate-wp-post-slug |
| 496 | */ |
| 497 | // if ($endpoint === 'validate-wp-post-slug') { |
| 498 | // Page::validate_wp_post_slug(); |
| 499 | // } |
| 500 | |
| 501 | /** |
| 502 | * USER DATA APIS |
| 503 | * @deprecated |
| 504 | * @see GET /global-ui-controller |
| 505 | */ |
| 506 | // if ( $endpoint === 'get-user-controller' ) { |
| 507 | // UserData::get_user_controller(); |
| 508 | // } |
| 509 | |
| 510 | /** |
| 511 | * @deprecated |
| 512 | * @see GET /is-user-logged-in |
| 513 | */ |
| 514 | // if ( $endpoint === 'is-user-logged-in' ) { |
| 515 | // UserData::check_user_login(); |
| 516 | // } |
| 517 | |
| 518 | /** |
| 519 | * USER DATA APIS |
| 520 | * @deprecated |
| 521 | * @see GET /global-ui-saved-data |
| 522 | */ |
| 523 | // if ( $endpoint === 'get-user-saved-data' ) { |
| 524 | // UserData::get_user_saved_data(); |
| 525 | // } |
| 526 | |
| 527 | /** |
| 528 | * USER DATA APIS |
| 529 | * @deprecated |
| 530 | * @see GET /app-list |
| 531 | */ |
| 532 | // if ( $endpoint === 'get-app-list' ) { |
| 533 | // Apps::get_app_list(); |
| 534 | // } |
| 535 | /** |
| 536 | * USER DATA APIS |
| 537 | * @deprecated |
| 538 | * @see GET /installed-app-list |
| 539 | */ |
| 540 | // if ( $endpoint === 'get-installed-app-list' ) { |
| 541 | // Apps::get_installed_apps_list(); |
| 542 | // } |
| 543 | |
| 544 | /** |
| 545 | * USER DATA APIS |
| 546 | * @deprecated |
| 547 | * @see GET /app-settings |
| 548 | */ |
| 549 | // if ( $endpoint === 'get-app-settings-using-slug' ) { |
| 550 | // Apps::get_app_settings_using_slug(); |
| 551 | // } |
| 552 | |
| 553 | /** |
| 554 | * @deprecated |
| 555 | * @see GET /global-custom-fonts |
| 556 | */ |
| 557 | // if ( $endpoint === 'get-user-custom-fonts-data' ) { |
| 558 | // UserData::get_user_custom_fonts_data(); |
| 559 | // } |
| 560 | |
| 561 | /** |
| 562 | * GET SYMBOL LIST API |
| 563 | */ |
| 564 | if ($endpoint === 'get-symbol-list') { |
| 565 | Symbol::fetch_list(false, true); |
| 566 | } |
| 567 | |
| 568 | if ($endpoint === 'get-page-custom-section') { |
| 569 | $type = HelperFunctions::sanitize_text(isset($_GET['type']) ? $_GET['type'] : ''); |
| 570 | wp_send_json(HelperFunctions::get_page_custom_section($type, true)); |
| 571 | } |
| 572 | |
| 573 | /** |
| 574 | * GET Single prebuilt html API |
| 575 | */ |
| 576 | if ($endpoint === 'get-pre-built-html') { |
| 577 | if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) { |
| 578 | wp_send_json_error('Not authorized', 401); |
| 579 | } |
| 580 | Symbol::get_pre_built_html_using_url(); |
| 581 | } |
| 582 | |
| 583 | /** |
| 584 | * GET DYNAMIC CONTENT API |
| 585 | */ |
| 586 | if ($endpoint === 'get-dynamic-content') { |
| 587 | DynamicContent::get_dynamic_element_data(); |
| 588 | } |
| 589 | |
| 590 | if ($endpoint === 'get-post-terms') { |
| 591 | Taxonomy::get_post_terms(); |
| 592 | } |
| 593 | |
| 594 | if ($endpoint === 'get-terms') { |
| 595 | Taxonomy::get_terms(); |
| 596 | } |
| 597 | |
| 598 | if ($endpoint === 'get-post-type-taxonomies') { |
| 599 | Taxonomy::get_post_type_taxonomies(); |
| 600 | } |
| 601 | |
| 602 | if ($endpoint === 'get-all-terms-by-post-type') { |
| 603 | Taxonomy::get_all_terms_by_post_type(); |
| 604 | } |
| 605 | |
| 606 | if ($endpoint === 'get_visibility_condition_fields') { |
| 607 | DynamicContent::get_visibility_condition_fields(); |
| 608 | } |
| 609 | |
| 610 | if ($endpoint === 'get_dynamic_content_fields') { |
| 611 | DynamicContent::get_dynamic_content_fields(); |
| 612 | } |
| 613 | |
| 614 | /** |
| 615 | * GET WordPress MENUS API |
| 616 | */ |
| 617 | if ($endpoint === 'get-wp-menus') { |
| 618 | WordpressData::get_wordpress_menus_data(); |
| 619 | } |
| 620 | |
| 621 | /** |
| 622 | * GET WordPress POST TYPES API |
| 623 | */ |
| 624 | if ($endpoint === 'get-wp-post-types') { |
| 625 | WordpressData::get_wordpress_post_types_data(); |
| 626 | } |
| 627 | |
| 628 | /** |
| 629 | * GET WordPress POST TYPES API |
| 630 | */ |
| 631 | if ($endpoint === 'get-wp-comment-types') { |
| 632 | WordpressData::get_wordpress_comment_types_data(); |
| 633 | } |
| 634 | |
| 635 | /** |
| 636 | * GET WordPress SINGLE MENU DATA API |
| 637 | */ |
| 638 | if ($endpoint === 'get-wp-sigle-menu') { |
| 639 | //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 640 | $term_id = HelperFunctions::sanitize_text(isset($_GET['term_id']) ? $_GET['term_id'] : null); |
| 641 | WordpressData::get_wordpress_single_menu_data($term_id); |
| 642 | } |
| 643 | |
| 644 | /** |
| 645 | * PAGE SETTINGS |
| 646 | */ |
| 647 | if ($endpoint === 'get-page-settings-data') { |
| 648 | PageSettings::get_page_settings_data(); |
| 649 | } |
| 650 | |
| 651 | if ($endpoint === 'get-custom-code') { |
| 652 | PageSettings::get_custom_code(); |
| 653 | } |
| 654 | |
| 655 | /** |
| 656 | * WALKTHROUGH |
| 657 | * @deprecated |
| 658 | * @see GET /walkthrough-shown-state |
| 659 | */ |
| 660 | // if ('get-walkthrough-shown-state' === $endpoint) { |
| 661 | // Walkthrough::get_walkthrough_state(); |
| 662 | // } |
| 663 | |
| 664 | /** |
| 665 | * COLLECTION |
| 666 | */ |
| 667 | if ('get-collection' === $endpoint) { |
| 668 | Collection::get_collection(); |
| 669 | } |
| 670 | |
| 671 | if ('get-external-collection-options' === $endpoint) { |
| 672 | Collection::get_external_collection_options(); |
| 673 | } |
| 674 | |
| 675 | if ('get-external-collection-item-type' === $endpoint) { |
| 676 | Collection::get_external_collection_item_type(); |
| 677 | } |
| 678 | |
| 679 | /** |
| 680 | * GET USERS |
| 681 | */ |
| 682 | |
| 683 | if ('get-users-of-collection' === $endpoint) { |
| 684 | Users::get_users_of_collection(); |
| 685 | } |
| 686 | |
| 687 | /** |
| 688 | * COMMENTS |
| 689 | */ |
| 690 | if ('get-comments' === $endpoint) { |
| 691 | Comments::get_comments(); |
| 692 | } |
| 693 | |
| 694 | /** |
| 695 | * AUTHOR LIST |
| 696 | */ |
| 697 | if ('get-authors' === $endpoint) { |
| 698 | if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) { |
| 699 | wp_send_json_error('Not authorized', 401); |
| 700 | } |
| 701 | WordpressData::get_author_list(); |
| 702 | } |
| 703 | |
| 704 | /** |
| 705 | * ROLE LIST |
| 706 | */ |
| 707 | |
| 708 | if ('get-roles' === $endpoint) { |
| 709 | if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) { |
| 710 | wp_send_json_error('Not authorized', 401); |
| 711 | } |
| 712 | WordpressData::get_role_list(); |
| 713 | } |
| 714 | |
| 715 | /** |
| 716 | * USER LIST |
| 717 | */ |
| 718 | if ( |
| 719 | 'get-users' === $endpoint |
| 720 | ) { |
| 721 | if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) { |
| 722 | wp_send_json_error('Not authorized', 401); |
| 723 | } |
| 724 | WordpressData::get_user_list(); |
| 725 | } |
| 726 | |
| 727 | /** |
| 728 | * CATEGORY LIST |
| 729 | */ |
| 730 | if ('get-categories' === $endpoint) { |
| 731 | WordpressData::get_category_list(); |
| 732 | } |
| 733 | |
| 734 | /** |
| 735 | * GET ACCESS LEVEL |
| 736 | */ |
| 737 | if ('editor-access-level' === $endpoint) { |
| 738 | RBAC::get_editor_access_level(); |
| 739 | } |
| 740 | |
| 741 | if ($endpoint === 'get-common-data') { |
| 742 | if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) { |
| 743 | wp_send_json_error('Not authorized', 401); |
| 744 | } |
| 745 | WpAdmin::get_common_data(); |
| 746 | } |
| 747 | |
| 748 | /** |
| 749 | * Collaboration data get |
| 750 | */ |
| 751 | if ('collect-collaboration-actions' === $endpoint) { |
| 752 | Collaboration::send_actions(); |
| 753 | } |
| 754 | /** |
| 755 | * Collaboration data get |
| 756 | */ |
| 757 | if ('delete-collaboration-connection' === $endpoint) { |
| 758 | $session_id = HelperFunctions::sanitize_text($_GET['session_id']); |
| 759 | Collaboration::delete_connection($session_id); |
| 760 | } |
| 761 | |
| 762 | if ($endpoint === 'get-connected-collaboration-users-list') { |
| 763 | $post_id = HelperFunctions::sanitize_text($_GET['post_id']); |
| 764 | $res = Collaboration::get_connected_collaboration_users_list($post_id); |
| 765 | wp_send_json($res); |
| 766 | } |
| 767 | |
| 768 | /** |
| 769 | * Staging GET APIs |
| 770 | * @deprecated |
| 771 | * @see GET /pages/{pageId}/staged-versions |
| 772 | */ |
| 773 | |
| 774 | // if ('get-all-staged-versions' === $endpoint) { |
| 775 | // $post_id = (int) HelperFunctions::sanitize_text(isset($_GET['post_id']) ? $_GET['post_id'] : null); |
| 776 | // Staging::get_all_staged_versions($post_id, false, true); |
| 777 | // } |
| 778 | } |
| 779 | |
| 780 | /** |
| 781 | * Check if the current request can access wp endpoints. |
| 782 | * |
| 783 | * @return bool |
| 784 | */ |
| 785 | private function user_can_access_get_apis() |
| 786 | { |
| 787 | if (HelperFunctions::is_api_call_from_editor_preview() && HelperFunctions::is_api_header_post_editor_preview_token_valid()) { |
| 788 | return true; |
| 789 | } |
| 790 | |
| 791 | return is_user_logged_in() && HelperFunctions::has_access( |
| 792 | array( |
| 793 | KIRKI_ACCESS_LEVELS['FULL_ACCESS'], |
| 794 | KIRKI_ACCESS_LEVELS['CONTENT_ACCESS'], |
| 795 | KIRKI_ACCESS_LEVELS['VIEW_ACCESS'], |
| 796 | ) |
| 797 | ); |
| 798 | } |
| 799 | |
| 800 | /** |
| 801 | * Initialize the admin post apis |
| 802 | * |
| 803 | * @return void |
| 804 | */ |
| 805 | public function kirki_wp_admin_post_apis() |
| 806 | { |
| 807 | HelperFunctions::verify_nonce('wp_rest'); |
| 808 | |
| 809 | if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) { |
| 810 | wp_send_json_error('Not authorized'); |
| 811 | } |
| 812 | |
| 813 | //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 814 | $endpoint = HelperFunctions::sanitize_text(isset($_POST['endpoint']) ? $_POST['endpoint'] : null); |
| 815 | |
| 816 | if ($endpoint === 'save-common-data') { |
| 817 | WpAdmin::save_common_data(); |
| 818 | } |
| 819 | |
| 820 | if ($endpoint === 'update-license-validity') { |
| 821 | WpAdmin::update_license_validity(); |
| 822 | } |
| 823 | |
| 824 | if ($endpoint === 'update-access-level') { |
| 825 | RBAC::update_access_level(); |
| 826 | } |
| 827 | |
| 828 | if ($endpoint === 'delete-form-row') { |
| 829 | Form::delete_form_row(); |
| 830 | } |
| 831 | |
| 832 | if ($endpoint === 'delete-form') { |
| 833 | Form::delete_form(); |
| 834 | } |
| 835 | |
| 836 | if ($endpoint === 'update-form-cell') { |
| 837 | Form::update_form_row(); |
| 838 | } |
| 839 | |
| 840 | /** |
| 841 | * Export Template |
| 842 | */ |
| 843 | if ($endpoint === 'import-template') { |
| 844 | TemplateExportImport::import(); |
| 845 | } |
| 846 | |
| 847 | if ($endpoint === 'process-imported-template') { |
| 848 | TemplateExportImport::processImport(); |
| 849 | } |
| 850 | |
| 851 | if ($endpoint === 'process-export-template') { |
| 852 | TemplateExportImport::processExport(); |
| 853 | } |
| 854 | |
| 855 | if ($endpoint === 'save-editor-read-only-access-data') { |
| 856 | Page::save_editor_read_only_access_data(); |
| 857 | } |
| 858 | /** |
| 859 | * Export Template |
| 860 | */ |
| 861 | |
| 862 | if ($endpoint === 'export-template') { |
| 863 | TemplateExportImport::export(); |
| 864 | } |
| 865 | |
| 866 | } |
| 867 | |
| 868 | /** |
| 869 | * Return an explicit unauthorized response for unauthenticated admin AJAX requests. |
| 870 | * |
| 871 | * @return void |
| 872 | */ |
| 873 | public function kirki_wp_admin_unauthorized() |
| 874 | { |
| 875 | wp_send_json_error('Not authorized', 401); |
| 876 | } |
| 877 | |
| 878 | /** |
| 879 | * Initialize the admin get apis |
| 880 | * |
| 881 | * @return void |
| 882 | */ |
| 883 | public function kirki_wp_admin_get_apis() |
| 884 | { |
| 885 | HelperFunctions::verify_nonce('wp_rest'); |
| 886 | |
| 887 | if (!is_admin()) { |
| 888 | wp_send_json_error('Not authorized', 401); |
| 889 | } |
| 890 | |
| 891 | if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) { |
| 892 | wp_send_json_error('Not authorized', 401); |
| 893 | } |
| 894 | |
| 895 | //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 896 | $endpoint = HelperFunctions::sanitize_text(isset($_GET['endpoint']) ? $_GET['endpoint'] : null); |
| 897 | |
| 898 | if ($endpoint === 'get-common-data') { |
| 899 | WpAdmin::get_common_data(); |
| 900 | } |
| 901 | |
| 902 | // From manipulation from admin dashboard. |
| 903 | if ($endpoint === 'get-forms') { |
| 904 | Form::get_forms(); |
| 905 | } |
| 906 | |
| 907 | if ($endpoint === 'get-form-data') { |
| 908 | Form::get_form_data(); |
| 909 | } |
| 910 | |
| 911 | if ($endpoint === 'get-wp-admin-page-data') { |
| 912 | Page::get_pages_for_pages_panel(); |
| 913 | } |
| 914 | |
| 915 | if ($endpoint === 'get-members-based-on-role') { |
| 916 | RBAC::members_based_on_role(); |
| 917 | } |
| 918 | |
| 919 | if ($endpoint === 'download-form-data') { |
| 920 | if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) { |
| 921 | wp_send_json_error('Not authorized'); |
| 922 | } |
| 923 | |
| 924 | Form::download_form_data(); |
| 925 | } |
| 926 | |
| 927 | // From manipulation from admin dashboard. |
| 928 | |
| 929 | if ($endpoint === 'get-editor-read-only-access-data') { |
| 930 | if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) { |
| 931 | wp_send_json_error('Not authorized', 401); |
| 932 | } |
| 933 | Page::get_editor_read_only_access_data(); |
| 934 | } |
| 935 | } |
| 936 | } |
| 937 |