PluginProbe ʕ •ᴥ•ʔ
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets / 3.8.10
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets v3.8.10
4.2.5 4.2.4 trunk 3.7.10 3.7.11 3.7.12 3.7.13 3.7.14 3.7.2 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8 3.8.1 3.8.10 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.8.8 3.8.9 3.8.9.1 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.5.1 4.0.6 4.0.6.1 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.2.0 4.2.1 4.2.2 4.2.3
widget-options / includes / ajax-functions.php
widget-options / includes Last commit date
admin 3 years ago pagebuilders 3 years ago widgets 3 years ago ajax-functions.php 8 years ago extras.php 4 years ago install.php 4 years ago scripts.php 4 years ago transient.php 8 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