refactor: move AJAX option handler to Admin Manager class

This commit is contained in:
Marcus Quinn
2025-03-24 17:06:09 +00:00
parent d280ec197b
commit 2b4e3cecd3
2 changed files with 16 additions and 7 deletions

View File

@ -18,6 +18,18 @@ class WP_Allstars_Admin_Manager {
public static function init() { public static function init() {
// Register hooks - we'll add more as we refactor each function // Register hooks - we'll add more as we refactor each function
add_action('admin_menu', array(__CLASS__, 'register_admin_menu')); add_action('admin_menu', array(__CLASS__, 'register_admin_menu'));
add_action('wp_ajax_wp_allstars_update_option', array(__CLASS__, 'update_option'));
}
/**
* AJAX handler for updating options
*/
public static function update_option() {
check_ajax_referer('wp-allstars-nonce', 'nonce');
$option = sanitize_text_field($_POST['option']);
$value = intval($_POST['value']);
update_option($option, $value);
wp_send_json_success('Option updated');
} }
/** /**

View File

@ -16,15 +16,12 @@ function wp_allstars_register_settings() {
} }
add_action('admin_init', 'wp_allstars_register_settings'); add_action('admin_init', 'wp_allstars_register_settings');
// AJAX handler for settings // AJAX handler for settings - now handled by WP_Allstars_Admin_Manager class, but kept for backward compatibility
function wp_allstars_update_option() { function wp_allstars_update_option() {
check_ajax_referer('wp-allstars-nonce', 'nonce'); // This function now redirects to the Admin Manager class
$option = sanitize_text_field($_POST['option']); // Kept for backward compatibility
$value = intval($_POST['value']); WP_Allstars_Admin_Manager::update_option();
update_option($option, $value);
wp_send_json_success('Option updated');
} }
add_action('wp_ajax_wp_allstars_update_option', 'wp_allstars_update_option');
// Include tools data // Include tools data
require_once dirname(__FILE__) . '/data/tools.php'; require_once dirname(__FILE__) . '/data/tools.php';