Add Modern Admin Colors feature to customize admin color scheme
This commit is contained in:
@ -71,7 +71,7 @@ class WP_Allstars_Settings_Manager {
|
||||
?>
|
||||
<div class="wp-allstars-settings-section">
|
||||
<div class="wp-allstars-settings-grid">
|
||||
<!-- Example of a simple toggle setting (no panel) -->
|
||||
<!-- Modern Admin Colors Setting -->
|
||||
<div class="wp-setting-row">
|
||||
<div class="wp-setting-header">
|
||||
<div class="wp-setting-main">
|
||||
@ -86,12 +86,12 @@ class WP_Allstars_Settings_Manager {
|
||||
<span class="wp-toggle-slider"></span>
|
||||
</div>
|
||||
<label for="wp_allstars_simple_setting" class="wp-setting-label">
|
||||
<?php esc_html_e('Example: Simple Toggle', 'wp-allstars'); ?>
|
||||
<?php esc_html_e('Modern Admin Colors', 'wp-allstars'); ?>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<p class="wp-setting-description">
|
||||
<?php esc_html_e('This is an example of a simple toggle setting without an expandable panel. Currently for demonstration purposes only.', 'wp-allstars'); ?>
|
||||
<?php esc_html_e('Toggle the Modern Admin colour scheme on & off to remind yourself you\'re in an SEO Pro Stack :)', 'wp-allstars'); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
98
includes/class-wp-allstars-admin-colors.php
Normal file
98
includes/class-wp-allstars-admin-colors.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* WP ALLSTARS Admin Colors Feature
|
||||
*
|
||||
* Handles setting the admin color scheme based on user preferences
|
||||
*
|
||||
* @package WP_ALLSTARS
|
||||
* @since 0.2.3
|
||||
*/
|
||||
|
||||
if (!defined('ABSPATH')) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin Colors Handler Class
|
||||
*/
|
||||
class WP_Allstars_Admin_Colors {
|
||||
|
||||
/**
|
||||
* Option name for the admin color scheme setting
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $option_name = 'wp_allstars_simple_setting';
|
||||
|
||||
/**
|
||||
* Modern color scheme key
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $modern_scheme = 'modern';
|
||||
|
||||
/**
|
||||
* Default color scheme key
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $default_scheme = 'fresh';
|
||||
|
||||
/**
|
||||
* Initialize the class and set up hooks
|
||||
*/
|
||||
public function __construct() {
|
||||
// Set up hooks
|
||||
add_action('admin_init', array($this, 'set_admin_color_scheme'));
|
||||
add_action('wp_ajax_wp_allstars_update_option', array($this, 'handle_color_scheme_update'), 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the admin color scheme based on the setting value
|
||||
*/
|
||||
public function set_admin_color_scheme() {
|
||||
// Get current user
|
||||
$user_id = get_current_user_id();
|
||||
if (!$user_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if our setting is enabled
|
||||
$modern_colors_enabled = get_option($this->option_name, false);
|
||||
|
||||
// Get the scheme to set
|
||||
$scheme = $modern_colors_enabled ? $this->modern_scheme : $this->default_scheme;
|
||||
|
||||
// Update user meta to set the color scheme
|
||||
update_user_meta($user_id, 'admin_color', $scheme);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle color scheme update via AJAX
|
||||
* Runs early to apply the color scheme change before the general option update handler
|
||||
*/
|
||||
public function handle_color_scheme_update() {
|
||||
// Check for required params
|
||||
if (!isset($_POST['option']) || !isset($_POST['value'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Only process our specific option
|
||||
if ($_POST['option'] !== $this->option_name) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the current user ID
|
||||
$user_id = get_current_user_id();
|
||||
if (!$user_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine which scheme to set based on the value
|
||||
$value = (bool) $_POST['value'];
|
||||
$scheme = $value ? $this->modern_scheme : $this->default_scheme;
|
||||
|
||||
// Update the user's color scheme
|
||||
update_user_meta($user_id, 'admin_color', $scheme);
|
||||
}
|
||||
}
|
@ -46,6 +46,7 @@ register_activation_hook(__FILE__, 'wp_allstars_activate');
|
||||
* Load core plugin components
|
||||
*/
|
||||
require_once plugin_dir_path(__FILE__) . 'includes/class-wp-allstars-auto-upload.php';
|
||||
require_once plugin_dir_path(__FILE__) . 'includes/class-wp-allstars-admin-colors.php';
|
||||
|
||||
// Load admin-specific components
|
||||
if (is_admin()) {
|
||||
@ -72,8 +73,6 @@ if (is_admin()) {
|
||||
require_once plugin_dir_path(__FILE__) . 'admin/settings.php';
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Auto Upload feature initialization
|
||||
*
|
||||
@ -87,6 +86,15 @@ function wp_allstars_init_auto_upload() {
|
||||
}
|
||||
add_action('init', 'wp_allstars_init_auto_upload');
|
||||
|
||||
/**
|
||||
* Initialize core features
|
||||
*/
|
||||
function wp_allstars_init_features() {
|
||||
// Initialize the Admin Colors feature
|
||||
new WP_Allstars_Admin_Colors();
|
||||
}
|
||||
add_action('plugins_loaded', 'wp_allstars_init_features');
|
||||
|
||||
/**
|
||||
* Initialize core plugin classes
|
||||
*/
|
||||
|
Reference in New Issue
Block a user