Skip to content

Commit 96dac60

Browse files
committed
👌 IMPROVE: Updated settings page to prepare for v2.0 release
1 parent 58ec6dc commit 96dac60

20 files changed

+848
-1226
lines changed

admin/class-clwc-admin.php

+62-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* @package CLWC
77
* @subpackage CLWC/admin
8-
* @author Devio Diital <[email protected]>
8+
* @author Devio Digital <[email protected]>
99
* @license GPL-2.0+ http://www.gnu.org/licenses/gpl-2.0.txt
1010
* @link https://www.deviodigital.com
1111
* @since 1.0.0
@@ -19,7 +19,7 @@
1919
*
2020
* @package CLWC
2121
* @subpackage CLWC/admin
22-
* @author Devio Diital <[email protected]>
22+
* @author Devio Digital <[email protected]>
2323
* @license GPL-2.0+ http://www.gnu.org/licenses/gpl-2.0.txt
2424
* @link https://www.deviodigital.com
2525
* @since 1.0.0
@@ -31,31 +31,31 @@ class Customer_Loyalty_Admin {
3131
*
3232
* @since 1.0.0
3333
* @access private
34-
* @var string $_plugin_name - The ID of this plugin.
34+
* @var string $plugin_name - The ID of this plugin.
3535
*/
36-
private $_plugin_name;
36+
private $plugin_name;
3737

3838
/**
3939
* The version of this plugin.
4040
*
4141
* @since 1.0.0
4242
* @access private
43-
* @var string $_version - The current version of this plugin.
43+
* @var string $version - The current version of this plugin.
4444
*/
45-
private $_version;
45+
private $version;
4646

4747
/**
4848
* Initialize the class and set its properties.
4949
*
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.
5252
*
5353
* @since 1.0.0
5454
*/
55-
public function __construct( $_plugin_name, $_version ) {
55+
public function __construct( $plugin_name, $version ) {
5656

57-
$this->plugin_name = $_plugin_name;
58-
$this->version = $_version;
57+
$this->plugin_name = $plugin_name;
58+
$this->version = $version;
5959

6060
}
6161

@@ -75,8 +75,57 @@ public function enqueue_styles() {
7575
* @since 1.0.0
7676
* @return void
7777
*/
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.' );
80118
}
81119

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.' );
82130
}
131+
add_action( 'wp_ajax_clwc_update_loyalty_points', 'clwc_update_loyalty_points' );

0 commit comments

Comments
 (0)