Collaboration
3 weeks ago
Apps.php
3 weeks ago
Collection.php
1 month ago
Comments.php
2 months ago
DynamicContent.php
1 month ago
ExportImport.php
3 weeks ago
Form.php
3 weeks ago
Media.php
3 weeks ago
Page.php
3 weeks ago
PageSettings.php
3 weeks ago
RBAC.php
3 weeks ago
Symbol.php
3 weeks ago
Taxonomy.php
2 months ago
TemplateExportImport.php
2 months ago
UserData.php
3 weeks ago
Users.php
2 months ago
Walkthrough.php
2 months ago
WordpressData.php
2 months ago
WpAdmin.php
2 months ago
WpAdmin.php
143 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WpAdmin dashboard api calls |
| 4 | * |
| 5 | * @package kirki |
| 6 | */ |
| 7 | |
| 8 | namespace Kirki\Ajax; |
| 9 | |
| 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | exit; // Exit if accessed directly. |
| 12 | } |
| 13 | use Kirki\HelperFunctions; |
| 14 | |
| 15 | |
| 16 | /** |
| 17 | * WpAdmin API Class |
| 18 | */ |
| 19 | class WpAdmin { |
| 20 | |
| 21 | /** |
| 22 | * Save common data from dashboard |
| 23 | * |
| 24 | * @return void wp_send_json. |
| 25 | */ |
| 26 | public static function save_common_data() { |
| 27 | //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 28 | $data = isset( $_POST['data'] ) ? $_POST['data'] : null; |
| 29 | $data = json_decode( stripslashes( $data ), true ); |
| 30 | |
| 31 | $new_data = self::get_common_data( true ); |
| 32 | |
| 33 | if ( isset( $data['license_key'], $data['license_key']['key'] ) ) { |
| 34 | if ( $data['license_key']['key'] !== '' ) { |
| 35 | $license_key = $data['license_key']['key']; |
| 36 | $license_info = HelperFunctions::get_my_license_info( $license_key ); |
| 37 | $new_data['license_key'] = $license_info; |
| 38 | } else { |
| 39 | $new_data['license_key'] = array( |
| 40 | 'key' => '', |
| 41 | 'valid' => false, |
| 42 | ); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | if ( isset( $data['json_upload'] ) ) { |
| 47 | $new_data['json_upload'] = $data['json_upload']; |
| 48 | } |
| 49 | if ( isset( $data['pexels_api_key'] ) ) { |
| 50 | $new_data['pexels_api_key'] = $data['pexels_api_key']; |
| 51 | } |
| 52 | if ( isset( $data['pexels_status'] ) ) { |
| 53 | $new_data['pexels_status'] = $data['pexels_status']; |
| 54 | } |
| 55 | if ( isset( $data['svg_upload'] ) ) { |
| 56 | $new_data['svg_upload'] = $data['svg_upload']; |
| 57 | } |
| 58 | if ( isset( $data['is_show_wp_theme_header_footer'] ) ) { |
| 59 | $new_data['is_show_wp_theme_header_footer'] = $data['is_show_wp_theme_header_footer']; |
| 60 | } |
| 61 | if ( isset( $data['image_optimization'] ) ) { |
| 62 | $new_data['image_optimization'] = $data['image_optimization']; |
| 63 | } |
| 64 | |
| 65 | if ( isset( $data['unsplash_api_key'] ) ) { |
| 66 | $new_data['unsplash_api_key'] = $data['unsplash_api_key']; |
| 67 | } |
| 68 | if ( isset( $data['unsplash_status'] ) ) { |
| 69 | $new_data['unsplash_status'] = $data['unsplash_status']; |
| 70 | } |
| 71 | |
| 72 | if ( isset( $data['reCAPTCHA_status'] ) ) { |
| 73 | $new_data['reCAPTCHA_status'] = $data['reCAPTCHA_status']; |
| 74 | } |
| 75 | |
| 76 | if ( isset( $data['smooth_scroll'] ) ) { |
| 77 | $new_data['smooth_scroll'] = $data['smooth_scroll']; |
| 78 | } |
| 79 | |
| 80 | if ( isset( $data['recaptcha'] ) ) { |
| 81 | // set data version wise, e.g: { GRC_version: '2.0', '2.0:{}, '3.0:{} }. |
| 82 | $new_data['recaptcha']['GRC_version'] = $data['recaptcha']['GRC_version']; |
| 83 | $new_data['recaptcha'][ $new_data['recaptcha']['GRC_version'] ] = $data['recaptcha'][ $data['recaptcha']['GRC_version'] ]; |
| 84 | } |
| 85 | |
| 86 | if ( isset( $data['chatGPT_api_key'] ) ) { |
| 87 | $new_data['chatGPT_api_key'] = $data['chatGPT_api_key']; |
| 88 | } |
| 89 | if ( isset( $data['chatGPT_status'] ) ) { |
| 90 | $new_data['chatGPT_status'] = $data['chatGPT_status']; |
| 91 | } |
| 92 | |
| 93 | update_option( KIRKI_WP_ADMIN_COMMON_DATA, $new_data, false ); |
| 94 | |
| 95 | wp_send_json( |
| 96 | array( |
| 97 | 'status' => 'success', |
| 98 | 'data' => self::get_common_data( true ), |
| 99 | ) |
| 100 | ); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Get common data |
| 105 | * |
| 106 | * @param boolean $inernal if this method call from intenally. |
| 107 | * @return void|array wp_send_json. |
| 108 | */ |
| 109 | public static function get_common_data( $inernal = false ) { |
| 110 | $data = get_option( KIRKI_WP_ADMIN_COMMON_DATA, array() ); |
| 111 | $data['post_max_size'] = ini_get( 'post_max_size' ); |
| 112 | $data['php_zip_ext_enabled'] = class_exists( 'ZipArchive' ); |
| 113 | if ( ! isset( $data['is_show_wp_theme_header_footer'] ) ) { |
| 114 | $data['is_show_wp_theme_header_footer'] = true; |
| 115 | } |
| 116 | if ( $inernal ) { |
| 117 | return $data; |
| 118 | } else { |
| 119 | if ( HelperFunctions::is_api_call_from_editor_preview() ) { |
| 120 | wp_send_json( array( 'license_key' => $data['license_key'] ) ); |
| 121 | } |
| 122 | wp_send_json( $data ); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Update common data license and editor type data. |
| 128 | * |
| 129 | * @return void wp_send_json_success. |
| 130 | */ |
| 131 | public static function update_license_validity() { |
| 132 | $valid = filter_input( INPUT_POST, 'valid', FILTER_VALIDATE_BOOLEAN ); |
| 133 | $data = self::get_common_data( true ); |
| 134 | |
| 135 | if ( isset( $data['license_key'] ) ) { |
| 136 | $data['license_key']['valid'] = $valid; |
| 137 | |
| 138 | update_option( KIRKI_WP_ADMIN_COMMON_DATA, $data, false ); |
| 139 | wp_send_json_success( true ); |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 |