Refactor(Admin): Implement Settings API & AJAX save for Settings Manager
- Refactored WPALLSTARS_Settings_Manager to use WordPress Settings API. - Stores settings in single 'wpallstars_options' array. - Implemented robust AJAX saving for specific settings (e.g., color scheme, auto-upload) via WPALLSTARS_Admin_Manager::update_option. - Updated JS and setting render functions for AJAX. - Corrected admin menu registration and script enqueue hooks. - Includes file renames from wp-allstars to wpallstars.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -11,10 +11,10 @@ if (!defined('ABSPATH')) {
|
||||
// Define readme content
|
||||
function wp_allstars_get_readme_content() {
|
||||
// Get README.md content
|
||||
$readme_path = WP_PLUGIN_DIR . '/wpa-superstar-plugin/README.md';
|
||||
$readme_path = WP_PLUGIN_DIR . '/wpallstars-superstar-plugin/README.md';
|
||||
$readme_content = '';
|
||||
|
||||
if (file_exists($readme_path)) {
|
||||
if (file_exists($readme_path) && is_readable($readme_path)) {
|
||||
$readme_content = file_get_contents($readme_path);
|
||||
} else {
|
||||
// Fallback content if README.md is not found
|
||||
|
||||
@@ -1,34 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* WP ALLSTARS Admin Manager
|
||||
* WPALLSTARS Admin Manager
|
||||
*
|
||||
* @package WP_ALLSTARS
|
||||
* @since 0.2.0
|
||||
* Manages the overall admin interface for the WPALLSTARS plugin, including menus, scripts, styles, and AJAX handlers.
|
||||
* Uses WPALLSTARS for class names/package/strings and wpallstars for slugs/handles/actions/nonces/options/textdomain/js vars/css classes.
|
||||
*
|
||||
* @package WPALLSTARS
|
||||
* @subpackage Admin
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class WP_Allstars_Admin_Manager {
|
||||
class WPALLSTARS_Admin_Manager {
|
||||
|
||||
/**
|
||||
* Initialize the class and register hooks
|
||||
*/
|
||||
public static function init() {
|
||||
add_action('admin_menu', array(__CLASS__, 'register_admin_menu'));
|
||||
add_action('wp_ajax_wp_allstars_update_option', array(__CLASS__, 'update_option'));
|
||||
add_action('admin_init', array(__CLASS__, 'register_settings'));
|
||||
add_action('wp_ajax_wpallstars_update_option', array(__CLASS__, 'update_option'));
|
||||
// remove settings registration from here, it's handled by Settings_Manager
|
||||
// add_action('admin_init', array(__CLASS__, 'register_settings'));
|
||||
add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_admin_scripts'));
|
||||
|
||||
// Initialize all manager classes
|
||||
WP_Allstars_Settings_Manager::init();
|
||||
WP_Allstars_Theme_Manager::init();
|
||||
WP_Allstars_Workflow_Manager::init();
|
||||
WP_Allstars_Pro_Plugins_Manager::init();
|
||||
WP_Allstars_Tools_Manager::init();
|
||||
WP_Allstars_Hosting_Manager::init();
|
||||
WP_Allstars_Free_Plugins_Manager::init();
|
||||
WPALLSTARS_Settings_Manager::init();
|
||||
WPALLSTARS_Theme_Manager::init();
|
||||
WPALLSTARS_Workflow_Manager::init();
|
||||
WPALLSTARS_Pro_Plugins_Manager::init();
|
||||
WPALLSTARS_Tools_Manager::init();
|
||||
WPALLSTARS_Hosting_Manager::init();
|
||||
WPALLSTARS_Free_Plugins_Manager::init();
|
||||
WPALLSTARS_Readme_Manager::init(); // Ensure Readme Manager is initialized
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,278 +43,309 @@ class WP_Allstars_Admin_Manager {
|
||||
* @param string $hook The current admin page hook
|
||||
*/
|
||||
public static function enqueue_admin_scripts($hook) {
|
||||
if ('settings_page_wp-allstars' !== $hook) {
|
||||
// Correct hook for the settings submenu page
|
||||
$settings_page_hook = 'wpallstars_page_wpallstars-settings';
|
||||
|
||||
// Only load specific assets on our settings page
|
||||
if ($settings_page_hook !== $hook) {
|
||||
// Maybe load global assets on all wpallstars pages?
|
||||
// if (strpos($hook, 'wpallstars') === false) return;
|
||||
return; // Exit if not the settings page for now
|
||||
}
|
||||
|
||||
// Enqueue main admin stylesheet
|
||||
wp_enqueue_style(
|
||||
'wpallstars-admin', // Handle for the main admin CSS
|
||||
WPALLSTARS_URL . 'admin/css/wpallstars-admin.css', // Use constant defined in main plugin file
|
||||
array(),
|
||||
WPALLSTARS_VERSION // Use constant defined in main plugin file
|
||||
);
|
||||
|
||||
// Enqueue main admin JavaScript (likely contains toggle functionality)
|
||||
wp_enqueue_script(
|
||||
'wpallstars-admin', // Handle for the main admin JS
|
||||
WPALLSTARS_URL . 'admin/js/wpallstars-admin.js', // Use constant for URL
|
||||
array('jquery'), // Dependencies
|
||||
WPALLSTARS_VERSION, // Use constant for version
|
||||
true // Load in footer
|
||||
);
|
||||
|
||||
// Localize script with data for AJAX and other JS needs
|
||||
wp_localize_script('wpallstars-admin', 'wpallstars', array(
|
||||
'ajaxurl' => admin_url('admin-ajax.php'),
|
||||
'nonce' => wp_create_nonce('wpallstars-nonce'), // Generic nonce for general actions
|
||||
'update_option_nonce' => wp_create_nonce('wpallstars_update_option'), // Specific nonce for updating options via AJAX (if still needed)
|
||||
'l10n' => array( // Localization strings for JS
|
||||
'updating' => __('Updating...', WPALLSTARS_TEXT_DOMAIN),
|
||||
'error' => __('Error', WPALLSTARS_TEXT_DOMAIN),
|
||||
'success' => __('Success', WPALLSTARS_TEXT_DOMAIN),
|
||||
),
|
||||
// Add any other data needed by wpallstars-admin.js
|
||||
));
|
||||
|
||||
// Settings Manager handles its own enqueuing via its init hook
|
||||
// WPALLSTARS_Settings_Manager::enqueue_settings_scripts($hook); // Removed
|
||||
|
||||
// Other managers can still enqueue specific assets if needed
|
||||
// Example:
|
||||
// WPALLSTARS_Theme_Manager::enqueue_theme_scripts($hook);
|
||||
// WPALLSTARS_Free_Plugins_Manager::enqueue_free_plugins_scripts($hook);
|
||||
|
||||
// Combine inline styles from various managers
|
||||
$inline_styles = ''; // Initialize
|
||||
// Uncomment and adjust class/method names as needed
|
||||
// $inline_styles .= WPALLSTARS_Pro_Plugins_Manager::get_inline_styles();
|
||||
// $inline_styles .= WPALLSTARS_Hosting_Manager::get_inline_styles();
|
||||
// $inline_styles .= WPALLSTARS_Tools_Manager::get_inline_styles();
|
||||
if (!empty($inline_styles)) {
|
||||
wp_add_inline_style('wpallstars-admin', $inline_styles);
|
||||
}
|
||||
|
||||
// Combine inline scripts from various managers (use with caution)
|
||||
$inline_scripts = ''; // Initialize
|
||||
// $inline_scripts .= WPALLSTARS_Theme_Manager::get_theme_scripts();
|
||||
// $inline_scripts .= WPALLSTARS_Free_Plugins_Manager::get_plugin_scripts();
|
||||
// $inline_scripts .= WPALLSTARS_Settings_Manager::get_settings_scripts(); // Removed
|
||||
if (!empty($inline_scripts)) {
|
||||
wp_add_inline_script('wpallstars-admin', $inline_scripts);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register core plugin settings - REMOVED
|
||||
* Settings registration is now handled by WPALLSTARS_Settings_Manager::register_settings
|
||||
*/
|
||||
// public static function register_settings() { ... }
|
||||
|
||||
/**
|
||||
* AJAX handler for updating options (Generic handler, specific validation can be added)
|
||||
* Note: This is likely NOT used for the main settings form save action anymore,
|
||||
* which is handled by options.php via the Settings API.
|
||||
* Keep it if it's used for dynamic updates elsewhere.
|
||||
* Handles saving *individual* setting keys within the 'wpallstars_options' array via AJAX.
|
||||
*/
|
||||
public static function update_option() {
|
||||
// Check nonce
|
||||
check_ajax_referer('wpallstars_update_option', 'nonce');
|
||||
|
||||
// Check user capabilities
|
||||
if (!current_user_can('manage_options')) {
|
||||
wp_send_json_error(__('You do not have permission to perform this action.', WPALLSTARS_TEXT_DOMAIN));
|
||||
return;
|
||||
}
|
||||
|
||||
// Enqueue admin stylesheet
|
||||
wp_enqueue_style(
|
||||
'wp-allstars-admin',
|
||||
plugins_url('css/wp-allstars-admin.css', dirname(__FILE__)),
|
||||
array(),
|
||||
WP_ALLSTARS_VERSION
|
||||
);
|
||||
|
||||
// Enqueue admin JavaScript
|
||||
wp_enqueue_script(
|
||||
'wp-allstars-admin',
|
||||
plugins_url('js/wp-allstars-admin.js', dirname(__FILE__)),
|
||||
array('jquery'),
|
||||
WP_ALLSTARS_VERSION,
|
||||
true
|
||||
);
|
||||
|
||||
// Localize the script with necessary data for AJAX
|
||||
wp_localize_script('wp-allstars-admin', 'wpAllstars', array(
|
||||
'nonce' => wp_create_nonce('wp-allstars-nonce'),
|
||||
'ajaxurl' => admin_url('admin-ajax.php')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register core plugin settings
|
||||
*/
|
||||
public static function register_settings() {
|
||||
// Core settings groups - tab-specific settings are registered in their respective manager classes
|
||||
register_setting('wp_allstars_general', 'wp_allstars_general_settings');
|
||||
register_setting('wp_allstars_advanced', 'wp_allstars_advanced_settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX handler for updating options
|
||||
*/
|
||||
public static function update_option() {
|
||||
// Verify nonce for security
|
||||
check_ajax_referer('wp-allstars-nonce', 'nonce');
|
||||
|
||||
// Check if user has proper permissions
|
||||
if (!current_user_can('manage_options')) {
|
||||
wp_send_json_error('Insufficient permissions');
|
||||
// Get setting key and value from POST data
|
||||
$setting_key = isset($_POST['setting_key']) ? sanitize_key($_POST['setting_key']) : '';
|
||||
// Don't sanitize value yet, do it based on the key type later
|
||||
$setting_value = isset($_POST['setting_value']) ? wp_unslash($_POST['setting_value']) : null;
|
||||
|
||||
if (empty($setting_key) || is_null($setting_value)) {
|
||||
wp_send_json_error(__('Setting key or value is missing.', WPALLSTARS_TEXT_DOMAIN));
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate and sanitize input
|
||||
if (!isset($_POST['option']) || !isset($_POST['value'])) {
|
||||
wp_send_json_error('Missing required parameters');
|
||||
return;
|
||||
}
|
||||
|
||||
$option = sanitize_text_field($_POST['option']);
|
||||
|
||||
// Different sanitization based on expected value type
|
||||
$value = $_POST['value'];
|
||||
if (is_numeric($value)) {
|
||||
$value = intval($value);
|
||||
} elseif (is_string($value)) {
|
||||
$value = sanitize_text_field($value);
|
||||
} elseif (is_array($value)) {
|
||||
$value = array_map('sanitize_text_field', $value);
|
||||
}
|
||||
|
||||
// Whitelist of allowed options to update for security
|
||||
|
||||
// --- Security & Validation ---
|
||||
// Whitelist setting KEYS within 'wpallstars_options' that can be updated via this AJAX handler
|
||||
$allowed_options = array(
|
||||
'wp_allstars_simple_setting',
|
||||
'wp_allstars_auto_upload_images',
|
||||
'wp_allstars_admin_color_scheme',
|
||||
'wp_allstars_max_width',
|
||||
'wp_allstars_max_height',
|
||||
'wp_allstars_exclude_urls',
|
||||
'wp_allstars_image_name_pattern',
|
||||
'wp_allstars_image_alt_pattern'
|
||||
'admin_color_scheme', // Example: Key for admin color scheme
|
||||
'enable_auto_upload', // Example: Key for auto-upload toggle
|
||||
'max_image_width', // Example: Key for max image width
|
||||
// Add other keys registered in Settings_Manager that should be AJAX-updatable
|
||||
);
|
||||
|
||||
if (!in_array($option, $allowed_options)) {
|
||||
wp_send_json_error('Invalid option');
|
||||
|
||||
if (!in_array($setting_key, $allowed_options, true)) {
|
||||
wp_send_json_error(__('Invalid setting key specified for AJAX update.', WPALLSTARS_TEXT_DOMAIN));
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the option
|
||||
$result = update_option($option, $value);
|
||||
|
||||
|
||||
// Sanitize the value based on the specific setting key
|
||||
$sanitized_value = '';
|
||||
switch ($setting_key) {
|
||||
case 'admin_color_scheme':
|
||||
// Assuming it's a class name or identifier
|
||||
$sanitized_value = sanitize_html_class($setting_value);
|
||||
// If it was intended to be a hex color, use sanitize_hex_color($setting_value);
|
||||
break;
|
||||
case 'enable_auto_upload':
|
||||
// Boolean toggle (common JS values are 'true'/'false' strings)
|
||||
$sanitized_value = rest_sanitize_boolean($setting_value);
|
||||
break;
|
||||
case 'max_image_width':
|
||||
// Positive integer
|
||||
$sanitized_value = absint($setting_value);
|
||||
break;
|
||||
// Add cases for other allowed keys
|
||||
default:
|
||||
// Should not happen due to whitelist check, but as a fallback:
|
||||
$sanitized_value = sanitize_text_field($setting_value);
|
||||
break;
|
||||
}
|
||||
|
||||
// Get the existing options array
|
||||
$options = get_option(WPALLSTARS_Settings_Manager::$option_name, array());
|
||||
|
||||
// Store the old value for comparison
|
||||
$old_value = isset($options[$setting_key]) ? $options[$setting_key] : null;
|
||||
|
||||
// Update the specific key in the options array
|
||||
$options[$setting_key] = $sanitized_value;
|
||||
|
||||
// Save the entire options array back
|
||||
// update_option handles serialization and DB storage
|
||||
$result = update_option(WPALLSTARS_Settings_Manager::$option_name, $options);
|
||||
|
||||
if ($result) {
|
||||
wp_send_json_success(array(
|
||||
'message' => 'Option updated successfully',
|
||||
'option' => $option,
|
||||
'value' => $value
|
||||
));
|
||||
wp_send_json_success(__('Option updated successfully.', WPALLSTARS_TEXT_DOMAIN));
|
||||
} else {
|
||||
wp_send_json_success(array(
|
||||
'message' => 'No changes made to option',
|
||||
'option' => $option
|
||||
));
|
||||
// Option might not have changed, or error occurred
|
||||
// Check if the value is the same as the old value (update_option returns false if value hasn't changed)
|
||||
if ($old_value === $sanitized_value) {
|
||||
wp_send_json_success(__('Option unchanged.', WPALLSTARS_TEXT_DOMAIN));
|
||||
} else {
|
||||
wp_send_json_error(__('Failed to update option.', WPALLSTARS_TEXT_DOMAIN));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register the admin menu item
|
||||
*/
|
||||
public static function register_admin_menu() {
|
||||
add_options_page(
|
||||
'WP ALLSTARS Settings',
|
||||
'WP ALLSTARS',
|
||||
add_menu_page(
|
||||
__('WP Allstars', WPALLSTARS_TEXT_DOMAIN),
|
||||
__('WP Allstars', WPALLSTARS_TEXT_DOMAIN),
|
||||
'manage_options',
|
||||
'wp-allstars',
|
||||
array(__CLASS__, 'render_settings_page')
|
||||
'wpallstars-dashboard', // Main dashboard slug
|
||||
array(__CLASS__, 'render_settings_page'), // Default to settings page for now
|
||||
'dashicons-star-filled',
|
||||
85
|
||||
);
|
||||
|
||||
// Add actual settings submenu
|
||||
add_submenu_page(
|
||||
'wpallstars-dashboard', // Parent slug
|
||||
__('Settings', WPALLSTARS_TEXT_DOMAIN), // Page title
|
||||
__('Settings', WPALLSTARS_TEXT_DOMAIN), // Menu title
|
||||
'manage_options', // Capability
|
||||
'wpallstars-settings', // Settings slug << THIS IS THE SLUG TO USE
|
||||
array(__CLASS__, 'render_settings_page') // Callback function
|
||||
);
|
||||
|
||||
// Add other submenus here using their respective managers or callbacks
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render the settings page
|
||||
* Render the settings page container and handle tab navigation.
|
||||
* Content for each tab is rendered by the respective manager class.
|
||||
*/
|
||||
public static function render_settings_page() {
|
||||
global $tabs;
|
||||
|
||||
$active_tab = isset($_GET['tab']) ? $_GET['tab'] : 'general';
|
||||
$active_category = isset($_GET['category']) ? $_GET['category'] : 'minimal';
|
||||
|
||||
// Tab-specific resources
|
||||
if ($active_tab === 'recommended') {
|
||||
WP_Allstars_Plugin_Manager::clear_plugin_cache();
|
||||
wp_enqueue_script('plugin-install');
|
||||
wp_enqueue_script('updates');
|
||||
add_thickbox();
|
||||
wp_enqueue_style('wp-allstars-plugins', plugins_url('css/wp-allstars-plugins.css', dirname(__FILE__)));
|
||||
|
||||
// Add inline script to load plugins on page load
|
||||
wp_add_inline_script('wp-allstars-admin', '
|
||||
jQuery(document).ready(function($) {
|
||||
if ($("#wpa-plugin-list").length && $("#wpa-plugin-list").is(":empty")) {
|
||||
var category = "' . esc_js($active_category) . '";
|
||||
var $container = $("#wpa-plugin-list");
|
||||
var $loadingOverlay = $("<div class=\"wp-allstars-loading-overlay\"><span class=\"spinner is-active\"></span></div>");
|
||||
|
||||
// Show loading overlay
|
||||
$container.css("position", "relative").append($loadingOverlay);
|
||||
|
||||
// AJAX request to get plugins
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
type: "POST",
|
||||
data: {
|
||||
action: "wp_allstars_get_plugins",
|
||||
category: category,
|
||||
_wpnonce: wpAllstars.nonce
|
||||
},
|
||||
success: function(response) {
|
||||
$loadingOverlay.remove();
|
||||
if (response.success) {
|
||||
$container.html(response.data);
|
||||
// Initialize plugin action buttons
|
||||
if (typeof initPluginActions === "function") {
|
||||
initPluginActions();
|
||||
}
|
||||
|
||||
// Spinners have been removed from individual cards
|
||||
} else {
|
||||
$container.html("<div class=\"notice notice-error\"><p>" + response.data + "</p></div>");
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
$loadingOverlay.remove();
|
||||
$container.html("<div class=\"notice notice-error\"><p>Failed to load plugins. Please try again. Error: " + error + "</p></div>");
|
||||
console.error("AJAX Error:", xhr.responseText);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
');
|
||||
// Check user capabilities
|
||||
if (!current_user_can('manage_options')) {
|
||||
wp_die(__('You do not have sufficient permissions to access this page.', WPALLSTARS_TEXT_DOMAIN));
|
||||
}
|
||||
|
||||
// Whitelist of valid tabs
|
||||
$valid_tabs = array(
|
||||
'general' => __('General', WPALLSTARS_TEXT_DOMAIN),
|
||||
'advanced' => __('Advanced', WPALLSTARS_TEXT_DOMAIN),
|
||||
'workflow' => __('Workflow', WPALLSTARS_TEXT_DOMAIN),
|
||||
'theme' => __('Theme', WPALLSTARS_TEXT_DOMAIN),
|
||||
'recommended' => __('Free Plugins', WPALLSTARS_TEXT_DOMAIN),
|
||||
'pro' => __('Pro Plugins', WPALLSTARS_TEXT_DOMAIN),
|
||||
'hosting' => __('Hosting', WPALLSTARS_TEXT_DOMAIN),
|
||||
'tools' => __('Tools', WPALLSTARS_TEXT_DOMAIN),
|
||||
'readme' => __('Read Me', WPALLSTARS_TEXT_DOMAIN),
|
||||
);
|
||||
|
||||
// Get current tab from URL, default to 'general'
|
||||
$current_tab = isset($_GET['tab']) ? sanitize_key($_GET['tab']) : 'general';
|
||||
|
||||
// Fallback to 'general' if the tab is not in the whitelist
|
||||
if (!array_key_exists($current_tab, $valid_tabs)) {
|
||||
$current_tab = 'general';
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="wrap wp-allstars-wrap">
|
||||
<div class="wp-allstars-header">
|
||||
<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
|
||||
<div class="wp-allstars-header-actions">
|
||||
<span class="wp-allstars-version"><?php echo esc_html(WP_ALLSTARS_VERSION); ?></span>
|
||||
<a href="https://www.wpallstars.com/" target="_blank" class="button button-secondary green-button-secondary green-visit-website">
|
||||
<?php esc_html_e('Visit Website', 'wp-allstars'); ?>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="wp-allstars-tabs-wrapper">
|
||||
<div class="wrap wpallstars-wrap wpallstars-settings-wrap">
|
||||
<h1><?php esc_html_e('WP Allstars Settings', WPALLSTARS_TEXT_DOMAIN); ?></h1>
|
||||
|
||||
<?php settings_errors(); // Display any settings errors registered by the Settings API ?>
|
||||
|
||||
<div class="wpallstars-settings-container">
|
||||
<h2 class="nav-tab-wrapper">
|
||||
<a href="?page=wp-allstars&tab=general" class="nav-tab <?php echo $active_tab === 'general' ? 'nav-tab-active' : ''; ?>">
|
||||
<?php esc_html_e('General', 'wp-allstars'); ?>
|
||||
</a>
|
||||
<a href="?page=wp-allstars&tab=advanced" class="nav-tab <?php echo $active_tab === 'advanced' ? 'nav-tab-active' : ''; ?>">
|
||||
<?php esc_html_e('Advanced', 'wp-allstars'); ?>
|
||||
</a>
|
||||
<a href="?page=wp-allstars&tab=workflow" class="nav-tab <?php echo $active_tab === 'workflow' ? 'nav-tab-active' : ''; ?>">
|
||||
<?php esc_html_e('Workflow', 'wp-allstars'); ?>
|
||||
</a>
|
||||
<a href="?page=wp-allstars&tab=theme" class="nav-tab <?php echo $active_tab === 'theme' ? 'nav-tab-active' : ''; ?>">
|
||||
<?php esc_html_e('Theme', 'wp-allstars'); ?>
|
||||
</a>
|
||||
<a href="?page=wp-allstars&tab=recommended" class="nav-tab <?php echo $active_tab === 'recommended' ? 'nav-tab-active' : ''; ?>">
|
||||
<?php esc_html_e('Free Plugins', 'wp-allstars'); ?>
|
||||
</a>
|
||||
<a href="?page=wp-allstars&tab=pro" class="nav-tab <?php echo $active_tab === 'pro' ? 'nav-tab-active' : ''; ?>">
|
||||
<?php esc_html_e('Pro Plugins', 'wp-allstars'); ?>
|
||||
</a>
|
||||
<a href="?page=wp-allstars&tab=hosting" class="nav-tab <?php echo $active_tab === 'hosting' ? 'nav-tab-active' : ''; ?>">
|
||||
<?php esc_html_e('Hosting', 'wp-allstars'); ?>
|
||||
</a>
|
||||
<a href="?page=wp-allstars&tab=tools" class="nav-tab <?php echo $active_tab === 'tools' ? 'nav-tab-active' : ''; ?>">
|
||||
<?php esc_html_e('Tools', 'wp-allstars'); ?>
|
||||
</a>
|
||||
<a href="?page=wp-allstars&tab=readme" class="nav-tab <?php echo $active_tab === 'readme' ? 'nav-tab-active' : ''; ?>">
|
||||
<?php esc_html_e('Read Me', 'wp-allstars'); ?>
|
||||
</a>
|
||||
</h2>
|
||||
|
||||
<div class="wp-allstars-tab-content">
|
||||
<?php
|
||||
// Each tab's content is handled by its respective manager class
|
||||
switch ($active_tab) {
|
||||
// Define tabs with their labels (already defined in $valid_tabs)
|
||||
$tabs = $valid_tabs;
|
||||
|
||||
// Output tab navigation links using the correct settings page slug
|
||||
foreach ($tabs as $tab_slug => $tab_label) {
|
||||
$tab_url = add_query_arg(array('page' => 'wpallstars-settings', 'tab' => $tab_slug), admin_url('admin.php'));
|
||||
$class = ($current_tab === $tab_slug) ? 'nav-tab nav-tab-active' : 'nav-tab';
|
||||
echo '<a href="' . esc_url($tab_url) . '" class="' . esc_attr($class) . '">' . esc_html($tab_label) . '</a>';
|
||||
}
|
||||
?>
|
||||
</h2>
|
||||
|
||||
<div class="wpallstars-tab-content-container">
|
||||
<?php
|
||||
// Display content based on the active tab by calling the appropriate manager's display method
|
||||
// Using a switch statement for clarity
|
||||
switch ($current_tab) {
|
||||
case 'general':
|
||||
WP_Allstars_Settings_Manager::display_general_tab();
|
||||
if (class_exists('WPALLSTARS_Settings_Manager')) WPALLSTARS_Settings_Manager::display_general_tab();
|
||||
break;
|
||||
|
||||
case 'advanced':
|
||||
WP_Allstars_Settings_Manager::display_advanced_tab();
|
||||
if (class_exists('WPALLSTARS_Settings_Manager')) WPALLSTARS_Settings_Manager::display_advanced_tab();
|
||||
break;
|
||||
|
||||
case 'workflow':
|
||||
WP_Allstars_Workflow_Manager::display_tab_content();
|
||||
if (class_exists('WPALLSTARS_Workflow_Manager')) WPALLSTARS_Workflow_Manager::display_tab_content();
|
||||
break;
|
||||
|
||||
case 'theme':
|
||||
WP_Allstars_Theme_Manager::display_tab_content();
|
||||
if (class_exists('WPALLSTARS_Theme_Manager')) WPALLSTARS_Theme_Manager::display_tab_content();
|
||||
break;
|
||||
|
||||
case 'recommended':
|
||||
WP_Allstars_Free_Plugins_Manager::display_tab_content();
|
||||
if (class_exists('WPALLSTARS_Free_Plugins_Manager')) WPALLSTARS_Free_Plugins_Manager::display_tab_content();
|
||||
break;
|
||||
|
||||
case 'pro':
|
||||
WP_Allstars_Pro_Plugins_Manager::display_tab_content();
|
||||
if (class_exists('WPALLSTARS_Pro_Plugins_Manager')) WPALLSTARS_Pro_Plugins_Manager::display_tab_content();
|
||||
break;
|
||||
|
||||
case 'hosting':
|
||||
WP_Allstars_Hosting_Manager::display_tab_content();
|
||||
if (class_exists('WPALLSTARS_Hosting_Manager')) WPALLSTARS_Hosting_Manager::display_tab_content();
|
||||
break;
|
||||
|
||||
case 'tools':
|
||||
WP_Allstars_Tools_Manager::display_tab_content();
|
||||
if (class_exists('WPALLSTARS_Tools_Manager')) WPALLSTARS_Tools_Manager::display_tab_content();
|
||||
break;
|
||||
|
||||
case 'readme':
|
||||
WP_Allstars_Readme_Manager::display_tab_content();
|
||||
if (class_exists('WPALLSTARS_Readme_Manager')) WPALLSTARS_Readme_Manager::display_tab_content();
|
||||
break;
|
||||
default:
|
||||
// Should not happen due to whitelist check, but good practice
|
||||
if (class_exists('WPALLSTARS_Settings_Manager')) WPALLSTARS_Settings_Manager::display_general_tab();
|
||||
break;
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- .wpallstars-tab-content-container -->
|
||||
</div><!-- .wpallstars-settings-container -->
|
||||
</div><!-- .wrap -->
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Alias for enqueue_admin_scripts to maintain compatibility with settings.php
|
||||
*
|
||||
* @param string $hook The current admin page hook
|
||||
* Alias for enqueue_admin_scripts to potentially maintain compatibility
|
||||
* if other parts of the codebase mistakenly call this.
|
||||
*
|
||||
* @deprecated Prefer calling enqueue_admin_scripts directly.
|
||||
* @param string $hook The current admin page hook.
|
||||
*/
|
||||
public static function enqueue_scripts($hook) {
|
||||
self::enqueue_admin_scripts($hook);
|
||||
}
|
||||
}
|
||||
|
||||
// Instantiate the Admin Manager when the admin area is loaded
|
||||
if (is_admin()) {
|
||||
// Ensure the class exists before calling init (optional safety check)
|
||||
if (class_exists('WPALLSTARS_Admin_Manager')) {
|
||||
WPALLSTARS_Admin_Manager::init();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,15 +50,15 @@ class WP_Allstars_Free_Plugins_Manager {
|
||||
// Define all categories in the desired display order
|
||||
$priority_categories = array(
|
||||
'minimal', 'admin', 'affiliates', 'ai', 'cms',
|
||||
'compliance', 'crm', 'ecommerce', 'lms', 'media',
|
||||
'seo', 'setup', 'social', 'speed', 'translation',
|
||||
'compliance', 'crm', 'ecommerce', 'events', 'lms', 'media',
|
||||
'members', 'seo', 'setup', 'social', 'speed', 'translation',
|
||||
'advanced', 'debug'
|
||||
);
|
||||
|
||||
// Start HTML output
|
||||
?>
|
||||
<div class="wp-allstars-settings-content tab-content" id="recommended">
|
||||
<div id="wpa-plugin-filters" class="wp-filter">
|
||||
<div id="wpallstars-plugin-filters" class="wp-filter">
|
||||
<ul class="filter-links">
|
||||
<?php
|
||||
// First output priority categories
|
||||
@@ -100,7 +100,7 @@ class WP_Allstars_Free_Plugins_Manager {
|
||||
</div>
|
||||
|
||||
<div class="wp-allstars-plugin-browser" style="margin-top: 22px;">
|
||||
<div id="wpa-plugin-list" class="wpa-plugin-container" style="position: relative; min-height: 200px;">
|
||||
<div id="wpallstars-plugin-list" class="wpallstars-plugin-container" style="position: relative; min-height: 200px;">
|
||||
<!-- Plugin content will be loaded via AJAX -->
|
||||
<div class="wp-allstars-loading-overlay">
|
||||
<span class="spinner is-active"></span>
|
||||
@@ -112,14 +112,14 @@ class WP_Allstars_Free_Plugins_Manager {
|
||||
<script>
|
||||
jQuery(document).ready(function($) {
|
||||
// Filter tab click handler
|
||||
$('#wpa-plugin-filters .filter-links a').on('click', function(e) {
|
||||
$('#wpallstars-plugin-filters .filter-links a').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var category = $(this).data('category');
|
||||
var $container = $('#wpa-plugin-list');
|
||||
var $container = $('#wpallstars-plugin-list');
|
||||
|
||||
// Update filter UI
|
||||
$('#wpa-plugin-filters .filter-links a').removeClass('current');
|
||||
$('#wpallstars-plugin-filters .filter-links a').removeClass('current');
|
||||
$(this).addClass('current');
|
||||
|
||||
// Create new loading overlay
|
||||
@@ -163,7 +163,7 @@ class WP_Allstars_Free_Plugins_Manager {
|
||||
});
|
||||
|
||||
// Load initial category (minimal or from URL)
|
||||
$('#wpa-plugin-filters .filter-links a.current').trigger('click');
|
||||
$('#wpallstars-plugin-filters .filter-links a.current').trigger('click');
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
@@ -24,7 +24,7 @@ class WP_Allstars_Hosting_Manager {
|
||||
public static function display_tab_content() {
|
||||
?>
|
||||
<div class="wp-allstars-settings-content tab-content" id="hosting">
|
||||
<div class="wpa-pro-plugins">
|
||||
<div class="wpallstars-pro-plugins">
|
||||
<?php
|
||||
$hosting_providers = self::get_hosting_providers();
|
||||
// Sort providers alphabetically by name
|
||||
@@ -33,7 +33,7 @@ class WP_Allstars_Hosting_Manager {
|
||||
});
|
||||
foreach ($hosting_providers as $provider) {
|
||||
?>
|
||||
<div class="wpa-pro-plugin">
|
||||
<div class="wpallstars-pro-plugin">
|
||||
<h3><?php echo esc_html($provider['name']); ?></h3>
|
||||
<p><?php echo esc_html($provider['description']); ?></p>
|
||||
<?php if (isset($provider['button_group'])): ?>
|
||||
@@ -100,7 +100,7 @@ class WP_Allstars_Hosting_Manager {
|
||||
|
||||
// Add inline CSS for hosting to match the single column layout
|
||||
$custom_css = '
|
||||
#hosting .wpa-pro-plugins {
|
||||
#hosting .wpallstars-pro-plugins {
|
||||
padding: 15px 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -108,7 +108,7 @@ class WP_Allstars_Hosting_Manager {
|
||||
max-width: 700px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
#hosting .wpa-pro-plugin {
|
||||
#hosting .wpallstars-pro-plugin {
|
||||
background: #fff;
|
||||
border: 1px solid #ddd;
|
||||
padding: 24px;
|
||||
@@ -121,14 +121,14 @@ class WP_Allstars_Hosting_Manager {
|
||||
margin-bottom: 24px;
|
||||
max-width: 100%;
|
||||
}
|
||||
#hosting .wpa-pro-plugin:last-child {
|
||||
#hosting .wpallstars-pro-plugin:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
#hosting .wpa-pro-plugin:hover {
|
||||
#hosting .wpallstars-pro-plugin:hover {
|
||||
border-color: #2271b1;
|
||||
box-shadow: 0 2px 6px rgba(0,0,0,0.15);
|
||||
}
|
||||
#hosting .wpa-pro-plugin .button-group {
|
||||
#hosting .wpallstars-pro-plugin .button-group {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
';
|
||||
|
||||
@@ -65,7 +65,7 @@ class WP_Allstars_Pro_Plugins_Manager {
|
||||
});
|
||||
|
||||
// Start the tab content container
|
||||
echo '<div class="wp-allstars-settings-content tab-content" id="pro"><div class="wpa-pro-plugins">';
|
||||
echo '<div class="wp-allstars-settings-content tab-content" id="pro"><div class="wpallstars-pro-plugins">';
|
||||
|
||||
// Render each plugin card
|
||||
foreach ($pro_plugins as $plugin) {
|
||||
@@ -83,7 +83,7 @@ class WP_Allstars_Pro_Plugins_Manager {
|
||||
*/
|
||||
public static function display_plugin_card($plugin) {
|
||||
?>
|
||||
<div class="wpa-pro-plugin">
|
||||
<div class="wpallstars-pro-plugin">
|
||||
<h3><?php echo esc_html($plugin['name']); ?></h3>
|
||||
<p><?php echo esc_html($plugin['description']); ?></p>
|
||||
<?php if (isset($plugin['button_group'])): ?>
|
||||
@@ -138,7 +138,7 @@ class WP_Allstars_Pro_Plugins_Manager {
|
||||
|
||||
// Add inline CSS for pro plugins
|
||||
$custom_css = '
|
||||
.wpa-pro-plugins {
|
||||
.wpallstars-pro-plugins {
|
||||
padding: 15px 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -146,7 +146,7 @@ class WP_Allstars_Pro_Plugins_Manager {
|
||||
max-width: 700px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.wpa-pro-plugin {
|
||||
.wpallstars-pro-plugin {
|
||||
background: #fff;
|
||||
border: 1px solid #ddd;
|
||||
padding: 24px;
|
||||
@@ -159,34 +159,34 @@ class WP_Allstars_Pro_Plugins_Manager {
|
||||
margin-bottom: 24px;
|
||||
max-width: 100%;
|
||||
}
|
||||
.wpa-pro-plugin:last-child {
|
||||
.wpallstars-pro-plugin:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.wpa-pro-plugin:hover {
|
||||
.wpallstars-pro-plugin:hover {
|
||||
border-color: #2271b1;
|
||||
box-shadow: 0 2px 6px rgba(0,0,0,0.15);
|
||||
}
|
||||
.wpa-pro-plugin h3 {
|
||||
.wpallstars-pro-plugin h3 {
|
||||
margin: 0 0 12px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #1d2327;
|
||||
line-height: 1.4;
|
||||
}
|
||||
.wpa-pro-plugin p {
|
||||
.wpallstars-pro-plugin p {
|
||||
margin: 0 0 16px;
|
||||
color: #50575e;
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.wpa-pro-plugin .button-group {
|
||||
.wpallstars-pro-plugin .button-group {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-top: auto;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
.wpa-pro-plugin .button {
|
||||
.wpallstars-pro-plugin .button {
|
||||
text-decoration: none;
|
||||
min-width: 120px;
|
||||
text-align: center;
|
||||
@@ -205,17 +205,17 @@ class WP_Allstars_Pro_Plugins_Manager {
|
||||
box-shadow: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
.wpa-pro-plugin .button:hover {
|
||||
.wpallstars-pro-plugin .button:hover {
|
||||
background: #f0f0f1;
|
||||
border-color: #0071a1;
|
||||
color: #0071a1;
|
||||
}
|
||||
.wpa-pro-plugin .button-primary {
|
||||
.wpallstars-pro-plugin .button-primary {
|
||||
background: #0071a1;
|
||||
border-color: #0071a1;
|
||||
color: #fff;
|
||||
}
|
||||
.wpa-pro-plugin .button-primary:hover {
|
||||
.wpallstars-pro-plugin .button-primary:hover {
|
||||
background: #006291;
|
||||
border-color: #006291;
|
||||
color: #fff;
|
||||
|
||||
@@ -50,14 +50,14 @@ class WP_Allstars_Readme_Manager {
|
||||
* Display the readme tab content
|
||||
*/
|
||||
public static function display_tab_content() {
|
||||
$readme = self::get_readme_content();
|
||||
$readme_content = self::get_readme_content();
|
||||
|
||||
?>
|
||||
<div class="wp-allstars-settings-content tab-content" id="readme">
|
||||
<div class="wpa-pro-plugins">
|
||||
<div class="wpa-pro-plugin">
|
||||
<div class="wpallstars-pro-plugins">
|
||||
<div class="wpallstars-pro-plugin">
|
||||
<div class="wp-allstars-markdown-content">
|
||||
<?php echo self::parse_markdown($readme['content']); ?>
|
||||
<?php echo self::parse_markdown($readme_content['content']); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* Settings Manager Class
|
||||
*
|
||||
* Handles the display and management of plugin settings tabs (General and Advanced).
|
||||
* Leverages the WordPress Settings API.
|
||||
*/
|
||||
|
||||
// If this file is called directly, abort.
|
||||
@@ -10,186 +11,400 @@ if ( ! defined( 'WPINC' ) ) {
|
||||
die;
|
||||
}
|
||||
|
||||
class WP_Allstars_Settings_Manager {
|
||||
|
||||
/**
|
||||
* Class WPALLSTARS_Settings_Manager
|
||||
* Manages WP Allstars plugin settings using the WordPress Settings API.
|
||||
*/
|
||||
class WPALLSTARS_Settings_Manager {
|
||||
|
||||
/**
|
||||
* Option group name.
|
||||
* @var string
|
||||
*/
|
||||
private static $option_group = 'wpallstars_settings_group';
|
||||
|
||||
/**
|
||||
* Option name stored in the database.
|
||||
* @var string
|
||||
*/
|
||||
private static $option_name = 'wpallstars_options';
|
||||
|
||||
/**
|
||||
* Initialize the class
|
||||
*/
|
||||
public static function init() {
|
||||
// Register settings
|
||||
// Register settings using admin_init hook
|
||||
add_action('admin_init', array(self::class, 'register_settings'));
|
||||
|
||||
// Enqueue scripts and styles if needed
|
||||
// Enqueue scripts and styles needed for settings page
|
||||
add_action('admin_enqueue_scripts', array(self::class, 'enqueue_scripts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register plugin settings
|
||||
* Register plugin settings, sections, and fields.
|
||||
*/
|
||||
public static function register_settings() {
|
||||
// General settings
|
||||
register_setting('wp_allstars_settings', 'wp_allstars_simple_setting');
|
||||
register_setting('wp_allstars_settings', 'wp_allstars_admin_color_scheme');
|
||||
// Register the single option array to store all settings
|
||||
register_setting(
|
||||
self::$option_group, // Option group
|
||||
self::$option_name, // Option name
|
||||
array(self::class, 'sanitize_settings') // Sanitize callback
|
||||
);
|
||||
|
||||
// --- General Settings Section ---
|
||||
add_settings_section(
|
||||
'wpallstars_general_settings_section', // ID
|
||||
__('General Settings', WPALLSTARS_TEXT_DOMAIN), // Title
|
||||
null, // Callback function (optional description)
|
||||
'wpallstars_general_settings_page' // Page slug where this section will be shown
|
||||
);
|
||||
|
||||
// Field: Admin Color Scheme
|
||||
add_settings_field(
|
||||
'admin_color_scheme', // Field ID (matches key in options array)
|
||||
__('Modern Admin Colors', WPALLSTARS_TEXT_DOMAIN), // Title
|
||||
array(self::class, 'render_admin_color_field'), // Callback to render the field
|
||||
'wpallstars_general_settings_page', // Page
|
||||
'wpallstars_general_settings_section' // Section
|
||||
);
|
||||
|
||||
// Field: Simple Toggle Example (Keeping for now, can be removed later)
|
||||
add_settings_field(
|
||||
'simple_toggle_example', // Field ID
|
||||
__('Example: Simple Toggle', WPALLSTARS_TEXT_DOMAIN), // Title
|
||||
array(self::class, 'render_simple_toggle_field'), // Callback
|
||||
'wpallstars_general_settings_page', // Page
|
||||
'wpallstars_general_settings_section' // Section
|
||||
);
|
||||
|
||||
// --- Advanced Settings Section ---
|
||||
add_settings_section(
|
||||
'wpallstars_advanced_settings_section', // ID
|
||||
__('Advanced Settings', WPALLSTARS_TEXT_DOMAIN), // Title
|
||||
null, // Callback
|
||||
'wpallstars_advanced_settings_page' // Page slug
|
||||
);
|
||||
|
||||
// Advanced settings
|
||||
register_setting('wp_allstars_settings', 'wp_allstars_auto_upload_images');
|
||||
// Field: Auto Upload Images
|
||||
add_settings_field(
|
||||
'auto_upload_enabled', // Field ID (matching key used in WPALLSTARS_Auto_Upload)
|
||||
__('Auto Upload External Images', WPALLSTARS_TEXT_DOMAIN), // Title
|
||||
array(self::class, 'render_auto_upload_field'), // Callback
|
||||
'wpallstars_advanced_settings_page', // Page
|
||||
'wpallstars_advanced_settings_section' // Section
|
||||
);
|
||||
|
||||
// Field: Sync Guard Enabled
|
||||
add_settings_field(
|
||||
'sync_guard_enabled', // Field ID (matching key used in WPALLSTARS_Sync_Guard)
|
||||
__('Enable Sync Guard', WPALLSTARS_TEXT_DOMAIN), // Title
|
||||
array(self::class, 'render_sync_guard_field'), // Callback
|
||||
'wpallstars_advanced_settings_page', // Page
|
||||
'wpallstars_advanced_settings_section' // Section
|
||||
);
|
||||
|
||||
// Add more fields for other settings as needed (e.g., Sync Guard Mode, Debug Mode)
|
||||
// ... add_settings_field(...) ...
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue scripts and styles needed for settings
|
||||
* Sanitize settings array before saving.
|
||||
*
|
||||
* @param array $input The input array from the settings form.
|
||||
* @return array The sanitized array to be saved.
|
||||
*/
|
||||
public static function sanitize_settings($input) {
|
||||
$sanitized_input = array();
|
||||
$options = get_option(self::$option_name, array()); // Get existing options
|
||||
|
||||
// Ensure $input is an array
|
||||
if (!is_array($input)) {
|
||||
$input = array();
|
||||
}
|
||||
|
||||
// Sanitize: Admin Color Scheme (checkbox - 1 or 0)
|
||||
$sanitized_input['admin_color_scheme'] = isset($input['admin_color_scheme']) ? 1 : 0;
|
||||
|
||||
// Sanitize: Simple Toggle Example (checkbox - 1 or 0)
|
||||
$sanitized_input['simple_toggle_example'] = isset($input['simple_toggle_example']) ? 1 : 0;
|
||||
|
||||
// Sanitize: Auto Upload Enabled (checkbox - 1 or 0)
|
||||
$sanitized_input['auto_upload_enabled'] = isset($input['auto_upload_enabled']) ? 1 : 0;
|
||||
|
||||
// Sanitize: Sync Guard Enabled (checkbox - 1 or 0)
|
||||
$sanitized_input['sync_guard_enabled'] = isset($input['sync_guard_enabled']) ? 1 : 0;
|
||||
|
||||
// Example: Sanitize a text field (if we add one later)
|
||||
// if (isset($input['api_key'])) {
|
||||
// $sanitized_input['api_key'] = sanitize_text_field($input['api_key']);
|
||||
// } else {
|
||||
// $sanitized_input['api_key'] = $options['api_key'] ?? ''; // Keep existing if not set
|
||||
// }
|
||||
|
||||
// Merge with existing options to preserve settings not on the current form
|
||||
// This might not be necessary if all settings are always present or handled by defaults.
|
||||
// Consider if default values are sufficient or if merging is required.
|
||||
// $sanitized_input = array_merge($options, $sanitized_input);
|
||||
|
||||
// Add settings saved notice (WordPress handles this automatically on successful save)
|
||||
// add_settings_error(...); // No need for this here anymore
|
||||
|
||||
return $sanitized_input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue scripts and styles needed for settings page.
|
||||
*
|
||||
* @param string $hook The current admin page hook.
|
||||
*/
|
||||
public static function enqueue_scripts($hook) {
|
||||
// Only load on the plugin settings page
|
||||
if (strpos($hook, 'wp-allstars') === false) {
|
||||
// Define the specific hook for the WPAllstars settings page
|
||||
$settings_page_hook = 'wpallstars_page_wpallstars-settings';
|
||||
|
||||
// Only enqueue assets on the WPAllstars settings page
|
||||
if ($settings_page_hook !== $hook) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Enqueue the color picker if needed (example)
|
||||
// wp_enqueue_style('wp-color-picker');
|
||||
// wp_enqueue_script('wp-color-picker');
|
||||
|
||||
// Enqueue specific CSS for the settings page if necessary
|
||||
// Example:
|
||||
// wp_enqueue_style(
|
||||
// 'wpallstars-settings-styles',
|
||||
// WPALLSTARS_URL . 'admin/css/wpallstars-settings.css',
|
||||
// array(),
|
||||
// WPALLSTARS_VERSION
|
||||
// );
|
||||
|
||||
// If there was specific JS for settings toggles/interactions (removed inline JS previously)
|
||||
// it should be enqueued here from a dedicated file.
|
||||
// Example:
|
||||
// wp_enqueue_script(
|
||||
// 'wpallstars-settings-script',
|
||||
// WPALLSTARS_URL . 'admin/js/wpallstars-settings.js',
|
||||
// array('jquery', 'wp-color-picker'), // Add dependencies
|
||||
// WPALLSTARS_VERSION,
|
||||
// true // Load in footer
|
||||
// );
|
||||
|
||||
// Add inline JS for toggle functionality
|
||||
$toggle_js = '
|
||||
jQuery(document).ready(function($) {
|
||||
// Toggle expandable settings panels
|
||||
$(".wp-allstars-toggle-header").on("click", function() {
|
||||
var $this = $(this);
|
||||
var $settings = $this.next(".wp-allstars-toggle-settings");
|
||||
var isExpanded = $this.attr("aria-expanded") === "true";
|
||||
|
||||
// Toggle aria-expanded attribute
|
||||
$this.attr("aria-expanded", !isExpanded);
|
||||
|
||||
// Toggle settings visibility
|
||||
$settings.slideToggle(200);
|
||||
});
|
||||
});
|
||||
';
|
||||
|
||||
wp_add_inline_script('wp-allstars-admin', $toggle_js);
|
||||
// Localize data specifically for the settings script if needed
|
||||
// wp_localize_script('wpallstars-settings-script', 'wpallstarsSettings', array(
|
||||
// 'someSettingNonce' => wp_create_nonce('wpallstars-setting-action-nonce'),
|
||||
// // Add other data...
|
||||
// ));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the general tab content
|
||||
* Renders the form structure for the General Settings Tab.
|
||||
* Called by the Admin Manager when displaying the settings page.
|
||||
*/
|
||||
public static function display_general_tab() {
|
||||
?>
|
||||
<div class="wp-allstars-settings-section">
|
||||
<div class="wp-allstars-settings-grid">
|
||||
<!-- Admin Color Scheme Setting -->
|
||||
<div class="wp-setting-row">
|
||||
<div class="wp-setting-header">
|
||||
<div class="wp-setting-main">
|
||||
<div class="wp-setting-left">
|
||||
<div class="wp-toggle-switch">
|
||||
<input type="checkbox"
|
||||
id="wp_allstars_admin_color_scheme"
|
||||
name="wp_allstars_admin_color_scheme"
|
||||
value="1"
|
||||
<?php checked(get_option('wp_allstars_admin_color_scheme', false)); ?>
|
||||
/>
|
||||
<span class="wp-toggle-slider"></span>
|
||||
</div>
|
||||
<label for="wp_allstars_admin_color_scheme" class="wp-setting-label">
|
||||
<?php esc_html_e('Modern Admin Colors', 'wp-allstars'); ?>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<p class="wp-setting-description">
|
||||
<?php esc_html_e('Switch to the Modern Admin colors, to remind that you\'re using WP Allstars.', 'wp-allstars'); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Example of a simple toggle setting (no panel) -->
|
||||
<div class="wp-setting-row">
|
||||
<div class="wp-setting-header">
|
||||
<div class="wp-setting-main">
|
||||
<div class="wp-setting-left">
|
||||
<div class="wp-toggle-switch">
|
||||
<input type="checkbox"
|
||||
id="wp_allstars_simple_setting"
|
||||
name="wp_allstars_simple_setting"
|
||||
value="1"
|
||||
<?php checked(get_option('wp_allstars_simple_setting', false)); ?>
|
||||
/>
|
||||
<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'); ?>
|
||||
</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'); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form method="post" action="options.php">
|
||||
<?php
|
||||
// Output security fields for the registered setting group
|
||||
settings_fields(self::$option_group); // Use the option group name
|
||||
|
||||
// Output setting sections and fields for the 'general' page
|
||||
do_settings_sections('wpallstars_general_settings_page'); // Use the page slug
|
||||
|
||||
// Output save settings button
|
||||
submit_button(__('Save General Settings', WPALLSTARS_TEXT_DOMAIN));
|
||||
?>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the advanced tab content
|
||||
* Renders the form structure for the Advanced Settings Tab.
|
||||
* Called by the Admin Manager when displaying the settings page.
|
||||
*/
|
||||
public static function display_advanced_tab() {
|
||||
?>
|
||||
<div class="wp-allstars-settings-section">
|
||||
<div class="wp-allstars-settings-grid">
|
||||
<!-- Example of an expandable panel setting -->
|
||||
<div class="wp-allstars-toggle">
|
||||
<div class="wp-allstars-toggle-header" aria-expanded="false">
|
||||
<div class="wp-allstars-toggle-main">
|
||||
<div class="wp-allstars-toggle-left">
|
||||
<div class="wp-toggle-switch">
|
||||
<input type="checkbox"
|
||||
id="wp_allstars_auto_upload_images"
|
||||
name="wp_allstars_auto_upload_images"
|
||||
value="1"
|
||||
<?php checked(get_option('wp_allstars_auto_upload_images', false)); ?>
|
||||
/>
|
||||
<span class="wp-toggle-slider"></span>
|
||||
</div>
|
||||
<label for="wp_allstars_auto_upload_images">
|
||||
<?php esc_html_e('Example: Expandable Panel', 'wp-allstars'); ?>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<p class="wp-setting-description">
|
||||
<?php esc_html_e('This is an example of an expandable panel setting. Currently for demonstration purposes only - no actual functionality.', 'wp-allstars'); ?>
|
||||
</p>
|
||||
</div>
|
||||
<div class="wp-allstars-toggle-settings">
|
||||
<div class="wp-allstars-setting-row">
|
||||
<label for="example_text"><?php esc_html_e('Example Text Field', 'wp-allstars'); ?></label>
|
||||
<input type="text"
|
||||
id="example_text"
|
||||
name="example_text"
|
||||
value="Example value"
|
||||
<form method="post" action="options.php">
|
||||
<?php
|
||||
// Output security fields for the registered setting group
|
||||
settings_fields(self::$option_group); // Use the option group name
|
||||
|
||||
// Output setting sections and fields for the 'advanced' page
|
||||
do_settings_sections('wpallstars_advanced_settings_page'); // Use the page slug
|
||||
|
||||
// Output save settings button
|
||||
submit_button(__('Save Advanced Settings', WPALLSTARS_TEXT_DOMAIN));
|
||||
?>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
|
||||
// --- Field Rendering Callbacks --- //
|
||||
|
||||
/**
|
||||
* Get the current value for a specific setting key.
|
||||
*
|
||||
* @param string $key The key within the wpallstars_options array.
|
||||
* @param mixed $default Default value if the key is not set.
|
||||
* @return mixed The setting value.
|
||||
*/
|
||||
private static function get_setting_value($key, $default = '') {
|
||||
$options = get_option(self::$option_name, array());
|
||||
return $options[$key] ?? $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the Admin Color Scheme toggle field.
|
||||
*/
|
||||
public static function render_admin_color_field() {
|
||||
$options = get_option(self::$option_name, array());
|
||||
$setting_key = 'admin_color_scheme'; // Key in the options array
|
||||
$value = isset($options[$setting_key]) ? $options[$setting_key] : 'default'; // Default value
|
||||
$field_id = self::$option_name . '_' . $setting_key; // Unique ID for label 'for' attribute
|
||||
|
||||
// Define color scheme options (example)
|
||||
$color_schemes = array(
|
||||
'default' => __('Default', WPALLSTARS_TEXT_DOMAIN),
|
||||
'light' => __('Light', WPALLSTARS_TEXT_DOMAIN),
|
||||
'blue' => __('Blue', WPALLSTARS_TEXT_DOMAIN),
|
||||
'coffee' => __('Coffee', WPALLSTARS_TEXT_DOMAIN),
|
||||
'ectoplasm' => __('Ectoplasm', WPALLSTARS_TEXT_DOMAIN),
|
||||
'midnight' => __('Midnight', WPALLSTARS_TEXT_DOMAIN),
|
||||
'ocean' => __('Ocean', WPALLSTARS_TEXT_DOMAIN),
|
||||
'sunrise' => __('Sunrise', WPALLSTARS_TEXT_DOMAIN),
|
||||
'modern' => __('Modern (WPAllstars)', WPALLSTARS_TEXT_DOMAIN),
|
||||
);
|
||||
|
||||
?>
|
||||
<select
|
||||
id="<?php echo esc_attr($field_id); ?>"
|
||||
name="<?php echo esc_attr(self::$option_name . '[' . $setting_key . ']'); ?>"
|
||||
class="wpallstars-ajax-save"
|
||||
data-setting-key="<?php echo esc_attr($setting_key); ?>"
|
||||
>
|
||||
<?php foreach ($color_schemes as $scheme_slug => $scheme_name) : ?>
|
||||
<option value="<?php echo esc_attr($scheme_slug); ?>" <?php selected($value, $scheme_slug); ?>>
|
||||
<?php echo esc_html($scheme_name); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<span class="wpallstars-ajax-feedback"></span> <!-- Feedback area for AJAX -->
|
||||
<p class="description">
|
||||
<?php esc_html_e('Select an admin color scheme. Changes are saved instantly.', WPALLSTARS_TEXT_DOMAIN); ?>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the Simple Toggle example field.
|
||||
*/
|
||||
public static function render_simple_toggle_field() {
|
||||
$key = 'simple_toggle_example';
|
||||
$value = self::get_setting_value($key, 0);
|
||||
?>
|
||||
<div class="wp-setting-row">
|
||||
<div class="wp-setting-header">
|
||||
<div class="wp-setting-main">
|
||||
<div class="wp-setting-left">
|
||||
<div class="wp-toggle-switch">
|
||||
<input type="checkbox"
|
||||
id="<?php echo esc_attr(self::$option_name . '_' . $key); ?>"
|
||||
name="<?php echo esc_attr(self::$option_name . '[' . $key . ']'); ?>"
|
||||
value="1"
|
||||
<?php checked($value, 1); ?>
|
||||
/>
|
||||
<p class="description"><?php esc_html_e('This is an example text field for demonstration purposes.', 'wp-allstars'); ?></p>
|
||||
<span class="wp-toggle-slider"></span>
|
||||
</div>
|
||||
<label for="<?php echo esc_attr(self::$option_name . '_' . $key); ?>" class="wp-setting-label">
|
||||
<?php // Label is provided by add_settings_field ?>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<p class="wp-setting-description description">
|
||||
<?php esc_html_e('This is an example of a simple toggle setting without an expandable panel. Currently for demonstration purposes only.', WPALLSTARS_TEXT_DOMAIN); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save settings
|
||||
* Render the Auto Upload toggle field.
|
||||
*/
|
||||
public static function save_settings() {
|
||||
// Check for nonce
|
||||
if (!isset($_POST['wp_allstars_settings_nonce']) || !wp_verify_nonce($_POST['wp_allstars_settings_nonce'], 'wp_allstars_save_settings')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Save general settings
|
||||
update_option('wp_allstars_simple_setting', isset($_POST['wp_allstars_simple_setting']) ? 1 : 0);
|
||||
update_option('wp_allstars_admin_color_scheme', isset($_POST['wp_allstars_admin_color_scheme']) ? 1 : 0);
|
||||
|
||||
// Save advanced settings
|
||||
update_option('wp_allstars_auto_upload_images', isset($_POST['wp_allstars_auto_upload_images']) ? 1 : 0);
|
||||
|
||||
// Add settings saved notice
|
||||
add_settings_error('wp_allstars_settings', 'settings_updated', __('Settings saved.', 'wp-allstars'), 'updated');
|
||||
public static function render_auto_upload_field() {
|
||||
$options = get_option(self::$option_name, array());
|
||||
$setting_key = 'auto_upload_enabled'; // Key in the options array
|
||||
$value = isset($options[$setting_key]) ? (bool) $options[$setting_key] : false; // Default to false
|
||||
$field_id = self::$option_name . '_' . $setting_key; // Unique ID for label 'for' attribute
|
||||
?>
|
||||
<label for="<?php echo esc_attr($field_id); ?>">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="<?php echo esc_attr($field_id); ?>"
|
||||
name="<?php echo esc_attr(self::$option_name . '[' . $setting_key . ']'); ?>"
|
||||
value="1"
|
||||
class="wpallstars-ajax-save"
|
||||
data-setting-key="<?php echo esc_attr($setting_key); ?>"
|
||||
<?php checked($value); ?>
|
||||
>
|
||||
<?php esc_html_e('Automatically upload external images referenced in post content on save.', WPALLSTARS_TEXT_DOMAIN); ?>
|
||||
</label>
|
||||
<span class="wpallstars-ajax-feedback"></span> <!-- Feedback area for AJAX -->
|
||||
<p class="description">
|
||||
<?php esc_html_e('When enabled, images from external URLs will be downloaded to the media library and their URLs updated in the post.', WPALLSTARS_TEXT_DOMAIN); ?><br>
|
||||
<em><?php esc_html_e('Note: This happens instantly when the checkbox is changed.', WPALLSTARS_TEXT_DOMAIN); ?></em>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the Sync Guard toggle field.
|
||||
*/
|
||||
public static function render_sync_guard_field() {
|
||||
$key = 'sync_guard_enabled';
|
||||
$value = self::get_setting_value($key, 0);
|
||||
?>
|
||||
<div class="wp-allstars-toggle">
|
||||
<div class="wp-allstars-toggle-header" aria-expanded="false">
|
||||
<div class="wp-allstars-toggle-main">
|
||||
<div class="wp-allstars-toggle-left">
|
||||
<div class="wp-toggle-switch">
|
||||
<input type="checkbox"
|
||||
id="<?php echo esc_attr(self::$option_name . '_' . $key); ?>"
|
||||
name="<?php echo esc_attr(self::$option_name . '[' . $key . ']'); ?>"
|
||||
value="1"
|
||||
<?php checked($value, 1); ?>
|
||||
/>
|
||||
<span class="wp-toggle-slider"></span>
|
||||
</div>
|
||||
<label for="<?php echo esc_attr(self::$option_name . '_' . $key); ?>">
|
||||
<?php // Label provided by add_settings_field ?>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<p class="wp-setting-description description">
|
||||
<?php esc_html_e('Protect against data loss during simultaneous edits or synchronization.', WPALLSTARS_TEXT_DOMAIN); ?>
|
||||
</p>
|
||||
</div>
|
||||
<div class="wp-allstars-toggle-settings" style="display: none;">
|
||||
<div class="wp-allstars-setting-row">
|
||||
<p class="description">
|
||||
<?php esc_html_e('When enabled, Sync Guard uses timestamps or locking mechanisms (depending on mode) to prevent multiple users or processes from overwriting each other\s changes, especially during sync operations like cloud storage or Git.', WPALLSTARS_TEXT_DOMAIN); ?>
|
||||
</p>
|
||||
<?php /* Add sub-settings for Sync Guard mode here */ ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/* Removed the custom save_settings method as it's handled by the Settings API */
|
||||
// public static function save_settings() { ... }
|
||||
|
||||
}
|
||||
|
||||
// --- Initialization ---
|
||||
// Assuming WPALLSTARS_Admin_Manager calls WPALLSTARS_Settings_Manager::init()
|
||||
// If not, uncomment the line below, but it's better practice to centralize initialization.
|
||||
// WPALLSTARS_Settings_Manager::init();
|
||||
|
||||
@@ -98,8 +98,8 @@ class WP_Allstars_Theme_Manager {
|
||||
private static function get_theme_scripts() {
|
||||
return '
|
||||
jQuery(document).ready(function($) {
|
||||
if ($("#wpa-theme-list").length) {
|
||||
var $container = $("#wpa-theme-list");
|
||||
if ($("#wpallstars-theme-list").length) {
|
||||
var $container = $("#wpallstars-theme-list");
|
||||
var $loadingOverlay = $container.find(".wp-allstars-loading-overlay");
|
||||
|
||||
// AJAX request to get themes
|
||||
@@ -139,7 +139,7 @@ class WP_Allstars_Theme_Manager {
|
||||
public static function display_tab_content() {
|
||||
?>
|
||||
<div class="wp-allstars-settings-content tab-content" id="theme">
|
||||
<div id="wpa-theme-list" class="wpa-theme-container">
|
||||
<div id="wpallstars-theme-list" class="wpallstars-theme-container">
|
||||
<!-- Theme content will be loaded via AJAX -->
|
||||
<div class="wp-allstars-loading-overlay">
|
||||
<span class="spinner is-active"></span>
|
||||
|
||||
@@ -38,7 +38,7 @@ class WP_Allstars_Tools_Manager {
|
||||
|
||||
// Add inline CSS for tools to match the single column layout
|
||||
$custom_css = '
|
||||
#tools .wpa-pro-plugins {
|
||||
#tools .wpallstars-pro-plugins {
|
||||
padding: 15px 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -46,7 +46,7 @@ class WP_Allstars_Tools_Manager {
|
||||
max-width: 700px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
#tools .wpa-pro-plugin {
|
||||
#tools .wpallstars-pro-plugin {
|
||||
background: #fff;
|
||||
border: 1px solid #ddd;
|
||||
padding: 24px;
|
||||
@@ -59,14 +59,14 @@ class WP_Allstars_Tools_Manager {
|
||||
margin-bottom: 24px;
|
||||
max-width: 100%;
|
||||
}
|
||||
#tools .wpa-pro-plugin:last-child {
|
||||
#tools .wpallstars-pro-plugin:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
#tools .wpa-pro-plugin:hover {
|
||||
#tools .wpallstars-pro-plugin:hover {
|
||||
border-color: #2271b1;
|
||||
box-shadow: 0 2px 6px rgba(0,0,0,0.15);
|
||||
}
|
||||
#tools .wpa-pro-plugin .button-group {
|
||||
#tools .wpallstars-pro-plugin .button-group {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
';
|
||||
@@ -96,7 +96,7 @@ class WP_Allstars_Tools_Manager {
|
||||
|
||||
?>
|
||||
<div class="wp-allstars-settings-content tab-content" id="tools">
|
||||
<div class="wpa-pro-plugins">
|
||||
<div class="wpallstars-pro-plugins">
|
||||
<?php
|
||||
foreach ($tools as $tool) {
|
||||
self::display_tool_card(self::sanitize_tool_data($tool));
|
||||
@@ -118,7 +118,7 @@ class WP_Allstars_Tools_Manager {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<div class="wpa-pro-plugin">
|
||||
<div class="wpallstars-pro-plugin">
|
||||
<h3><?php echo esc_html($tool['name']); ?></h3>
|
||||
|
||||
<?php if (!empty($tool['description'])): ?>
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/**
|
||||
* WP Allstars Admin Script
|
||||
*
|
||||
* Handles UI interactions in the admin settings
|
||||
*/
|
||||
(function($) {
|
||||
'use strict';
|
||||
|
||||
// Document ready handler
|
||||
$(document).ready(function() {
|
||||
// Handle toggle switches
|
||||
$('.wp-toggle-switch input[type="checkbox"]').on('change', function() {
|
||||
var $this = $(this);
|
||||
var option = $this.attr('id');
|
||||
var value = $this.is(':checked') ? 1 : 0;
|
||||
|
||||
// Don't handle the admin color scheme toggle here - it has its own handler
|
||||
if (option === 'wp_allstars_admin_color_scheme') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Show update notification
|
||||
var $notification = $this.closest('label').find('.wp-setting-notification');
|
||||
if ($notification.length === 0) {
|
||||
$notification = $('<span class="wp-setting-notification">Saving...</span>');
|
||||
$this.closest('label').append($notification);
|
||||
} else {
|
||||
$notification.text('Saving...').removeClass('error').show();
|
||||
}
|
||||
|
||||
// Save the option via AJAX
|
||||
$.ajax({
|
||||
url: wpAllstars.ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'wp_allstars_update_option',
|
||||
nonce: wpAllstars.nonce,
|
||||
option: option,
|
||||
value: value
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
$notification.text('Saved!');
|
||||
setTimeout(function() {
|
||||
$notification.fadeOut(300);
|
||||
}, 2000);
|
||||
} else {
|
||||
$notification.text('Error').addClass('error');
|
||||
console.error('Error saving option:', response.data);
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
$notification.text('Error').addClass('error');
|
||||
console.error('AJAX error:', error);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Toggle expandable panels
|
||||
$('.wp-allstars-toggle-header').on('click', function() {
|
||||
var $this = $(this);
|
||||
var $settings = $this.next('.wp-allstars-toggle-settings');
|
||||
var isExpanded = $this.attr('aria-expanded') === 'true';
|
||||
|
||||
// Toggle aria-expanded attribute
|
||||
$this.attr('aria-expanded', !isExpanded);
|
||||
|
||||
// Toggle settings visibility
|
||||
$settings.slideToggle(200);
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,139 @@
|
||||
/**
|
||||
* WP Allstars Admin Script
|
||||
*
|
||||
* Handles generic UI interactions in the admin settings page.
|
||||
* Specific AJAX handlers for themes/plugins are handled in inline scripts
|
||||
* loaded by their respective managers.
|
||||
*/
|
||||
(function($) {
|
||||
'use strict';
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
// --- General UI Enhancements ---
|
||||
|
||||
// Toggle expandable sections/panels (using consistent class names)
|
||||
$('.wpallstars-toggle-header').on('click', function() {
|
||||
var $this = $(this);
|
||||
var $content = $this.next('.wpallstars-toggle-content'); // Use a consistent content class
|
||||
var isExpanded = $this.attr('aria-expanded') === 'true';
|
||||
|
||||
// Toggle ARIA attribute for accessibility
|
||||
$this.attr('aria-expanded', !isExpanded);
|
||||
|
||||
// Toggle content visibility with animation
|
||||
$content.slideToggle(200);
|
||||
|
||||
// Optional: Toggle an icon class on the header (e.g., dashicons-arrow-down / dashicons-arrow-up)
|
||||
$this.find('.dashicons').toggleClass('dashicons-arrow-down dashicons-arrow-up');
|
||||
});
|
||||
|
||||
// Initialize state for expandable sections (ensure icons are correct on load)
|
||||
$('.wpallstars-toggle-header').each(function() {
|
||||
var $this = $(this);
|
||||
var isExpanded = $this.attr('aria-expanded') === 'true';
|
||||
if (isExpanded) {
|
||||
$this.find('.dashicons').removeClass('dashicons-arrow-down').addClass('dashicons-arrow-up');
|
||||
$this.next('.wpallstars-toggle-content').show();
|
||||
} else {
|
||||
$this.find('.dashicons').removeClass('dashicons-arrow-up').addClass('dashicons-arrow-down');
|
||||
$this.next('.wpallstars-toggle-content').hide();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// --- Settings Save Logic (Example for simple toggles/inputs via AJAX) ---
|
||||
|
||||
// AJAX saving for specific settings (e.g., checkboxes, selects)
|
||||
// Add the class 'wpallstars-ajax-save' and 'data-setting-key="your_key"' to the input elements
|
||||
$('.wpallstars-settings-wrap').on('change', 'input.wpallstars-ajax-save, select.wpallstars-ajax-save', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const $input = $(this);
|
||||
const settingKey = $input.data('setting-key'); // Get key from data attribute
|
||||
let settingValue;
|
||||
|
||||
// Determine the value based on input type
|
||||
if ($input.is(':checkbox')) {
|
||||
settingValue = $input.is(':checked'); // Send true/false
|
||||
} else {
|
||||
settingValue = $input.val(); // Get value from select or other inputs
|
||||
}
|
||||
|
||||
// Find the feedback element (could be next to the input, or a general area)
|
||||
let $feedback = $input.siblings('.wpallstars-ajax-feedback');
|
||||
if (!$feedback.length) {
|
||||
// Fallback to a general feedback area if specific one not found
|
||||
$feedback = $input.closest('td, p, div').find('.wpallstars-ajax-feedback');
|
||||
if (!$feedback.length) {
|
||||
// If still no feedback area, maybe create one dynamically or log error
|
||||
console.error('WPAllstars: Feedback element not found for AJAX save.', $input);
|
||||
return; // Stop if no feedback area
|
||||
}
|
||||
}
|
||||
|
||||
// Check if settingKey is valid
|
||||
if (!settingKey) {
|
||||
console.error('WPAllstars: Missing data-setting-key attribute for AJAX save.', $input);
|
||||
$feedback.removeClass('spinner success is-active').addClass('error').text('Error: Missing setting key.').show();
|
||||
return;
|
||||
}
|
||||
|
||||
// Show spinner/updating message
|
||||
if ($feedback.hasClass('spinner')) {
|
||||
// If it's already designed as a spinner container
|
||||
$feedback.removeClass('success error').addClass('is-active').show();
|
||||
// Optionally add text: $feedback.text(wpallstars.l10n.updating || 'Updating...');
|
||||
} else {
|
||||
$feedback.removeClass('success error').addClass('spinner is-active').text(wpallstars.l10n.updating || 'Updating...').show();
|
||||
}
|
||||
|
||||
// Use localized strings and the specific nonce
|
||||
// $feedback.text(wpallstars.l10n.updating || 'Updating...'); // Moved spinner text above
|
||||
|
||||
|
||||
// Perform AJAX request
|
||||
$.ajax({
|
||||
url: wpallstars.ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'wpallstars_update_option', // The action hook in WPALLSTARS_Admin_Manager
|
||||
nonce: wpallstars.update_option_nonce, // Use the specific nonce
|
||||
setting_key: settingKey, // Send the setting key
|
||||
setting_value: settingValue // Send the setting value
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
$feedback.removeClass('spinner is-active error').addClass('success').text(response.data || wpallstars.l10n.success || 'Saved!');
|
||||
// Optionally fade out the success message after a delay
|
||||
setTimeout(function() {
|
||||
// $feedback.fadeOut();
|
||||
// Or just remove the text/class if element should stay
|
||||
$feedback.removeClass('success').text('');
|
||||
}, 3000);
|
||||
} else {
|
||||
const errorMessage = response.data || wpallstars.l10n.error || 'Error';
|
||||
$feedback.removeClass('spinner is-active success').addClass('error').text(errorMessage);
|
||||
console.error('WPAllstars AJAX Error:', response.data);
|
||||
}
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
$feedback.removeClass('spinner is-active success').addClass('error').text(wpallstars.l10n.error || 'Error');
|
||||
console.error('WPAllstars AJAX Request Failed:', textStatus, errorThrown);
|
||||
},
|
||||
// Removed complete: function() { ... } as feedback is handled in success/error
|
||||
});
|
||||
});
|
||||
|
||||
// --- Tab Handling ---
|
||||
// Basic tab switching is handled by WordPress core CSS (.nav-tab-active) and page reloads.
|
||||
// If you need AJAX tab loading in the future, implement it here.
|
||||
|
||||
// --- Initialization ---
|
||||
// Add any code that needs to run on page load after elements are ready.
|
||||
// Example: Initialize color pickers if added via WPALLSTARS_Settings_Manager
|
||||
|
||||
|
||||
}); // End document ready
|
||||
|
||||
})(jQuery);
|
||||
Reference in New Issue
Block a user