PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.0.13
Kirki – Freeform Page Builder, Website Builder & Customizer v6.0.13
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 2 weeks ago Admin 2 weeks ago Ajax 2 weeks ago ExportImport 2 weeks ago FormValidator 2 months ago Frontend 2 weeks ago Manager 2 weeks ago API.php 2 weeks ago Admin.php 2 months ago Ajax.php 2 weeks ago Apps.php 2 weeks ago ContentManager.php 2 months ago DbQueryUtils.php 2 months ago ElementVisibilityConditions.php 2 months ago Frontend.php 2 months ago HelperFunctions.php 2 weeks ago KirkiBase.php 2 weeks ago PostsQueryUtils.php 2 months ago Staging.php 2 weeks ago View.php 1 month ago
Ajax.php
895 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 */
288 if ('set-walkthrough-shown-state' === $endpoint) {
289 Walkthrough::set_walkthrough_state();
290 }
291
292 /**
293 * Collaboration data save
294 */
295 if ('save-collaboration-actions' === $endpoint) {
296 Collaboration::save_actions();
297 }
298
299 /**
300 * Collaboration data save
301 * @deprecated
302 * @see POST /install-app
303 */
304 // if ( 'install-app' === $endpoint && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) {
305 // Apps::install_app();
306 // }
307
308 /**
309 * @deprecated
310 * @see PUT /app-settings
311 */
312 // if ( 'save-app-settings-using-slug' === $endpoint && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) {
313 // Apps::save_app_settings_using_slug();
314 // }
315
316 /**
317 * @deprecated
318 * @see DELETE /remove-app
319 */
320 // if ( 'delete-app-using-slug' === $endpoint && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) {
321 // Apps::delete_app_using_slug();
322 // }
323
324 /**
325 * @deprecated
326 * @see PUT /update-app
327 */
328 // if ( 'update-app' === $endpoint && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) {
329 // Apps::update_app();
330 // }
331
332 /**
333 * Export page data
334 */
335 if ('import-page-data' === $endpoint && HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
336 ExportImport::import();
337 }
338 /**
339 * Export template data
340 */
341 if ('import-template-data' === $endpoint && HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
342 ExportImport::template_import();
343
344 }
345
346 /**
347 * Export page dat
348 */
349 if ('export-page-data' === $endpoint) {
350 ExportImport::export();
351 }
352 if ($endpoint === 'import-template-using-url' && HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
353 TemplateExportImport::import_using_url();
354 }
355 if ($endpoint === 'process-imported-template' && HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
356 TemplateExportImport::processImport();
357 }
358 if ($endpoint === 'check-existing-template-data' && HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
359 TemplateExportImport::check_existing_template_data();
360 }
361
362 if ($endpoint === 'rename-staging-version' && HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
363 Staging::rename_stage_version();
364 }
365
366 if ($endpoint === 'delete-staging-version' && HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
367 Staging::delete_stage_version();
368 }
369
370 /**
371 * @deprecated
372 * @see POST /pages/{page_id}/publish-staging-version
373 */
374 // if ( $endpoint === 'publish-staging-version' && HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) {
375 // Staging::publish_stage_version();
376 // }
377
378 if ($endpoint === 'restore-staging-version' && HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
379 Staging::restore_stage_version();
380 }
381
382 if ($endpoint === 'get-dynamic-content-batch') {
383 DynamicContent::get_dynamic_element_data_batch();
384 }
385
386 if ($endpoint === 'get-collection-batch') {
387 Collection::get_collection_batch();
388 }
389
390 }
391
392 if ($endpoint === 'get-single-symbol') {
393 Symbol::fetch_symbol();
394 }
395 }
396
397 /**
398 * Initialize the get apis
399 *
400 * @return void
401 */
402 public function kirki_get_apis()
403 {
404 if (HelperFunctions::is_api_call_from_editor_preview() && !HelperFunctions::is_api_header_post_editor_preview_token_valid()) {
405 wp_send_json_error('Not authorized');
406 }
407
408 //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
409 $endpoint = HelperFunctions::sanitize_text(isset($_GET['endpoint']) ? $_GET['endpoint'] : null);
410 if (in_array($endpoint, array('collect-collaboration-actions', 'delete-collaboration-connection'), true)) {
411 if (!$this->user_can_access_wp_apis()) {
412 wp_send_json_error('Not authorized');
413 }
414 } else {
415 // TODO: Need to verify for collaboration.
416 HelperFunctions::verify_nonce('wp_rest');
417 }
418
419 if (!is_admin()) {
420 wp_send_json_error('Not authorized');
421 }
422 /**
423 * PAGE APIS
424 */
425 if ($endpoint === 'get-page-data') {
426 Page::get_page_blocks_and_styles();
427 }
428
429 if ($endpoint === 'get-wp-single-post') {
430 if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
431 wp_send_json_error('Not authorized', 401);
432 }
433 $post_id = (int) HelperFunctions::sanitize_text(isset($_GET['post_id']) ? $_GET['post_id'] : null);
434 $post = get_post($post_id);
435
436 if (!$post) {
437 wp_send_json_error('Post not found');
438 }
439
440 wp_send_json_success($post);
441 }
442
443 if ($endpoint === 'get-pages-list') {
444 Page::fetch_list_api();
445 }
446
447 if ($endpoint === 'get-pages-for-pages-panel') {
448 Page::get_pages_for_pages_panel();
449 }
450 if ($endpoint === 'get-data-list-for-template-edit-search-flyout') {
451 Page::get_data_list_for_template_edit_search_flyout();
452 }
453 if ($endpoint === 'get-posts-list') {
454 Page::fetch_post_list_data_post_type_wise();
455 }
456
457 if ($endpoint === 'get-current-page-data') {
458 Page::get_current_page_data();
459 }
460 if ($endpoint === 'get-unused-class-info-from-db') {
461 Page::get_unused_class_info_from_db();
462 }
463 if ($endpoint === 'validate-wp-post-slug') {
464 Page::validate_wp_post_slug();
465 }
466
467 if ($endpoint === 'get-page-html') {
468 Page::get_page_html();
469 }
470
471 /**
472 * USER DATA APIS
473 * @deprecated
474 * @see GET /global-ui-controller
475 */
476 // if ( $endpoint === 'get-user-controller' ) {
477 // UserData::get_user_controller();
478 // }
479
480 /**
481 * @deprecated
482 * @see GET /is-user-logged-in
483 */
484 // if ( $endpoint === 'is-user-logged-in' ) {
485 // UserData::check_user_login();
486 // }
487
488 /**
489 * USER DATA APIS
490 * @deprecated
491 * @see GET /global-ui-saved-data
492 */
493 // if ( $endpoint === 'get-user-saved-data' ) {
494 // UserData::get_user_saved_data();
495 // }
496
497 /**
498 * USER DATA APIS
499 * @deprecated
500 * @see GET /app-list
501 */
502 // if ( $endpoint === 'get-app-list' ) {
503 // Apps::get_app_list();
504 // }
505 /**
506 * USER DATA APIS
507 * @deprecated
508 * @see GET /installed-app-list
509 */
510 // if ( $endpoint === 'get-installed-app-list' ) {
511 // Apps::get_installed_apps_list();
512 // }
513
514 /**
515 * USER DATA APIS
516 * @deprecated
517 * @see GET /app-settings
518 */
519 // if ( $endpoint === 'get-app-settings-using-slug' ) {
520 // Apps::get_app_settings_using_slug();
521 // }
522
523 /**
524 * @deprecated
525 * @see GET /global-custom-fonts
526 */
527 // if ( $endpoint === 'get-user-custom-fonts-data' ) {
528 // UserData::get_user_custom_fonts_data();
529 // }
530
531 /**
532 * GET SYMBOL LIST API
533 */
534 if ($endpoint === 'get-symbol-list') {
535 Symbol::fetch_list(false, true);
536 }
537
538 if ($endpoint === 'get-page-custom-section') {
539 $type = HelperFunctions::sanitize_text(isset($_GET['type']) ? $_GET['type'] : '');
540 wp_send_json(HelperFunctions::get_page_custom_section($type, true));
541 }
542
543 /**
544 * GET Single prebuilt html API
545 */
546 if ($endpoint === 'get-pre-built-html') {
547 if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
548 wp_send_json_error('Not authorized', 401);
549 }
550 Symbol::get_pre_built_html_using_url();
551 }
552
553 /**
554 * GET DYNAMIC CONTENT API
555 */
556 if ($endpoint === 'get-dynamic-content') {
557 DynamicContent::get_dynamic_element_data();
558 }
559
560 if ($endpoint === 'get-post-terms') {
561 Taxonomy::get_post_terms();
562 }
563
564 if ($endpoint === 'get-terms') {
565 Taxonomy::get_terms();
566 }
567
568 if ($endpoint === 'get-post-type-taxonomies') {
569 Taxonomy::get_post_type_taxonomies();
570 }
571
572 if ($endpoint === 'get-all-terms-by-post-type') {
573 Taxonomy::get_all_terms_by_post_type();
574 }
575
576 if ($endpoint === 'get_visibility_condition_fields') {
577 DynamicContent::get_visibility_condition_fields();
578 }
579
580 if ($endpoint === 'get_dynamic_content_fields') {
581 DynamicContent::get_dynamic_content_fields();
582 }
583
584 /**
585 * GET WordPress MENUS API
586 */
587 if ($endpoint === 'get-wp-menus') {
588 WordpressData::get_wordpress_menus_data();
589 }
590
591 /**
592 * GET WordPress POST TYPES API
593 */
594 if ($endpoint === 'get-wp-post-types') {
595 WordpressData::get_wordpress_post_types_data();
596 }
597
598 /**
599 * GET WordPress POST TYPES API
600 */
601 if ($endpoint === 'get-wp-comment-types') {
602 WordpressData::get_wordpress_comment_types_data();
603 }
604
605 /**
606 * GET WordPress SINGLE MENU DATA API
607 */
608 if ($endpoint === 'get-wp-sigle-menu') {
609 //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
610 $term_id = HelperFunctions::sanitize_text(isset($_GET['term_id']) ? $_GET['term_id'] : null);
611 WordpressData::get_wordpress_single_menu_data($term_id);
612 }
613
614 /**
615 * PAGE SETTINGS
616 */
617 if ($endpoint === 'get-page-settings-data') {
618 PageSettings::get_page_settings_data();
619 }
620
621 if ($endpoint === 'get-custom-code') {
622 PageSettings::get_custom_code();
623 }
624
625 /**
626 * WALKTHROUGH
627 */
628 if ('get-walkthrough-shown-state' === $endpoint) {
629 Walkthrough::get_walkthrough_state();
630 }
631
632 /**
633 * COLLECTION
634 */
635 if ('get-collection' === $endpoint) {
636 Collection::get_collection();
637 }
638
639 if ('get-external-collection-options' === $endpoint) {
640 Collection::get_external_collection_options();
641 }
642
643 if ('get-external-collection-item-type' === $endpoint) {
644 Collection::get_external_collection_item_type();
645 }
646
647 /**
648 * GET USERS
649 */
650
651 if ('get-users-of-collection' === $endpoint) {
652 Users::get_users_of_collection();
653 }
654
655 /**
656 * COMMENTS
657 */
658 if ('get-comments' === $endpoint) {
659 Comments::get_comments();
660 }
661
662 /**
663 * AUTHOR LIST
664 */
665 if ('get-authors' === $endpoint) {
666 if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
667 wp_send_json_error('Not authorized', 401);
668 }
669 WordpressData::get_author_list();
670 }
671
672 /**
673 * ROLE LIST
674 */
675
676 if ('get-roles' === $endpoint) {
677 if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
678 wp_send_json_error('Not authorized', 401);
679 }
680 WordpressData::get_role_list();
681 }
682
683 /**
684 * USER LIST
685 */
686 if (
687 'get-users' === $endpoint
688 ) {
689 if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
690 wp_send_json_error('Not authorized', 401);
691 }
692 WordpressData::get_user_list();
693 }
694
695 /**
696 * CATEGORY LIST
697 */
698 if ('get-categories' === $endpoint) {
699 WordpressData::get_category_list();
700 }
701
702 /**
703 * GET ACCESS LEVEL
704 */
705 if ('editor-access-level' === $endpoint) {
706 RBAC::get_editor_access_level();
707 }
708
709 if ($endpoint === 'get-common-data') {
710 if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
711 wp_send_json_error('Not authorized', 401);
712 }
713 WpAdmin::get_common_data();
714 }
715
716 /**
717 * Collaboration data get
718 */
719 if ('collect-collaboration-actions' === $endpoint) {
720 Collaboration::send_actions();
721 }
722 /**
723 * Collaboration data get
724 */
725 if ('delete-collaboration-connection' === $endpoint) {
726 $session_id = HelperFunctions::sanitize_text($_GET['session_id']);
727 Collaboration::delete_connection($session_id);
728 }
729
730 if ($endpoint === 'get-connected-collaboration-users-list') {
731 $post_id = HelperFunctions::sanitize_text($_GET['post_id']);
732 $res = Collaboration::get_connected_collaboration_users_list($post_id);
733 wp_send_json($res);
734 }
735
736 /**
737 * Staging GET APIs
738 */
739
740 if ('get-all-staged-versions' === $endpoint) {
741 $post_id = (int) HelperFunctions::sanitize_text(isset($_GET['post_id']) ? $_GET['post_id'] : null);
742 Staging::get_all_staged_versions($post_id, false, true);
743 }
744 }
745
746 /**
747 * Check if the current request can access wp endpoints.
748 *
749 * @return bool
750 */
751 private function user_can_access_wp_apis()
752 {
753 return is_user_logged_in() && HelperFunctions::has_access(
754 array(
755 KIRKI_ACCESS_LEVELS['FULL_ACCESS'],
756 KIRKI_ACCESS_LEVELS['CONTENT_ACCESS'],
757 KIRKI_ACCESS_LEVELS['VIEW_ACCESS'],
758 )
759 );
760 }
761
762 /**
763 * Initialize the admin post apis
764 *
765 * @return void
766 */
767 public function kirki_wp_admin_post_apis()
768 {
769 if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
770 wp_send_json_error('Not authorized');
771 }
772
773 //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
774 $endpoint = HelperFunctions::sanitize_text(isset($_POST['endpoint']) ? $_POST['endpoint'] : null);
775
776 if ($endpoint === 'save-common-data') {
777 WpAdmin::save_common_data();
778 }
779
780 if ($endpoint === 'update-license-validity') {
781 WpAdmin::update_license_validity();
782 }
783
784 if ($endpoint === 'update-access-level') {
785 RBAC::update_access_level();
786 }
787
788 if ($endpoint === 'delete-form-row') {
789 Form::delete_form_row();
790 }
791
792 if ($endpoint === 'delete-form') {
793 Form::delete_form();
794 }
795
796 if ($endpoint === 'update-form-cell') {
797 Form::update_form_row();
798 }
799
800 /**
801 * Export Template
802 */
803 if ($endpoint === 'import-template') {
804 TemplateExportImport::import();
805 }
806
807 if ($endpoint === 'process-imported-template') {
808 TemplateExportImport::processImport();
809 }
810
811 if ($endpoint === 'process-export-template') {
812 TemplateExportImport::processExport();
813 }
814
815 if ($endpoint === 'save-editor-read-only-access-data') {
816 Page::save_editor_read_only_access_data();
817 }
818 /**
819 * Export Template
820 */
821
822 if ($endpoint === 'export-template') {
823 TemplateExportImport::export();
824 }
825
826 }
827
828 /**
829 * Return an explicit unauthorized response for unauthenticated admin AJAX requests.
830 *
831 * @return void
832 */
833 public function kirki_wp_admin_unauthorized()
834 {
835 wp_send_json_error('Not authorized', 401);
836 }
837
838 /**
839 * Initialize the admin get apis
840 *
841 * @return void
842 */
843 public function kirki_wp_admin_get_apis()
844 {
845 if (!is_admin()) {
846 wp_send_json_error('Not authorized', 401);
847 }
848
849 if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
850 wp_send_json_error('Not authorized', 401);
851 }
852
853 //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
854 $endpoint = HelperFunctions::sanitize_text(isset($_GET['endpoint']) ? $_GET['endpoint'] : null);
855
856 if ($endpoint === 'get-common-data') {
857 WpAdmin::get_common_data();
858 }
859
860 // From manipulation from admin dashboard.
861 if ($endpoint === 'get-forms') {
862 Form::get_forms();
863 }
864
865 if ($endpoint === 'get-form-data') {
866 Form::get_form_data();
867 }
868
869 if ($endpoint === 'get-wp-admin-page-data') {
870 Page::get_pages_for_pages_panel();
871 }
872
873 if ($endpoint === 'get-members-based-on-role') {
874 RBAC::members_based_on_role();
875 }
876
877 if ($endpoint === 'download-form-data') {
878 if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
879 wp_send_json_error('Not authorized');
880 }
881
882 Form::download_form_data();
883 }
884
885 // From manipulation from admin dashboard.
886
887 if ($endpoint === 'get-editor-read-only-access-data') {
888 if (!HelperFunctions::has_access(KIRKI_ACCESS_LEVELS['FULL_ACCESS'])) {
889 wp_send_json_error('Not authorized', 401);
890 }
891 Page::get_editor_read_only_access_data();
892 }
893 }
894 }
895