PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.4.14
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.4.14
1.4.14 1.4.13 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.54 1.3.53 1.3.52 1.3.51 1.3.50 1.3.49 1.3.48 1.3.47 1.3.46 1.3.45 All 177 releases
disco / ajax / Ajax.php

Ajax.php in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.4.14, at ajax/Ajax.php

135 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Disco
4 *
5 * @package Disco
6 * @author Ohidul Islam <wahid0003@gmail.com>
7 * @copyright 2022 WebAppick
8 * @license GPL 2.0+
9 * @link http://domain.tld
10 */
11
12 namespace Disco\Ajax;
13
14 use Disco\Engine\Base;
15
16 /**
17 * AJAX in the public
18 */
19 class Ajax extends Base {
20
21 /**
22 * Initialize the class.
23 *
24 * @return void
25 */
26 public function initialize() {
27 if ( ! \apply_filters( 'disco_d_ajax_initialize', true ) ) {
28 return;
29 }
30
31 // For not logged user.
32 \add_action( 'wp_ajax_nopriv_your_method', array( $this, 'your_method' ) );
33
34 \add_action( 'wp_ajax_disco_dismiss_review_notice', [ $this, 'dismiss_review_notice' ] );
35
36 \add_action( 'wp_ajax_disco_dismiss_promotional_notice', [ $this, 'dismiss_promotional_notice' ] );
37
38 \add_action( 'wp_ajax_disco_dismiss_compatible_plugin_notice', [ $this, 'dismiss_compatible_plugin_notice' ] );
39
40 \add_action( 'wp_ajax_disco_dismiss_feature_unlock_notice', [ $this, 'disco_dismiss_feature_unlock_notice' ] );
41
42 }
43
44 /**
45 * The method to run on ajax
46 *
47 * @since 1.0.0
48 * @return void
49 */
50 public function your_method() {
51 $return = array(
52 'message' => 'Saved',
53 'ID' => 1,
54 );
55
56 $this->clean_buffer();
57 \wp_send_json_success( $return );
58 }
59
60 /**
61 * Handle the AJAX request to dismiss the review notice.
62 */
63 public function dismiss_review_notice() {
64 $this->clean_buffer();
65 check_ajax_referer( 'disco_dismiss_notice', 'nonce' );
66
67 if ( ! is_user_logged_in() ) {
68 wp_send_json_error( [ 'message' => 'Unauthorized request' ], 403 );
69 }
70
71 $current_user_id = get_current_user_id();
72 $dismiss_value = isset( $_POST['dismiss'] ) ? sanitize_text_field( $_POST['dismiss'] ) : 'later';
73
74 if ( $dismiss_value === 'never' ) {
75 update_user_meta( $current_user_id, 'disco_review_dismissed', 'never' );
76 } else {
77 update_user_meta( $current_user_id, 'disco_review_dismissed', time() + ( 7 * DAY_IN_SECONDS ) );
78 }
79
80 wp_send_json_success( [ 'message' => 'Notice dismissed' ] );
81 }
82
83 /**
84 * Handle the AJAX request to dismiss the promotional notice.
85 */
86 public function dismiss_promotional_notice() {
87 $this->clean_buffer();
88 check_ajax_referer( 'disco_dismiss_notice', 'nonce' );
89
90 if ( ! is_user_logged_in() ) {
91 wp_send_json_error( [ 'message' => 'Unauthorized request' ], 403 );
92 }
93
94 update_user_meta( get_current_user_id(), 'disco_promotional_holiday_banner_2025', 'never' );
95
96 wp_send_json_success( [ 'message' => 'Notice dismissed' ] );
97 }
98
99 /**
100 * Handle the AJAX request to dismiss the compatible plugin notice.
101 */
102 public function dismiss_compatible_plugin_notice() {
103 $this->clean_buffer();
104 check_ajax_referer( 'disco_dismiss_notice', 'nonce' );
105
106 if ( ! is_user_logged_in() ) {
107 wp_send_json_error( [ 'message' => 'Unauthorized request' ], 403 );
108 }
109
110 $dismiss_value = isset( $_POST['dismiss'] ) ? sanitize_text_field( $_POST['dismiss'] ) : 'later';
111
112 update_user_meta( get_current_user_id(), 'disco_compatible_plugin_notice_dismissed', $dismiss_value );
113
114 wp_send_json_success( [ 'message' => 'Notice dismissed' ] );
115 }
116
117 /**
118 * Handle the AJAX request to dismiss the compatible plugin notice.
119 */
120 public function disco_dismiss_feature_unlock_notice() {
121 $this->clean_buffer();
122 check_ajax_referer( 'disco_dismiss_notice', 'nonce' );
123
124 if ( ! is_user_logged_in() ) {
125 wp_send_json_error( [ 'message' => 'Unauthorized request' ], 403 );
126 }
127
128 $dismiss_value = isset( $_POST['dismiss'] ) ? sanitize_text_field( $_POST['dismiss'] ) : 'later';
129
130 update_user_meta( get_current_user_id(), 'disco_feature_unlock_notice_dismissed', $dismiss_value );
131
132 wp_send_json_success( [ 'message' => 'Notice dismissed' ] );
133 }
134 }
135