admin
2 years ago
pagebuilders
2 years ago
widgets
2 years ago
ajax-functions.php
2 years ago
extras.php
2 years ago
install.php
2 years ago
scripts.php
2 years ago
transient.php
2 years ago
ajax-functions.php
122 lines
| 1 | <?php |
| 2 | /** |
| 3 | * AJAX Functions |
| 4 | * |
| 5 | * Process AJAX actions. |
| 6 | * |
| 7 | * @copyright Copyright (c) 2016, Jeffrey Carandang |
| 8 | * @since 4.0 |
| 9 | */ |
| 10 | // Exit if accessed directly |
| 11 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 12 | |
| 13 | /** |
| 14 | * Save Options |
| 15 | * |
| 16 | * @since 1.0 |
| 17 | * @return void |
| 18 | */ |
| 19 | function widgetopts_ajax_save_settings(){ |
| 20 | $response = array( 'errors' => array() ); |
| 21 | |
| 22 | if( !isset( $_POST['method'] ) ) return; |
| 23 | if( !isset( $_POST['nonce'] ) ) return; |
| 24 | |
| 25 | if ( ! wp_verify_nonce( $_POST['nonce'], 'widgetopts-settings-nonce' ) ) { |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | switch ( $_POST['method'] ) { |
| 30 | case 'activate': |
| 31 | case 'deactivate': |
| 32 | if( !isset( $_POST['module'] ) ) return; |
| 33 | |
| 34 | //update options |
| 35 | update_option( 'widgetopts_tabmodule-' . sanitize_text_field( $_POST['module'] ), sanitize_text_field( $_POST['method'] ) ); |
| 36 | |
| 37 | //update global variable |
| 38 | widgetopts_update_option( sanitize_text_field( $_POST['module'] ), sanitize_text_field( $_POST['method'] ) ); |
| 39 | break; |
| 40 | |
| 41 | case 'save': |
| 42 | $response['messages'] = array( __( 'Settings saved successfully.', 'widget-options' ) ); |
| 43 | if( !isset( $_POST['data'] ) ) return; |
| 44 | parse_str( $_POST['data']['--widgetopts-form-serialized-data'], $params ); |
| 45 | $sanitized = widgetopts_sanitize_array( $params ); |
| 46 | update_option( 'widgetopts_tabmodule-settings', maybe_serialize( $sanitized ) ); |
| 47 | |
| 48 | //reset options |
| 49 | widgetopts_update_option( 'settings', $sanitized ); |
| 50 | break; |
| 51 | |
| 52 | case 'deactivate_license': |
| 53 | global $extended_license; |
| 54 | $license = sanitize_text_field( $_POST['data']['license-data'] ); |
| 55 | if( !empty( $license ) ){ |
| 56 | |
| 57 | if( isset( $_POST['data']['shortname'] ) ){ |
| 58 | $item_shortname = sanitize_text_field( $_POST['data']['shortname'] ); |
| 59 | }else{ |
| 60 | $item_shortname = 'widgetopts_' . preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( WIDGETOPTS_PLUGIN_NAME ) ) ); |
| 61 | } |
| 62 | switch ( $item_shortname ) { |
| 63 | case 'widgetopts_sliding_widget_options': |
| 64 | global $widgetopts_sliding_license; |
| 65 | $data = $widgetopts_sliding_license->deactivate_license( $license ); |
| 66 | break; |
| 67 | |
| 68 | default: |
| 69 | $data = $extended_license->deactivate_license( $license ); |
| 70 | break; |
| 71 | } |
| 72 | |
| 73 | $response['button'] = sanitize_text_field( $_POST['data']['button'] ); |
| 74 | if( $data == 'deactivated' ){ |
| 75 | |
| 76 | $optiondata = get_option( 'widgetopts_license_keys' ); |
| 77 | $name = str_replace( 'widgetopts-license-btn-', '', sanitize_text_field( $_POST['data']['button'] ) ); |
| 78 | $optiondata[ $name ] = ''; |
| 79 | update_option( 'widgetopts_license_keys', $optiondata ); |
| 80 | |
| 81 | //remove license key on option |
| 82 | delete_option( $item_shortname . '_license_key' ); |
| 83 | |
| 84 | $response['messages'] = array( __( 'Successfully Deactivated.', 'widget-options' ) ); |
| 85 | }else{ |
| 86 | $response['messages'] = array( __( 'Deactivation Failed.', 'widget-options' ) ); |
| 87 | } |
| 88 | $response['success'] = $data; |
| 89 | } |
| 90 | |
| 91 | break; |
| 92 | |
| 93 | default: |
| 94 | # code... |
| 95 | break; |
| 96 | } |
| 97 | $response['source'] = 'WIDGETOPTS_Response'; |
| 98 | $response['response'] = 'success'; |
| 99 | $response['closeModal'] = true; |
| 100 | $response = (object) $response; |
| 101 | |
| 102 | //let devs do there action |
| 103 | do_action( 'widget_options_before_ajax_print', sanitize_text_field( $_POST['method'] ) ); |
| 104 | |
| 105 | echo json_encode( $response ); |
| 106 | die(); |
| 107 | } |
| 108 | add_action( 'wp_ajax_widgetopts_ajax_settings', 'widgetopts_ajax_save_settings' ); |
| 109 | |
| 110 | /* Hide the rating div |
| 111 | * @return json string |
| 112 | * |
| 113 | */ |
| 114 | if( !function_exists( 'widgetopts_ajax_hide_rating' ) ): |
| 115 | function widgetopts_ajax_hide_rating(){ |
| 116 | update_option('widgetopts_RatingDiv','yes'); |
| 117 | echo json_encode(array("success")); exit; |
| 118 | } |
| 119 | add_action( 'wp_ajax_widgetopts_hideRating', 'widgetopts_ajax_hide_rating' ); |
| 120 | endif; |
| 121 | ?> |
| 122 |