5
5
*
6
6
* @package CLWC
7
7
* @subpackage CLWC/admin
8
- * @author Devio Diital <[email protected] >
8
+ * @author Devio Digital <[email protected] >
9
9
* @license GPL-2.0+ http://www.gnu.org/licenses/gpl-2.0.txt
10
10
* @link https://www.deviodigital.com
11
11
* @since 1.0.0
19
19
*
20
20
* @package CLWC
21
21
* @subpackage CLWC/admin
22
- * @author Devio Diital <[email protected] >
22
+ * @author Devio Digital <[email protected] >
23
23
* @license GPL-2.0+ http://www.gnu.org/licenses/gpl-2.0.txt
24
24
* @link https://www.deviodigital.com
25
25
* @since 1.0.0
@@ -31,31 +31,31 @@ class Customer_Loyalty_Admin {
31
31
*
32
32
* @since 1.0.0
33
33
* @access private
34
- * @var string $_plugin_name - The ID of this plugin.
34
+ * @var string $plugin_name - The ID of this plugin.
35
35
*/
36
- private $ _plugin_name ;
36
+ private $ plugin_name ;
37
37
38
38
/**
39
39
* The version of this plugin.
40
40
*
41
41
* @since 1.0.0
42
42
* @access private
43
- * @var string $_version - The current version of this plugin.
43
+ * @var string $version - The current version of this plugin.
44
44
*/
45
- private $ _version ;
45
+ private $ version ;
46
46
47
47
/**
48
48
* Initialize the class and set its properties.
49
49
*
50
- * @param string $_plugin_name - The name of this plugin.
51
- * @param string $_version - The version of this plugin.
50
+ * @param string $plugin_name - The name of this plugin.
51
+ * @param string $version - The version of this plugin.
52
52
*
53
53
* @since 1.0.0
54
54
*/
55
- public function __construct ( $ _plugin_name , $ _version ) {
55
+ public function __construct ( $ plugin_name , $ version ) {
56
56
57
- $ this ->plugin_name = $ _plugin_name ;
58
- $ this ->version = $ _version ;
57
+ $ this ->plugin_name = $ plugin_name ;
58
+ $ this ->version = $ version ;
59
59
60
60
}
61
61
@@ -75,8 +75,57 @@ public function enqueue_styles() {
75
75
* @since 1.0.0
76
76
* @return void
77
77
*/
78
- public function enqueue_scripts () {
79
- //wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/clwc-admin.js', array( 'jquery' ), $this->version, false );
78
+ public function enqueue_scripts ( $ hook_suffix ) {
79
+ // Only enqueue on your specific admin page.
80
+ if ( 'woocommerce_page_clwc-customer-loyalty ' !== $ hook_suffix ) {
81
+ return ;
82
+ }
83
+
84
+ wp_enqueue_script (
85
+ 'clwc-loyalty-ajax ' ,
86
+ plugin_dir_url ( __FILE__ ) . 'js/clwc-admin.js ' ,
87
+ [ 'jquery ' ],
88
+ '1.0.0 ' ,
89
+ true
90
+ );
91
+
92
+ wp_localize_script ( 'clwc-loyalty-ajax ' , 'clwc_ajax ' , [
93
+ 'ajax_url ' => admin_url ( 'admin-ajax.php ' ),
94
+ 'nonce ' => wp_create_nonce ( 'clwc_update_points_nonce ' ),
95
+ ] );
96
+ }
97
+
98
+
99
+ }
100
+
101
+ /**
102
+ * Handle AJAX request to update loyalty points.
103
+ *
104
+ * @since 2.0.0
105
+ * @return void
106
+ */
107
+ function clwc_update_loyalty_points () {
108
+ // Verify nonce for security
109
+ check_ajax_referer ( 'clwc_update_points_nonce ' , 'security ' );
110
+
111
+ // Get POST variables
112
+ $ user_id = isset ( $ _POST ['user_id ' ] ) ? intval ( $ _POST ['user_id ' ] ) : 0 ;
113
+ $ points = isset ( $ _POST ['points ' ] ) ? intval ( $ _POST ['points ' ] ) : 0 ;
114
+
115
+ // Verify user ID
116
+ if ( ! $ user_id || ! get_userdata ( $ user_id ) ) {
117
+ wp_send_json_error ( 'Invalid user ID. ' );
80
118
}
81
119
120
+ // Capability check - ensure the current user can edit users
121
+ if ( ! current_user_can ( 'edit_user ' , $ user_id ) ) {
122
+ wp_send_json_error ( 'You do not have permission to edit this user. ' );
123
+ }
124
+
125
+ // Update user meta
126
+ update_user_meta ( $ user_id , 'clwc_loyalty_points ' , $ points );
127
+
128
+ // Return success message
129
+ wp_send_json_success ( 'Loyalty points updated successfully. ' );
82
130
}
131
+ add_action ( 'wp_ajax_clwc_update_loyalty_points ' , 'clwc_update_loyalty_points ' );
0 commit comments