classes
5 months ago
compatibility
1 year ago
metaboxes
5 months ago
admin-ajax.php
1 month ago
admin-hooks.php
1 year ago
admin-the-functions.php
1 year ago
index.php
2 years ago
admin-ajax.php
524 lines
| 1 | <?php |
| 2 | |
| 3 | function auxin_ajax_send_feedback(){ |
| 4 | |
| 5 | // skip if the form data is not receiced |
| 6 | if( empty( $_POST['form'] ) ){ |
| 7 | wp_send_json_error( __( 'Data cannot be delivered, please try again.', 'auxin-elements' ) ); |
| 8 | } |
| 9 | |
| 10 | |
| 11 | // extract the form data |
| 12 | $rate = ( ! empty( $_POST['form']['theme_rate'] ) || $_POST['form']['theme_rate'] === '0' ) ? sanitize_text_field( $_POST['form']['theme_rate'] ) : ''; |
| 13 | $feedback = ! empty( $_POST['form']['feedback'] ) ? sanitize_text_field( $_POST['form']['feedback'] ) : ''; |
| 14 | $email = ! empty( $_POST['form']['email'] ) ? sanitize_email( $_POST['form']['email'] ) : ''; |
| 15 | $nonce = ! empty( $_POST['form']['_wpnonce'] ) ? sanitize_text_field( $_POST['form']['_wpnonce'] ) : ''; |
| 16 | |
| 17 | if( ! wp_verify_nonce( $nonce, 'phlox_feedback' ) ){ |
| 18 | wp_send_json_error( __( 'Authorization failed!', 'auxin-elements' ) ); |
| 19 | } |
| 20 | |
| 21 | if ( ! current_user_can('manage_options') ) { |
| 22 | wp_send_json_error( __( "Access Denied: You don't have the required permissions!", 'auxin-elements' ) ); |
| 23 | } |
| 24 | |
| 25 | if( $rate || $rate === '0' ){ |
| 26 | |
| 27 | global $wp_version; |
| 28 | |
| 29 | $passed_diff_time = auxin_get_passed_installed_time(); |
| 30 | $installed_days = isset( $passed_diff_time->days ) ? $passed_diff_time->days : 1; |
| 31 | |
| 32 | $args = array( |
| 33 | 'user-agent' => 'WordPress/'.$wp_version.'; '. get_home_url(), |
| 34 | 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 5), |
| 35 | 'body' => array( |
| 36 | 'cat' => 'rating', |
| 37 | 'action' => 'submit', |
| 38 | 'item-slug' => 'phlox', |
| 39 | 'rate' => $rate, |
| 40 | 'client_key' => get_theme_mod( 'client_key', ''), |
| 41 | 'item_version'=> THEME_VERSION, |
| 42 | 'theme_slug' => THEME_ID, |
| 43 | 'feedback' => $feedback, |
| 44 | 'is_active' => function_exists('auxin_is_activated') && auxin_is_activated(), |
| 45 | 'installed_days' => $installed_days |
| 46 | ) |
| 47 | ); |
| 48 | // send the rating through the api |
| 49 | $request = wp_remote_post( 'https://api.averta.net/envato/items/', $args ); |
| 50 | update_option( 'auxin_show_rate_scale_notice', 0 ); |
| 51 | set_theme_mod( 'rate_scale_notice_remind_later_date', 0 ); |
| 52 | // if ( ! is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) === 200 ) {} |
| 53 | |
| 54 | // store the user rating on the website |
| 55 | auxin_update_option( 'user_rating', $rate ); |
| 56 | |
| 57 | // send the feedback via email |
| 58 | $message = 'Rate: '. $rate . "\r\n" . 'Email: <' . $email . ">\r\n\r\n" . $feedback; |
| 59 | wp_mail( 'feedbacks@averta.net', 'Feedback from phlox dashboard:', $message ); |
| 60 | |
| 61 | wp_send_json_success( __( 'Sent Successfully. Thanks for your feedback!', 'auxin-elements' ) ); |
| 62 | |
| 63 | } else{ |
| 64 | wp_send_json_error( __( 'An error occurred. Feedback could not be delivered, please try again.', 'auxin-elements' ) ); |
| 65 | } |
| 66 | |
| 67 | } |
| 68 | |
| 69 | add_action( 'wp_ajax_send_feedback', 'auxin_ajax_send_feedback' ); |
| 70 | |
| 71 | /** |
| 72 | * Hide Feedback notice |
| 73 | */ |
| 74 | function auxin_remove_feedback_notice() { |
| 75 | // skip if the form data is not receiced |
| 76 | if( empty( $_POST['form'] ) ){ |
| 77 | wp_send_json_error( __( 'Data cannot be delivered, please try again.', 'auxin-elements' ) ); |
| 78 | } |
| 79 | |
| 80 | $nonce = ! empty( $_POST['form']['_wpnonce'] ) ? sanitize_text_field( $_POST['form']['_wpnonce'] ) : ''; |
| 81 | |
| 82 | if( ! wp_verify_nonce( $nonce, 'phlox_feedback' ) ){ |
| 83 | wp_send_json_error( __( 'Authorization failed!', 'auxin-elements' ) ); |
| 84 | } |
| 85 | |
| 86 | if ( ! current_user_can('manage_options') ) { |
| 87 | wp_send_json_error( __( "Access Denied: You don't have the required permissions!", 'auxin-elements' ) ); |
| 88 | } |
| 89 | |
| 90 | update_option( 'auxin_show_rate_scale_notice', 0 ); |
| 91 | set_theme_mod( 'rate_scale_notice_remind_later_date', 0 ); |
| 92 | |
| 93 | wp_send_json_success(); |
| 94 | } |
| 95 | |
| 96 | add_action( 'wp_ajax_aux-remove-feedback-notice', 'auxin_remove_feedback_notice' ); |
| 97 | |
| 98 | |
| 99 | /** |
| 100 | * Remind feedback |
| 101 | */ |
| 102 | function auxin_ajax_remind_feedback() { |
| 103 | // skip if the form data is not receiced |
| 104 | if( empty( $_POST['form'] ) ){ |
| 105 | wp_send_json_error( __( 'Data cannot be delivered, please try again.', 'auxin-elements' ) ); |
| 106 | } |
| 107 | |
| 108 | $nonce = ! empty( $_POST['form']['_wpnonce'] ) ? sanitize_text_field( $_POST['form']['_wpnonce'] ) : ''; |
| 109 | |
| 110 | if( ! wp_verify_nonce( $nonce, 'phlox_feedback' ) || ! current_user_can('manage_options') ){ |
| 111 | wp_send_json_error( __( 'Authorization failed!', 'auxin-elements' ) ); |
| 112 | } |
| 113 | |
| 114 | // reset feedback notice viewer |
| 115 | update_option( 'auxin_show_rate_scale_notice', 0 ); |
| 116 | set_theme_mod( 'rate_scale_notice_remind_later_date', time() + DAY_IN_SECONDS * 3 ); |
| 117 | |
| 118 | wp_send_json_success(); |
| 119 | } |
| 120 | |
| 121 | add_action( 'wp_ajax_remind_feedback', 'auxin_ajax_remind_feedback' ); |
| 122 | |
| 123 | |
| 124 | |
| 125 | function auxin_ajax_isotope_filter_group(){ |
| 126 | // Check nonce |
| 127 | if ( ! isset( $_POST['group'] ) ||! isset( $_POST['key'] ) || ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'aux-iso-group' ) ) { |
| 128 | wp_send_json_error( __( 'Token Error.', 'auxin-elements' ) ); |
| 129 | } |
| 130 | |
| 131 | if ( ! current_user_can('manage_options') ) { |
| 132 | wp_send_json_error( __( "Access Denied: You don't have the required permissions!", 'auxin-elements' ) ); |
| 133 | } |
| 134 | |
| 135 | if( false !== update_option( 'aux_isotope_group_' . auxin_sanitize_input( $_POST['key'] ) , auxin_sanitize_input( $_POST['group'] ) ) ) { |
| 136 | wp_send_json_success( __( 'It\'s Done.', 'auxin-elements' ) ); |
| 137 | } |
| 138 | |
| 139 | wp_send_json_error( __( 'An error occurred.', 'auxin-elements' ) ); |
| 140 | } |
| 141 | add_action( 'wp_ajax_aux_isotope_group', 'auxin_ajax_isotope_filter_group' ); |
| 142 | |
| 143 | |
| 144 | function auxin_ajax_filter_get_content() { |
| 145 | |
| 146 | // Check nonce |
| 147 | if ( ! isset( $_POST['n'] ) || ! wp_verify_nonce( $_POST['n'], 'aux_ajax_filter_request' ) ) { |
| 148 | wp_send_json_error( 'Nonce check failed!', 403 ); |
| 149 | } |
| 150 | |
| 151 | $num = sanitize_text_field( $_POST['num'] ); |
| 152 | $post_type = 'product'; |
| 153 | $tax = sanitize_text_field( $_POST['taxonomy'] ); |
| 154 | $term = sanitize_text_field( $_POST['term'] ); |
| 155 | $image_class = 'aux-img-dynamic-dropshadow'; |
| 156 | $width = sanitize_text_field( $_POST['width'] ); |
| 157 | $height = sanitize_text_field( $_POST['height'] ); |
| 158 | $order = sanitize_text_field( $_POST['order'] ); |
| 159 | $orderby = sanitize_text_field( $_POST['orderby'] ); |
| 160 | $size = array( 'width' => $width, 'height' => $height ); |
| 161 | |
| 162 | /* |
| 163 | * The WordPress Query class. |
| 164 | * |
| 165 | * @link http://codex.wordpress.org/Function_Reference/WP_Query |
| 166 | */ |
| 167 | $args = array( |
| 168 | // Type & Status Parameters |
| 169 | 'post_type' => $post_type, |
| 170 | 'post_status' => 'publish', |
| 171 | // Pagination Parameters |
| 172 | 'posts_per_page' => $num, |
| 173 | 'nopaging' => false, |
| 174 | 'order' => $order, |
| 175 | 'orderby' => $orderby, |
| 176 | ); |
| 177 | |
| 178 | if ( 'all' !== $term ) { |
| 179 | // Taxonomy Parameters |
| 180 | $args['tax_query'] = array( |
| 181 | array( |
| 182 | 'taxonomy' => $tax, |
| 183 | 'field' => 'slug', |
| 184 | 'terms' => $term, |
| 185 | 'include_children' => true, |
| 186 | 'operator' => 'IN', |
| 187 | ) |
| 188 | ); |
| 189 | } |
| 190 | |
| 191 | $posts = get_posts( $args ); |
| 192 | |
| 193 | foreach ( $posts as $post ) { |
| 194 | |
| 195 | $image_id = get_post_thumbnail_id( $post ); |
| 196 | $product = wc_get_product( $post->ID ); |
| 197 | |
| 198 | $post->thumb = auxin_get_the_responsive_attachment( |
| 199 | $image_id, |
| 200 | array( |
| 201 | 'quality' => 100, |
| 202 | 'upscale' => true, |
| 203 | 'crop' => true, |
| 204 | 'add_hw' => true, // whether add width and height attr or not |
| 205 | 'attr' => array( |
| 206 | 'class' => 'auxshp-product-image auxshp-attachment ' . $image_class, |
| 207 | 'data-original-width' => $width, |
| 208 | 'data-original-height' => $height, |
| 209 | 'data-original-src' => wp_get_attachment_image_src( $image_id, 'full' )[0] |
| 210 | ), |
| 211 | 'size' => $size, |
| 212 | 'image_sizes' => 'auto', |
| 213 | 'srcset_sizes' => 'auto', |
| 214 | 'original_src' => true |
| 215 | ) |
| 216 | ); |
| 217 | |
| 218 | $post->price = $product->get_price_html(); |
| 219 | $post->meta = wc_get_product_category_list( $product->get_id(), ', ', '<em class="auxshp-meta-terms">', '</em>' ); |
| 220 | $post->badge = $product->is_on_sale() ? true : false; |
| 221 | |
| 222 | $isAjaxEnabled = class_exists( 'AUXSHP' ) ? auxin_is_true( auxin_get_option( 'product_index_ajax_add_to_cart', '1' ) ) : auxin_is_true( get_option( 'woocommerce_enable_ajax_add_to_cart' ) ); |
| 223 | if( $isAjaxEnabled ) { |
| 224 | $class = 'button aux-ajax-add-to-cart add_to_cart_button'; |
| 225 | } |
| 226 | |
| 227 | $post->cart = apply_filters( 'woocommerce_loop_add_to_cart_link', |
| 228 | sprintf( '<a rel="nofollow" href="%s" data-quantity="1" data-product_id="%s" data-product_sku="%s" data-verify_nonce="%s" class="%s"><i class="aux-ico auxicon-handbag"></i><span>%s</span></a>', |
| 229 | esc_url( $product->add_to_cart_url() ), |
| 230 | esc_attr( $product->get_id() ), |
| 231 | esc_attr( $product->get_sku() ), |
| 232 | esc_attr( wp_create_nonce( 'aux_add_to_cart-' . $product->get_id() ) ), |
| 233 | esc_attr( isset( $class ) ? $class : 'button add_to_cart_button' ), |
| 234 | esc_html( $product->add_to_cart_text() ) |
| 235 | ), |
| 236 | $product ); |
| 237 | } |
| 238 | |
| 239 | wp_send_json_success( $posts ); |
| 240 | |
| 241 | } |
| 242 | |
| 243 | add_action( 'wp_ajax_filter_get_content', 'auxin_ajax_filter_get_content' ); |
| 244 | add_action( 'wp_ajax_noprive_filter_get_content', 'auxin_ajax_filter_get_content' ); |
| 245 | |
| 246 | /** |
| 247 | * wordpress ajax for dismissed notice |
| 248 | * |
| 249 | * @return json |
| 250 | */ |
| 251 | function auxin_dismissed_notice(){ |
| 252 | // Store it in the options table |
| 253 | if ( ! isset( $_POST['id'] ) || ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], '_notice_nonce' ) || ! current_user_can('manage_options') ) { |
| 254 | wp_send_json_error( __( 'Token Error.', 'auxin-elements' ) ); |
| 255 | } else { |
| 256 | auxin_set_transient( sanitize_text_field( 'auxin-notice-' . $_POST['id'] ), 1, sanitize_text_field( $_POST['expiration'] ) ); |
| 257 | wp_send_json_success( __( 'It\'s OK.', 'auxin-elements' ) ); |
| 258 | } |
| 259 | } |
| 260 | add_action( 'wp_ajax_auxin_dismissed_notice', 'auxin_dismissed_notice' ); |
| 261 | |
| 262 | /** |
| 263 | * WordPress ajax to display activation form |
| 264 | * |
| 265 | * @return html |
| 266 | */ |
| 267 | function auxin_display_actvation_form(){ |
| 268 | if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], 'aux-activation-form' ) ) { |
| 269 | // This nonce is not valid. |
| 270 | wp_die( esc_html__( 'Security Token Error!', 'auxin-elements' ) ); |
| 271 | } |
| 272 | ob_start(); |
| 273 | ?> |
| 274 | <div class="aux-license-popup"> |
| 275 | <button class="featherlight-close-icon featherlight-close" aria-label="Close">✕</button> |
| 276 | <img class="aux-popup-image" src="<?php echo esc_url( AUXELS_ADMIN_URL . '/assets/images/welcome/activation.svg' ); ?>" /> |
| 277 | <h2 class="aux-popup-title"><?php esc_html_e( 'License Activation', 'auxin-elements' ); ?></h2> |
| 278 | <p class="aux-popup-desc"><?php esc_html_e( 'Please activate your license to get automatic updates, premium support, and unlimited access to the template library and demo importer.', 'auxin-elements' ); printf(' <a href="https://help.market.envato.com/hc/en-us/articles/202822600-Where-Is-My-Purchase-Code-" target="_blank">%s</a>', esc_html( 'how to find purchase code?', 'auxin-elements' ) ); ?></p> |
| 279 | <form class="auxin-form auxin-check-purchase" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" method="post"> |
| 280 | <div class="form-group"> |
| 281 | <label class="form-label" for="aux-usermail"><?php esc_html_e( 'E-mail address', 'auxin-elements' ); ?></label> |
| 282 | <input class="form-control" type="text" name="usermail" value="<?php echo esc_attr( get_option('admin_email') ); ?>" required> |
| 283 | </div> |
| 284 | |
| 285 | <div class="form-group"> |
| 286 | <label class="form-label" for="aux-purchase"><?php esc_html_e( 'Purchase code', 'auxin-elements' ); ?></label> |
| 287 | <input class="form-control" type="text" name="purchase" required> |
| 288 | </div> |
| 289 | |
| 290 | <?php wp_nonce_field( 'auxin-purchase-activation', 'security' ); ?> |
| 291 | <input type="hidden" name="action" value="auxin_purchase_activation"> |
| 292 | <div class="button-group"> |
| 293 | <button type="submit" class="aux-button aux-primary aux-medium aux-activate-license" value="submit"> |
| 294 | <span><?php esc_html_e( 'Activate', 'auxin-elements' ); ?></span> |
| 295 | </button> |
| 296 | </div> |
| 297 | </form> |
| 298 | </div> |
| 299 | <?php |
| 300 | wp_die( ob_get_clean() ); |
| 301 | } |
| 302 | add_action( 'wp_ajax_auxin_display_actvation_form', 'auxin_display_actvation_form' ); |
| 303 | |
| 304 | /** |
| 305 | * wordpress ajax for auxin purchase activation |
| 306 | * |
| 307 | * @return json |
| 308 | */ |
| 309 | function auxin_purchase_activation(){ |
| 310 | |
| 311 | if ( ! current_user_can( 'manage_options') ) { |
| 312 | wp_send_json_error( array( |
| 313 | 'message' => __( 'Persmission Error.', 'auxin-elements' ), |
| 314 | 'buttonText' => __( 'Close', 'auxin-elements' ), |
| 315 | ) ); |
| 316 | } |
| 317 | |
| 318 | if ( ! isset( $_POST['usermail'] ) || ! isset( $_POST['purchase'] ) || ! isset( $_POST['security'] ) || ! wp_verify_nonce( $_POST['security'], 'auxin-purchase-activation' ) ) { |
| 319 | wp_send_json_error( array( |
| 320 | 'message' => __( 'Token Error.', 'auxin-elements' ), |
| 321 | 'buttonText' => __( 'Retry', 'auxin-elements' ), |
| 322 | ) ); |
| 323 | } |
| 324 | |
| 325 | $usermail = sanitize_email( $_POST['usermail'] ); |
| 326 | $purchase_code = auxin_sanitize_input( $_POST['purchase'] ); |
| 327 | $action = 'activate'; |
| 328 | |
| 329 | $result = Auxin_License_Activation::get_instance()->license_action( $usermail, $purchase_code, $action ); |
| 330 | |
| 331 | if( isset( $result['success'] ) && $result['success'] ){ |
| 332 | $result['buttonText'] = __( 'Close', 'auxin-elements' ); |
| 333 | wp_send_json_success( $result ); |
| 334 | } |
| 335 | |
| 336 | $result['buttonText'] = __( 'Retry', 'auxin-elements' ); |
| 337 | wp_send_json_error( $result ); |
| 338 | |
| 339 | } |
| 340 | add_action( 'wp_ajax_auxin_purchase_activation', 'auxin_purchase_activation' ); |
| 341 | |
| 342 | /** |
| 343 | * wordpress ajax for auxin upgrader |
| 344 | * |
| 345 | * @return json |
| 346 | */ |
| 347 | function auxin_ajax_upgrader(){ |
| 348 | // Check ajax nonce field |
| 349 | check_ajax_referer( 'auxin-start-upgrading', 'nonce' ); |
| 350 | |
| 351 | if ( ! isset( $_POST['key'] ) || ! isset( $_POST['type'] ) ) { |
| 352 | wp_send_json_error( array( |
| 353 | 'slug' => '', |
| 354 | 'errorCode' => 'no_token_specified', |
| 355 | 'errorMessage' => __( 'Token Error.', 'auxin-elements' ) |
| 356 | ) ); |
| 357 | } |
| 358 | |
| 359 | if ( ! current_user_can( 'manage_options' ) ) { |
| 360 | wp_send_json_error( array( |
| 361 | 'slug' => '', |
| 362 | 'errorCode' => 'permission_error', |
| 363 | 'errorMessage' => __( 'Permission Error.', 'auxin-elements' ) |
| 364 | ) ); |
| 365 | } |
| 366 | |
| 367 | $handler = new Auxin_Upgrader_Ajax_Handlers; |
| 368 | $handler->run( sanitize_text_field( $_POST['key'] ), sanitize_text_field( $_POST['type'] ) ); |
| 369 | } |
| 370 | add_action( 'wp_ajax_auxin_start_upgrading', 'auxin_ajax_upgrader' ); |
| 371 | |
| 372 | |
| 373 | /** |
| 374 | * wordpress ajax for auxin customizer export |
| 375 | * |
| 376 | * @return json |
| 377 | */ |
| 378 | function auxin_customizer_export(){ |
| 379 | |
| 380 | if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'auxin-export-control' ) ) { |
| 381 | wp_send_json_error( __( 'Token Error.', 'auxin-elements' ) ); |
| 382 | } |
| 383 | |
| 384 | if ( ! current_user_can( 'manage_options' ) ) { |
| 385 | wp_send_json_error( __('Permission Error.', 'auxin-elements' ) ); |
| 386 | } |
| 387 | |
| 388 | // Get theme options |
| 389 | $theme_options = auxin_options(); |
| 390 | |
| 391 | // Get theme mods |
| 392 | $theme_mods = get_theme_mods(); |
| 393 | $filters = array( 0, 'nav_menu_locations', 'custom_css_post_id', 'last_checked_version' ); |
| 394 | foreach ( $filters as $filter ) { |
| 395 | if ( isset( $theme_mods[ $filter ] ) ) { |
| 396 | unset( $theme_mods[ $filter ] ); |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | if( empty( $theme_options ) && empty( $theme_mods ) ){ |
| 401 | wp_send_json_error( __( 'No data found!', 'auxin-elements' ) ); |
| 402 | } |
| 403 | |
| 404 | $b64_content = base64_encode( wp_json_encode( array( |
| 405 | 'theme_options' => $theme_options, |
| 406 | 'theme_mods' => $theme_mods |
| 407 | ) ) ); |
| 408 | |
| 409 | wp_send_json_success( array( |
| 410 | 'content' => $b64_content, |
| 411 | 'fileName' => THEME_ID . '_export_' . current_time('timestamp') . '.txt' |
| 412 | ) ); |
| 413 | |
| 414 | } |
| 415 | add_action( 'wp_ajax_auxin_customizer_export', 'auxin_customizer_export' ); |
| 416 | |
| 417 | |
| 418 | /** |
| 419 | * wordpress ajax for auxin customizer import |
| 420 | * |
| 421 | * @return json |
| 422 | */ |
| 423 | function auxin_customizer_import(){ |
| 424 | // Check security |
| 425 | if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'auxin-import-control' ) ) { |
| 426 | wp_send_json_error( __( 'Token Error.', 'auxin-elements' ) ); |
| 427 | } |
| 428 | |
| 429 | if ( ! current_user_can('manage_options') ) { |
| 430 | wp_send_json_error( __( "Access Denied: You don't have the required permissions!", 'auxin-elements' ) ); |
| 431 | } |
| 432 | |
| 433 | // Check input file |
| 434 | if ( ! isset( $_FILES['file'] ) || 0 < $_FILES['file']['error'] ) { |
| 435 | wp_send_json_error( __( 'Please upload a valid file.', 'auxin-elements' ) ); |
| 436 | } |
| 437 | |
| 438 | // Get and decode file content |
| 439 | global $wp_filesystem; |
| 440 | if ( empty($wp_filesystem) ) { |
| 441 | require_once( ABSPATH . '/wp-admin/includes/file.php' ); |
| 442 | WP_Filesystem(); |
| 443 | } |
| 444 | $json_content = $wp_filesystem->get_contents( $_FILES['file']['tmp_name'] ); |
| 445 | $array_content = json_decode( base64_decode( $json_content ), true ); |
| 446 | $array_content = auxin_sanitize_input( $array_content ); |
| 447 | |
| 448 | // Check array empty |
| 449 | if ( empty( $array_content ) || ! is_array( $array_content ) ) { |
| 450 | wp_send_json_error( __( 'Invalid or Empty Data.', 'auxin-elements' ) ); |
| 451 | } |
| 452 | |
| 453 | if( isset( $array_content['theme_options'] ) ){ |
| 454 | // Get image options names |
| 455 | $get_options = auxin_get_defined_options(); |
| 456 | $custom_images = array(); |
| 457 | foreach ( $get_options['fields'] as $key => $value ) { |
| 458 | if ( ! array_search( 'image', $value ) ) { |
| 459 | continue; |
| 460 | } |
| 461 | $custom_images[] = $value['id']; |
| 462 | } |
| 463 | // Update options |
| 464 | foreach ( $array_content['theme_options'] as $auxin_key => $auxin_value ) { |
| 465 | if ( in_array( $auxin_key, $custom_images ) && ! empty( $auxin_value ) ) { |
| 466 | continue; |
| 467 | } |
| 468 | // Update exclusive auxin options |
| 469 | auxin_update_option( $auxin_key , $auxin_value ); |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | if( isset( $array_content['theme_mods'] ) ){ |
| 474 | foreach ( $array_content['theme_mods'] as $theme_mods_key => $theme_mods_value ) { |
| 475 | // Start theme mods loop: |
| 476 | if( $theme_mods_key === 'custom_logo' ) { |
| 477 | continue; |
| 478 | } |
| 479 | // Update theme mods |
| 480 | set_theme_mod( $theme_mods_key , $theme_mods_value ); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | // force to flush dynamic asset files |
| 485 | delete_transient( 'auxin_' . AUXELS_SLUG . '_version' ); |
| 486 | |
| 487 | wp_send_json_success( __( 'Successfully Imported.', 'auxin-elements' ) ); |
| 488 | |
| 489 | } |
| 490 | add_action( 'wp_ajax_auxin_customizer_import', 'auxin_customizer_import' ); |
| 491 | |
| 492 | |
| 493 | /** |
| 494 | * Ajax handler for auxin_template_library control to import template |
| 495 | * |
| 496 | * @return json |
| 497 | */ |
| 498 | function auxin_template_control_importer() { |
| 499 | $template_type = sanitize_text_field( $_POST['template_type'] ); |
| 500 | if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'customizer-template-library-' . $template_type ) ) { |
| 501 | wp_send_json_error([ |
| 502 | 'message' => __( 'Authorization failed!', 'auxin-elements') |
| 503 | ]); |
| 504 | } |
| 505 | |
| 506 | if ( ! current_user_can('manage_options') ) { |
| 507 | wp_send_json_error( [ |
| 508 | 'message' => __( "Access Denied: You don't have the required permissions!", 'auxin-elements' ) |
| 509 | ]); |
| 510 | } |
| 511 | |
| 512 | // Strict validation for ID |
| 513 | if ( ! isset( $_POST['id'] ) || ! ctype_digit( $_POST['id'] ) ) { |
| 514 | wp_send_json_error([ |
| 515 | 'message' => __('Invalid template ID.', 'auxin-elements') |
| 516 | ]); |
| 517 | } |
| 518 | |
| 519 | $template_id = absint($_POST['id']); |
| 520 | |
| 521 | wp_send_json( auxin_template_importer( $template_id, $template_type, 'update_menu' ) ); |
| 522 | } |
| 523 | add_action( 'wp_ajax_auxin_template_control_importer', 'auxin_template_control_importer' ); |
| 524 |