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