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