PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.2.0
Kirki – Freeform Page Builder, Website Builder & Customizer v6.2.0
6.2.0 6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / includes / Ajax.php
kirki / includes Last commit date
API 4 days ago Admin 1 month ago Ajax 4 days ago ExportImport 2 weeks ago FormValidator 3 months ago Frontend 4 days ago Manager 2 weeks ago API.php 2 weeks ago Admin.php 3 months ago Ajax.php 4 days ago Apps.php 1 month ago ContentManager.php 3 months ago DbQueryUtils.php 2 months ago ElementVisibilityConditions.php 3 months ago Frontend.php 3 months ago HelperFunctions.php 4 days ago KirkiBase.php 1 month ago PostsQueryUtils.php 3 months ago Staging.php 4 days ago View.php 1 month ago
Ajax.php
936 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-zip' && HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
270 Media::upload_font_zip();
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 }
407
408 if ($endpoint === 'get-single-symbol') {
409 Symbol::fetch_symbol();
410 }
411 }
412
413 /**
414 * Initialize the get apis
415 *
416 * @return void
417 */
418 public function kirki_get_apis()
419 {
420 HelperFunctions::verify_nonce('wp_rest');
421
422 if (!$this->user_can_access_get_apis()) {
423 wp_send_json_error('Not authorized');
424 }
425
426 //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
427 $endpoint = HelperFunctions::sanitize_text(isset($_GET['endpoint']) ? $_GET['endpoint'] : null);
428
429 /**
430 * PAGE APIS
431 * @deprecated
432 * @see GET /pages/{page_id}
433 */
434 // if ($endpoint === 'get-page-data') {
435 // Page::get_page_blocks_and_styles();
436 // }
437
438 /**
439 * @deprecated
440 * @see GET /wp-posts/{post_id}
441 */
442 // if ($endpoint === 'get-wp-single-post') {
443 // if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
444 // wp_send_json_error('Not authorized', 401);
445 // }
446 // $post_id = (int) HelperFunctions::sanitize_text(isset($_GET['post_id']) ? $_GET['post_id'] : null);
447 // $post = get_post($post_id);
448
449 // if (!$post) {
450 // wp_send_json_error('Post not found');
451 // }
452
453 // wp_send_json_success($post);
454 // }
455
456 /**
457 * @deprecated
458 * @see GET /pages
459 */
460 if ($endpoint === 'get-pages-list') {
461 Page::fetch_list_api();
462 }
463
464 /**
465 * @deprecated
466 * @see GET /page-panel-pages
467 */
468 if ($endpoint === 'get-pages-for-pages-panel') {
469 Page::get_pages_for_pages_panel();
470 }
471 /**
472 * @deprecated
473 * @see GET /data-list-for-template-edit-search-flyout
474 */
475 // if ($endpoint === 'get-data-list-for-template-edit-search-flyout') {
476 // Page::get_data_list_for_template_edit_search_flyout();
477 // }
478 if ($endpoint === 'get-posts-list') {
479 Page::fetch_post_list_data_post_type_wise();
480 }
481
482 /**
483 * @deprecated
484 * @see GET /current-page/{page_id}
485 */
486 // if ($endpoint === 'get-current-page-data') {
487 // Page::get_current_page_data();
488 // }
489 if ($endpoint === 'get-unused-class-info-from-db') {
490 Page::get_unused_class_info_from_db();
491 }
492 /**
493 * @deprecated
494 * @see GET /validate-wp-post-slug
495 */
496 // if ($endpoint === 'validate-wp-post-slug') {
497 // Page::validate_wp_post_slug();
498 // }
499
500 /**
501 * USER DATA APIS
502 * @deprecated
503 * @see GET /global-ui-controller
504 */
505 // if ( $endpoint === 'get-user-controller' ) {
506 // UserData::get_user_controller();
507 // }
508
509 /**
510 * @deprecated
511 * @see GET /is-user-logged-in
512 */
513 // if ( $endpoint === 'is-user-logged-in' ) {
514 // UserData::check_user_login();
515 // }
516
517 /**
518 * USER DATA APIS
519 * @deprecated
520 * @see GET /global-ui-saved-data
521 */
522 // if ( $endpoint === 'get-user-saved-data' ) {
523 // UserData::get_user_saved_data();
524 // }
525
526 /**
527 * USER DATA APIS
528 * @deprecated
529 * @see GET /app-list
530 */
531 // if ( $endpoint === 'get-app-list' ) {
532 // Apps::get_app_list();
533 // }
534 /**
535 * USER DATA APIS
536 * @deprecated
537 * @see GET /installed-app-list
538 */
539 // if ( $endpoint === 'get-installed-app-list' ) {
540 // Apps::get_installed_apps_list();
541 // }
542
543 /**
544 * USER DATA APIS
545 * @deprecated
546 * @see GET /app-settings
547 */
548 // if ( $endpoint === 'get-app-settings-using-slug' ) {
549 // Apps::get_app_settings_using_slug();
550 // }
551
552 /**
553 * @deprecated
554 * @see GET /global-custom-fonts
555 */
556 // if ( $endpoint === 'get-user-custom-fonts-data' ) {
557 // UserData::get_user_custom_fonts_data();
558 // }
559
560 /**
561 * GET SYMBOL LIST API
562 */
563 if ($endpoint === 'get-symbol-list') {
564 Symbol::fetch_list(false, true);
565 }
566
567 if ($endpoint === 'get-page-custom-section') {
568 $type = HelperFunctions::sanitize_text(isset($_GET['type']) ? $_GET['type'] : '');
569 wp_send_json(HelperFunctions::get_page_custom_section($type, true));
570 }
571
572 /**
573 * GET Single prebuilt html API
574 */
575 if ($endpoint === 'get-pre-built-html') {
576 if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
577 wp_send_json_error('Not authorized', 401);
578 }
579 Symbol::get_pre_built_html_using_url();
580 }
581
582 /**
583 * GET DYNAMIC CONTENT API
584 */
585 if ($endpoint === 'get-dynamic-content') {
586 DynamicContent::get_dynamic_element_data();
587 }
588
589 if ($endpoint === 'get-post-terms') {
590 Taxonomy::get_post_terms();
591 }
592
593 if ($endpoint === 'get-terms') {
594 Taxonomy::get_terms();
595 }
596
597 if ($endpoint === 'get-post-type-taxonomies') {
598 Taxonomy::get_post_type_taxonomies();
599 }
600
601 if ($endpoint === 'get-all-terms-by-post-type') {
602 Taxonomy::get_all_terms_by_post_type();
603 }
604
605 if ($endpoint === 'get_visibility_condition_fields') {
606 DynamicContent::get_visibility_condition_fields();
607 }
608
609 if ($endpoint === 'get_dynamic_content_fields') {
610 DynamicContent::get_dynamic_content_fields();
611 }
612
613 /**
614 * GET WordPress MENUS API
615 */
616 if ($endpoint === 'get-wp-menus') {
617 WordpressData::get_wordpress_menus_data();
618 }
619
620 /**
621 * GET WordPress POST TYPES API
622 */
623 if ($endpoint === 'get-wp-post-types') {
624 WordpressData::get_wordpress_post_types_data();
625 }
626
627 /**
628 * GET WordPress POST TYPES API
629 */
630 if ($endpoint === 'get-wp-comment-types') {
631 WordpressData::get_wordpress_comment_types_data();
632 }
633
634 /**
635 * GET WordPress SINGLE MENU DATA API
636 */
637 if ($endpoint === 'get-wp-sigle-menu') {
638 //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
639 $term_id = HelperFunctions::sanitize_text(isset($_GET['term_id']) ? $_GET['term_id'] : null);
640 WordpressData::get_wordpress_single_menu_data($term_id);
641 }
642
643 /**
644 * PAGE SETTINGS
645 */
646 if ($endpoint === 'get-page-settings-data') {
647 PageSettings::get_page_settings_data();
648 }
649
650 if ($endpoint === 'get-custom-code') {
651 PageSettings::get_custom_code();
652 }
653
654 /**
655 * WALKTHROUGH
656 * @deprecated
657 * @see GET /walkthrough-shown-state
658 */
659 // if ('get-walkthrough-shown-state' === $endpoint) {
660 // Walkthrough::get_walkthrough_state();
661 // }
662
663 /**
664 * COLLECTION
665 */
666 if ('get-collection' === $endpoint) {
667 Collection::get_collection();
668 }
669
670 if ('get-external-collection-options' === $endpoint) {
671 Collection::get_external_collection_options();
672 }
673
674 if ('get-external-collection-item-type' === $endpoint) {
675 Collection::get_external_collection_item_type();
676 }
677
678 /**
679 * GET USERS
680 */
681
682 if ('get-users-of-collection' === $endpoint) {
683 Users::get_users_of_collection();
684 }
685
686 /**
687 * COMMENTS
688 */
689 if ('get-comments' === $endpoint) {
690 Comments::get_comments();
691 }
692
693 /**
694 * AUTHOR LIST
695 */
696 if ('get-authors' === $endpoint) {
697 if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
698 wp_send_json_error('Not authorized', 401);
699 }
700 WordpressData::get_author_list();
701 }
702
703 /**
704 * ROLE LIST
705 */
706
707 if ('get-roles' === $endpoint) {
708 if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
709 wp_send_json_error('Not authorized', 401);
710 }
711 WordpressData::get_role_list();
712 }
713
714 /**
715 * USER LIST
716 */
717 if (
718 'get-users' === $endpoint
719 ) {
720 if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
721 wp_send_json_error('Not authorized', 401);
722 }
723 WordpressData::get_user_list();
724 }
725
726 /**
727 * CATEGORY LIST
728 */
729 if ('get-categories' === $endpoint) {
730 WordpressData::get_category_list();
731 }
732
733 /**
734 * GET ACCESS LEVEL
735 */
736 if ('editor-access-level' === $endpoint) {
737 RBAC::get_editor_access_level();
738 }
739
740 if ($endpoint === 'get-common-data') {
741 if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
742 wp_send_json_error('Not authorized', 401);
743 }
744 WpAdmin::get_common_data();
745 }
746
747 /**
748 * Collaboration data get
749 */
750 if ('collect-collaboration-actions' === $endpoint) {
751 Collaboration::send_actions();
752 }
753 /**
754 * Collaboration data get
755 */
756 if ('delete-collaboration-connection' === $endpoint) {
757 $session_id = HelperFunctions::sanitize_text($_GET['session_id']);
758 Collaboration::delete_connection($session_id);
759 }
760
761 if ($endpoint === 'get-connected-collaboration-users-list') {
762 $post_id = HelperFunctions::sanitize_text($_GET['post_id']);
763 $res = Collaboration::get_connected_collaboration_users_list($post_id);
764 wp_send_json($res);
765 }
766
767 /**
768 * Staging GET APIs
769 * @deprecated
770 * @see GET /pages/{pageId}/staged-versions
771 */
772
773 // if ('get-all-staged-versions' === $endpoint) {
774 // $post_id = (int) HelperFunctions::sanitize_text(isset($_GET['post_id']) ? $_GET['post_id'] : null);
775 // Staging::get_all_staged_versions($post_id, false, true);
776 // }
777 }
778
779 /**
780 * Check if the current request can access wp endpoints.
781 *
782 * @return bool
783 */
784 private function user_can_access_get_apis()
785 {
786 if (HelperFunctions::is_api_call_from_editor_preview() && HelperFunctions::is_api_header_post_editor_preview_token_valid()) {
787 return true;
788 }
789
790 return is_user_logged_in() && HelperFunctions::has_access(
791 array(
792 KIRKI_ACCESS_LEVELS['FULL_ACCESS'],
793 KIRKI_ACCESS_LEVELS['CONTENT_ACCESS'],
794 KIRKI_ACCESS_LEVELS['VIEW_ACCESS'],
795 )
796 );
797 }
798
799 /**
800 * Initialize the admin post apis
801 *
802 * @return void
803 */
804 public function kirki_wp_admin_post_apis()
805 {
806 HelperFunctions::verify_nonce('wp_rest');
807
808 if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
809 wp_send_json_error('Not authorized');
810 }
811
812 //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
813 $endpoint = HelperFunctions::sanitize_text(isset($_POST['endpoint']) ? $_POST['endpoint'] : null);
814
815 if ($endpoint === 'save-common-data') {
816 WpAdmin::save_common_data();
817 }
818
819 if ($endpoint === 'update-license-validity') {
820 WpAdmin::update_license_validity();
821 }
822
823 if ($endpoint === 'update-access-level') {
824 RBAC::update_access_level();
825 }
826
827 if ($endpoint === 'delete-form-row') {
828 Form::delete_form_row();
829 }
830
831 if ($endpoint === 'delete-form') {
832 Form::delete_form();
833 }
834
835 if ($endpoint === 'update-form-cell') {
836 Form::update_form_row();
837 }
838
839 /**
840 * Export Template
841 */
842 if ($endpoint === 'import-template') {
843 TemplateExportImport::import();
844 }
845
846 if ($endpoint === 'process-imported-template') {
847 TemplateExportImport::processImport();
848 }
849
850 if ($endpoint === 'process-export-template') {
851 TemplateExportImport::processExport();
852 }
853
854 if ($endpoint === 'save-editor-read-only-access-data') {
855 Page::save_editor_read_only_access_data();
856 }
857 /**
858 * Export Template
859 */
860
861 if ($endpoint === 'export-template') {
862 TemplateExportImport::export();
863 }
864
865 }
866
867 /**
868 * Return an explicit unauthorized response for unauthenticated admin AJAX requests.
869 *
870 * @return void
871 */
872 public function kirki_wp_admin_unauthorized()
873 {
874 wp_send_json_error('Not authorized', 401);
875 }
876
877 /**
878 * Initialize the admin get apis
879 *
880 * @return void
881 */
882 public function kirki_wp_admin_get_apis()
883 {
884 HelperFunctions::verify_nonce('wp_rest');
885
886 if (!is_admin()) {
887 wp_send_json_error('Not authorized', 401);
888 }
889
890 if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
891 wp_send_json_error('Not authorized', 401);
892 }
893
894 //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
895 $endpoint = HelperFunctions::sanitize_text(isset($_GET['endpoint']) ? $_GET['endpoint'] : null);
896
897 if ($endpoint === 'get-common-data') {
898 WpAdmin::get_common_data();
899 }
900
901 // From manipulation from admin dashboard.
902 if ($endpoint === 'get-forms') {
903 Form::get_forms();
904 }
905
906 if ($endpoint === 'get-form-data') {
907 Form::get_form_data();
908 }
909
910 if ($endpoint === 'get-wp-admin-page-data') {
911 Page::get_pages_for_pages_panel();
912 }
913
914 if ($endpoint === 'get-members-based-on-role') {
915 RBAC::members_based_on_role();
916 }
917
918 if ($endpoint === 'download-form-data') {
919 if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
920 wp_send_json_error('Not authorized');
921 }
922
923 Form::download_form_data();
924 }
925
926 // From manipulation from admin dashboard.
927
928 if ($endpoint === 'get-editor-read-only-access-data') {
929 if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
930 wp_send_json_error('Not authorized', 401);
931 }
932 Page::get_editor_read_only_access_data();
933 }
934 }
935 }
936