Refactor plugin structure:

- Rename pro-plugins-config.php to data/pro-plugins.php
- Rename recommended-plugins.php to free-plugins.php
- Rename class-recommended-plugins-manager.php to class-free-plugins-manager.php
- Update all references throughout the codebase
- Add enhanced hover effects to Go Pro buttons
This commit is contained in:
Marcus Quinn
2025-03-24 18:42:24 +00:00
parent 4bbcbe3d12
commit 9e1c077080
15 changed files with 1256 additions and 1237 deletions

View File

@ -1,53 +1,42 @@
<?php
/**
* WP ALLSTARS Admin Manager
*
* Main controller for the plugin's admin interface. Responsible for:
* - Registering the admin menu item
* - Enqueueing admin scripts and styles
* - Handling AJAX requests for settings updates
* - Rendering the admin page with tabs
* - Managing plugin settings registration
*
* @package WP_ALLSTARS
* @since 0.2.0
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
exit;
}
/**
* WP_Allstars_Admin_Manager class
*
* Centralizes all admin-related functionality for the WP ALLSTARS plugin.
*/
class WP_Allstars_Admin_Manager {
/**
* Initialize the class and register all hooks
*
* @return void
* Initialize the class and register hooks
*/
public static function init() {
// Register admin hooks
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('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();
}
/**
* Enqueue admin scripts and styles
*
* Loads CSS and JavaScript only on the plugin admin page
* to avoid conflicts with other plugins.
*
*
* @param string $hook The current admin page hook
* @return void
*/
public static function enqueue_admin_scripts($hook) {
// Only load on our plugin's admin page
if ('settings_page_wp-allstars' !== $hook) {
return;
}
@ -77,39 +66,79 @@ class WP_Allstars_Admin_Manager {
}
/**
* Register plugin settings
*
* Registers all settings fields with the WordPress Settings API
* for proper data sanitization and storage.
*
* @return void
* Register core plugin settings
*/
public static function register_settings() {
// Register settings for each tab as needed
// 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');
// Add additional settings as needed for future functionality
}
/**
* 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');
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']);
$value = intval($_POST['value']);
update_option($option, $value);
wp_send_json_success('Option updated');
// 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
$allowed_options = array(
'wp_allstars_auto_upload_images',
'wp_allstars_max_width',
'wp_allstars_max_height',
'wp_allstars_exclude_urls',
'wp_allstars_image_name_pattern',
'wp_allstars_image_alt_pattern'
);
if (!in_array($option, $allowed_options)) {
wp_send_json_error('Invalid option');
return;
}
// Update the option
$result = update_option($option, $value);
if ($result) {
wp_send_json_success(array(
'message' => 'Option updated successfully',
'option' => $option,
'value' => $value
));
} else {
wp_send_json_success(array(
'message' => 'No changes made to option',
'option' => $option
));
}
}
/**
* Register the admin menu item
*
* Adds the WP ALLSTARS menu item under the Settings menu
* in the WordPress admin dashboard.
*
* @return void
*/
public static function register_admin_menu() {
add_options_page(
@ -130,14 +159,12 @@ class WP_Allstars_Admin_Manager {
$active_tab = isset($_GET['tab']) ? $_GET['tab'] : 'general';
$active_category = isset($_GET['category']) ? $_GET['category'] : 'minimal';
// Clear cache and load required files
// Tab-specific resources
if ($active_tab === 'recommended') {
WP_Allstars_Plugin_Manager::clear_plugin_cache();
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
wp_enqueue_script('plugin-install');
wp_enqueue_script('updates');
add_thickbox();
wp_enqueue_style('wp-allstars-admin', plugins_url('css/wp-allstars-admin.css', dirname(__FILE__)));
wp_enqueue_style('wp-allstars-plugins', plugins_url('css/wp-allstars-plugins.css', dirname(__FILE__)));
// Add inline script to load plugins on page load
@ -237,7 +264,7 @@ class WP_Allstars_Admin_Manager {
break;
case 'workflow':
self::display_workflow_tab();
WP_Allstars_Workflow_Manager::display_tab_content();
break;
case 'theme':
@ -245,7 +272,7 @@ class WP_Allstars_Admin_Manager {
break;
case 'recommended':
WP_Allstars_Recommended_Plugins_Manager::display_tab_content();
WP_Allstars_Free_Plugins_Manager::display_tab_content();
break;
case 'pro':
@ -275,91 +302,4 @@ class WP_Allstars_Admin_Manager {
public static function enqueue_scripts($hook) {
self::enqueue_admin_scripts($hook);
}
/**
* Display the Workflow tab content
*/
public static function display_workflow_tab() {
?>
<div class="wp-allstars-settings-content tab-content" id="workflow">
<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('Enable Auto Upload Images', 'wp-allstars'); ?>
</label>
</div>
</div>
<p class="wp-setting-description">
<?php esc_html_e('Import images that have external URLs into your Media Library when saving. Consider disabling during large data imports with many external image URLs.', 'wp-allstars'); ?>
</p>
</div>
<div class="wp-allstars-toggle-settings">
<div class="wp-allstars-setting-row">
<label for="wp_allstars_max_width"><?php esc_html_e('Max Width', 'wp-allstars'); ?></label>
<input type="number"
id="wp_allstars_max_width"
name="wp_allstars_max_width"
value="<?php echo esc_attr(get_option('wp_allstars_max_width', 2560)); ?>"
/>
<p class="description"><?php esc_html_e('Maximum width for uploaded images in pixels.', 'wp-allstars'); ?></p>
</div>
<div class="wp-allstars-setting-row">
<label for="wp_allstars_max_height"><?php esc_html_e('Max Height', 'wp-allstars'); ?></label>
<input type="number"
id="wp_allstars_max_height"
name="wp_allstars_max_height"
value="<?php echo esc_attr(get_option('wp_allstars_max_height', 2560)); ?>"
/>
<p class="description"><?php esc_html_e('Maximum height for uploaded images in pixels.', 'wp-allstars'); ?></p>
</div>
<div class="wp-allstars-setting-row">
<label for="wp_exclude_urls"><?php esc_html_e('Exclude URLs', 'wp-allstars'); ?></label>
<textarea id="wp_exclude_urls"
name="wp_exclude_urls"
rows="3"
placeholder="example.com&#10;another-domain.com"
><?php echo esc_textarea(get_option('wp_allstars_exclude_urls', '')); ?></textarea>
<p class="description"><?php esc_html_e('Enter domains to exclude (one per line). Images from these domains will not be imported.', 'wp-allstars'); ?></p>
</div>
<div class="wp-allstars-setting-row">
<label for="wp_image_name"><?php esc_html_e('Image Name Pattern', 'wp-allstars'); ?></label>
<input type="text"
id="wp_image_name"
name="wp_image_name"
value="<?php echo esc_attr(get_option('wp_allstars_image_name_pattern', '%filename%')); ?>"
/>
<p class="description">
<?php esc_html_e('Available patterns:', 'wp-allstars'); ?> %filename%, %post_id%, %postname%, %timestamp%, %date%, %year%, %month%, %day%
</p>
</div>
<div class="wp-allstars-setting-row">
<label for="wp_image_alt"><?php esc_html_e('Image Alt Pattern', 'wp-allstars'); ?></label>
<input type="text"
id="wp_image_alt"
name="wp_image_alt"
value="<?php echo esc_attr(get_option('wp_allstars_image_alt_pattern', '%filename%')); ?>"
/>
<p class="description">
<?php esc_html_e('Available patterns:', 'wp-allstars'); ?> %filename%, %post_title%, %post_id%, %postname%, %timestamp%
</p>
</div>
</div>
</div>
</div>
<?php
}
}

View File

@ -0,0 +1,159 @@
<?php
/**
* WP ALLSTARS Free Plugins Manager
*
* Manages the Free Plugins tab including:
* - Category filtering system
* - Plugin recommendations by use case
* - Plugin installation functionality
*
* @package WP_ALLSTARS
* @since 0.2.0
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
/**
* WP_Allstars_Free_Plugins_Manager class
*
* Provides categorized plugin recommendations based on website needs
*/
class WP_Allstars_Free_Plugins_Manager {
/**
* Initialize the class and register hooks if needed
*
* @return void
*/
public static function init() {
// We'll implement AJAX handlers in a future update if needed
// add_action('wp_ajax_wp_allstars_load_free_plugins', array(self::class, 'ajax_load_free_plugins'));
}
/**
* Display the free plugins tab content
*
* Renders the category filter bar and plugin list container.
* Initial view shows 'minimal' category plugins by default.
*
* @return void
*/
public static function display_tab_content() {
// Get the active category from query params or use default
$active_category = isset($_GET['category']) ? sanitize_text_field($_GET['category']) : 'minimal';
?>
<div class="wp-allstars-settings-content tab-content" id="recommended">
<div id="wpa-plugin-filters" class="wp-filter">
<ul class="filter-links">
<li><a href="#" data-category="minimal" class="<?php echo $active_category == 'minimal' ? 'current' : ''; ?>">
<?php esc_html_e('Minimal', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="admin" class="<?php echo $active_category == 'admin' ? 'current' : ''; ?>">
<?php esc_html_e('Admin', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="cms" class="<?php echo $active_category == 'cms' ? 'current' : ''; ?>">
<?php esc_html_e('CMS', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="ecommerce" class="<?php echo $active_category == 'ecommerce' ? 'current' : ''; ?>">
<?php esc_html_e('eCommerce', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="marketing" class="<?php echo $active_category == 'marketing' ? 'current' : ''; ?>">
<?php esc_html_e('Marketing', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="media" class="<?php echo $active_category == 'media' ? 'current' : ''; ?>">
<?php esc_html_e('Media', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="security" class="<?php echo $active_category == 'security' ? 'current' : ''; ?>">
<?php esc_html_e('Security', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="developers" class="<?php echo $active_category == 'developers' ? 'current' : ''; ?>">
<?php esc_html_e('Developers', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="affiliates" class="<?php echo $active_category == 'affiliates' ? 'current' : ''; ?>">
<?php esc_html_e('Affiliates', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="ai" class="<?php echo $active_category == 'ai' ? 'current' : ''; ?>">
<?php esc_html_e('AI', 'wp-allstars'); ?>
</a></li>
</ul>
</div>
<div class="wp-allstars-plugin-browser">
<div class="wp-list-table plugin-install">
<div id="wpa-plugin-list">
<div id="the-list"></div>
</div>
</div>
<div class="wp-allstars-loading-overlay">
<span class="spinner is-active"></span>
</div>
</div>
<script>
jQuery(document).ready(function($) {
// Filter tab click handler
$('#wpa-plugin-filters .filter-links a').on('click', function(e) {
e.preventDefault();
var category = $(this).data('category');
// Update filter UI
$('#wpa-plugin-filters .filter-links a').removeClass('current');
$(this).addClass('current');
// Show loading spinner
$('.wp-allstars-loading-overlay').show();
// Clear existing plugins
$('#the-list').empty();
// Load plugins in selected category
$.ajax({
url: ajaxurl,
type: 'POST',
data: {
action: 'wp_allstars_load_plugins',
category: category,
nonce: '<?php echo wp_create_nonce('wp_allstars_load_plugins'); ?>'
},
success: function(response) {
if (response.success) {
// Hide loading spinner
$('.wp-allstars-loading-overlay').hide();
// Add plugins to the container
$('#the-list').html(response.data);
} else {
console.error('Error loading plugins:', response.data);
}
},
error: function(xhr, status, error) {
console.error('AJAX error:', error);
}
});
});
// Load initial category (minimal or from URL)
$('#wpa-plugin-filters .filter-links a.current').trigger('click');
});
</script>
</div>
<?php
}
/**
* Get the recommended plugins data
*
* @return array Array of recommended plugins by category
*/
public static function get_recommended_plugins() {
// Define the plugins data if it hasn't been included yet
if (!function_exists('wp_allstars_get_free_plugins')) {
require_once dirname(dirname(__FILE__)) . '/data/free-plugins.php';
}
return wp_allstars_get_free_plugins();
}
}

View File

@ -91,7 +91,7 @@ class WP_Allstars_Plugin_Manager {
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
// Get our recommended plugins for this category
$recommended_plugins = wp_allstars_get_recommended_plugins();
$recommended_plugins = wp_allstars_get_free_plugins();
if (!isset($recommended_plugins[$category])) {
wp_send_json_error('Invalid category: ' . $category);
return;
@ -309,7 +309,7 @@ class WP_Allstars_Plugin_Manager {
* @param object $plugin The plugin object
*/
public static function add_pro_button($plugin) {
$pro_plugins = wp_allstars_get_pro_plugins_config();
$pro_plugins = wp_allstars_get_pro_plugins();
if (isset($pro_plugins[$plugin->slug])) {
$pro_plugin = $pro_plugins[$plugin->slug];
@ -355,7 +355,7 @@ class WP_Allstars_Plugin_Manager {
* Clear plugin cache when plugins are updated, activated, or deactivated
*/
public static function clear_plugin_cache() {
$recommended_plugins = wp_allstars_get_recommended_plugins();
$recommended_plugins = wp_allstars_get_free_plugins();
foreach (array_keys($recommended_plugins) as $category) {
delete_transient('wp_allstars_plugins_' . $category);
}

View File

@ -43,8 +43,8 @@ class WP_Allstars_Pro_Plugins_Manager {
* @return array Array of premium plugin data
*/
public static function get_pro_plugins() {
// Load pro plugin configuration from the function defined in pro-plugins-config.php
return wp_allstars_get_pro_plugins_config();
// Load pro plugin configuration from the data file
return wp_allstars_get_pro_plugins();
}
/**

View File

@ -1,121 +0,0 @@
<?php
/**
* WP ALLSTARS Recommended Plugins Manager
*
* Manages the Recommended Plugins tab including:
* - Category filtering system
* - Plugin recommendations by use case
* - Plugin installation functionality
*
* @package WP_ALLSTARS
* @since 0.2.0
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
/**
* WP_Allstars_Recommended_Plugins_Manager class
*
* Provides categorized plugin recommendations based on website needs
*/
class WP_Allstars_Recommended_Plugins_Manager {
/**
* Initialize the class and register hooks if needed
*
* @return void
*/
public static function init() {
// We'll implement AJAX handlers in a future update if needed
// add_action('wp_ajax_wp_allstars_load_recommended_plugins', array(self::class, 'ajax_load_recommended_plugins'));
}
/**
* Display the recommended plugins tab content
*
* Renders the category filter bar and plugin list container.
* Initial view shows 'minimal' category plugins by default.
*
* @return void
*/
public static function display_tab_content() {
// Get the active category from query params or use default
$active_category = isset($_GET['category']) ? sanitize_text_field($_GET['category']) : 'minimal';
?>
<div class="wp-allstars-settings-content tab-content" id="recommended">
<div id="wpa-plugin-filters" class="wp-filter">
<ul class="filter-links">
<li><a href="#" data-category="minimal" class="<?php echo $active_category == 'minimal' ? 'current' : ''; ?>">
<?php esc_html_e('Minimal', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="admin" class="<?php echo $active_category == 'admin' ? 'current' : ''; ?>">
<?php esc_html_e('Admin', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="ai" class="<?php echo $active_category == 'ai' ? 'current' : ''; ?>">
<?php esc_html_e('AI', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="cms" class="<?php echo $active_category == 'cms' ? 'current' : ''; ?>">
<?php esc_html_e('CMS', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="compliance" class="<?php echo $active_category == 'compliance' ? 'current' : ''; ?>">
<?php esc_html_e('Compliance', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="crm" class="<?php echo $active_category == 'crm' ? 'current' : ''; ?>">
<?php esc_html_e('CRM', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="ecommerce" class="<?php echo $active_category == 'ecommerce' ? 'current' : ''; ?>">
<?php esc_html_e('Ecommerce', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="lms" class="<?php echo $active_category == 'lms' ? 'current' : ''; ?>">
<?php esc_html_e('LMS', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="media" class="<?php echo $active_category == 'media' ? 'current' : ''; ?>">
<?php esc_html_e('Media', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="seo" class="<?php echo $active_category == 'seo' ? 'current' : ''; ?>">
<?php esc_html_e('SEO', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="setup" class="<?php echo $active_category == 'setup' ? 'current' : ''; ?>">
<?php esc_html_e('Setup', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="social" class="<?php echo $active_category == 'social' ? 'current' : ''; ?>">
<?php esc_html_e('Social', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="speed" class="<?php echo $active_category == 'speed' ? 'current' : ''; ?>">
<?php esc_html_e('Speed', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="translation" class="<?php echo $active_category == 'translation' ? 'current' : ''; ?>">
<?php esc_html_e('Translation', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="advanced" class="<?php echo $active_category == 'advanced' ? 'current' : ''; ?>">
<?php esc_html_e('Advanced', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="debug" class="<?php echo $active_category == 'debug' ? 'current' : ''; ?>">
<?php esc_html_e('Debug', 'wp-allstars'); ?>
</a></li>
</ul>
</div>
<div class="wp-allstars-plugin-browser">
<div id="wpa-plugin-list"></div>
</div>
</div>
<?php
}
/**
* Get the list of recommended plugins
*
* @return array Array of recommended plugins
*/
public static function get_recommended_plugins() {
// Define the plugins data if it hasn't been included yet
if (!function_exists('wp_allstars_get_recommended_plugins')) {
require_once dirname(dirname(__FILE__)) . '/data/recommended-plugins.php';
}
return wp_allstars_get_recommended_plugins();
}
}

View File

@ -2,12 +2,12 @@
/**
* Tools Manager Class
*
* Handles the display and management of recommended tools.
* @package WP_ALLSTARS
* @since 0.2.0
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
if (!defined('ABSPATH')) {
exit;
}
class WP_Allstars_Tools_Manager {
@ -16,16 +16,33 @@ class WP_Allstars_Tools_Manager {
* Initialize the class
*/
public static function init() {
// No hooks needed currently as styles are included directly in the HTML output
add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_styles'));
}
/**
* Enqueue styles for the tools tab
*
* @param string $hook Current admin page hook
*/
public static function enqueue_styles($hook) {
if ('settings_page_wp-allstars' !== $hook) {
return;
}
wp_enqueue_style(
'wp-allstars-admin',
plugins_url('css/wp-allstars-admin.css', dirname(__FILE__)),
array(),
WP_ALLSTARS_VERSION
);
}
/**
* Get all tools
*
* @return array Tools configuration
* @return array
*/
public static function get_tools() {
// Using the existing function to maintain compatibility
return wp_allstars_get_tools();
}
@ -40,116 +57,15 @@ class WP_Allstars_Tools_Manager {
return strcasecmp($a['name'], $b['name']);
});
// Output the CSS and HTML for the tools tab
?>
<div class="wp-allstars-settings-content tab-content" id="tools">
<style>
.wpa-pro-plugins {
padding: 0;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(450px, 1fr));
gap: 24px;
max-width: 1920px;
margin: 0 auto;
}
.wpa-pro-plugin {
background: #fff;
border: 1px solid #ddd;
padding: 24px;
border-radius: 8px;
display: flex;
flex-direction: column;
transition: all 0.2s ease;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.wpa-pro-plugin:hover {
border-color: #2271b1;
box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.wpa-pro-plugin h3 {
margin: 0 0 12px;
font-size: 16px;
font-weight: 600;
color: #1d2327;
line-height: 1.4;
}
.wpa-pro-plugin p {
margin: 0 0 16px;
color: #50575e;
font-size: 14px;
line-height: 1.6;
}
.wpa-pro-plugin .button-group {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: auto;
}
.wpa-pro-plugin .button {
text-decoration: none;
min-width: 120px;
text-align: center;
height: 30px;
line-height: 28px;
padding: 0 12px;
font-size: 13px;
font-weight: normal;
margin: 0;
border: 1px solid #0071a1 !important;
border-radius: 3px !important;
background: #f6f7f7;
color: #0071a1;
display: inline-block;
vertical-align: top;
box-shadow: none;
cursor: pointer;
}
.wpa-pro-plugin .button:hover {
background: #f0f0f1;
border-color: #0071a1;
color: #0071a1;
}
.wpa-pro-plugin .button.button-primary {
background: #2271b1;
border-color: #2271b1 !important;
color: #fff;
}
.wpa-tool-card .button.button-primary:hover {
background: #135e96;
border-color: #135e96 !important;
}
@media screen and (max-width: 960px) {
.wpa-tools-grid {
grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
gap: 20px;
padding: 16px;
}
.wpa-pro-plugin {
padding: 20px;
}
}
@media screen and (max-width: 782px) {
.wpa-tools-grid {
grid-template-columns: 1fr;
gap: 16px;
padding: 12px;
}
.wpa-pro-plugin {
padding: 16px;
}
.wpa-pro-plugin .button {
width: 100%;
}
}
</style>
<div class="wpa-pro-plugins">
<?php
foreach ($tools as $tool) {
self::display_tool_card($tool);
}
?>
</div>
<div class="wpa-pro-plugins">
<?php
foreach ($tools as $tool) {
self::display_tool_card(self::sanitize_tool_data($tool));
}
?>
</div>
</div>
<?php
}
@ -157,19 +73,33 @@ class WP_Allstars_Tools_Manager {
/**
* Display a single tool card
*
* @param array $tool Tool configuration
* @param array $tool Sanitized tool configuration
*/
public static function display_tool_card($tool) {
private static function display_tool_card($tool) {
// Ensure we have the required fields
if (empty($tool['name'])) {
return;
}
?>
<div class="wpa-pro-plugin">
<h3><?php echo esc_html($tool['name']); ?></h3>
<p><?php echo esc_html($tool['description']); ?></p>
<?php if (isset($tool['button_group'])): ?>
<?php if (!empty($tool['description'])): ?>
<p><?php echo esc_html($tool['description']); ?></p>
<?php endif; ?>
<?php if (!empty($tool['button_group']) && is_array($tool['button_group'])): ?>
<div class="button-group">
<?php foreach ($tool['button_group'] as $button): ?>
<a href="<?php echo esc_url($button['url']); ?>" target="_blank" class="button <?php echo isset($button['primary']) && $button['primary'] ? 'button-primary' : ''; ?>">
<?php echo esc_html($button['text']); ?>
</a>
<?php if (!empty($button['url']) && !empty($button['text'])): ?>
<a
href="<?php echo esc_url($button['url']); ?>"
target="_blank"
class="button <?php echo !empty($button['primary']) ? 'button-primary' : ''; ?>"
>
<?php echo esc_html($button['text']); ?>
</a>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
@ -178,13 +108,16 @@ class WP_Allstars_Tools_Manager {
}
/**
* Enqueue styles specific to tools
*
* Note: This method is no longer used as styles are now directly included in the display_tab_content method
* for immediate application. Kept for reference or future use if needed.
* Sanitize tool data
*
* @param array $tool Raw tool data
* @return array Sanitized tool data
*/
public static function enqueue_styles($hook) {
// This method is currently not in use as styles are directly included in the HTML output
// to ensure immediate application without relying on the WordPress hook system timing
private static function sanitize_tool_data($tool) {
return array(
'name' => isset($tool['name']) ? sanitize_text_field($tool['name']) : '',
'description' => isset($tool['description']) ? sanitize_text_field($tool['description']) : '',
'button_group' => isset($tool['button_group']) ? $tool['button_group'] : array(),
);
}
}

View File

@ -0,0 +1,178 @@
<?php
/**
* Workflow Manager Class
*
* @package WP_ALLSTARS
* @since 0.2.0
*/
if (!defined('ABSPATH')) {
exit;
}
class WP_Allstars_Workflow_Manager {
/**
* Initialize the class
*/
public static function init() {
add_action('admin_init', array(__CLASS__, 'register_settings'));
}
/**
* Register workflow settings
*/
public static function register_settings() {
register_setting('wp_allstars_workflow', 'wp_allstars_workflow_options');
register_setting('wp_allstars_workflow', 'wp_allstars_auto_upload_images');
register_setting('wp_allstars_workflow', 'wp_allstars_max_width');
register_setting('wp_allstars_workflow', 'wp_allstars_max_height');
register_setting('wp_allstars_workflow', 'wp_allstars_exclude_urls');
register_setting('wp_allstars_workflow', 'wp_allstars_image_name_pattern');
register_setting('wp_allstars_workflow', 'wp_allstars_image_alt_pattern');
}
/**
* Display the workflow tab content
*/
public static function display_tab_content() {
?>
<div class="wp-allstars-settings-content tab-content" id="workflow">
<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('Enable Auto Upload Images', 'wp-allstars'); ?>
</label>
</div>
</div>
<p class="wp-setting-description">
<?php esc_html_e('Import images that have external URLs into your Media Library when saving. Consider disabling during large data imports with many external image URLs.', 'wp-allstars'); ?>
</p>
</div>
<div class="wp-allstars-toggle-settings">
<div class="wp-allstars-setting-row">
<label for="wp_allstars_max_width"><?php esc_html_e('Max Width', 'wp-allstars'); ?></label>
<input type="number"
id="wp_allstars_max_width"
name="wp_allstars_max_width"
value="<?php echo esc_attr(get_option('wp_allstars_max_width', 2560)); ?>"
/>
<p class="description"><?php esc_html_e('Maximum width for uploaded images in pixels.', 'wp-allstars'); ?></p>
</div>
<div class="wp-allstars-setting-row">
<label for="wp_allstars_max_height"><?php esc_html_e('Max Height', 'wp-allstars'); ?></label>
<input type="number"
id="wp_allstars_max_height"
name="wp_allstars_max_height"
value="<?php echo esc_attr(get_option('wp_allstars_max_height', 2560)); ?>"
/>
<p class="description"><?php esc_html_e('Maximum height for uploaded images in pixels.', 'wp-allstars'); ?></p>
</div>
<div class="wp-allstars-setting-row">
<label for="wp_allstars_exclude_urls"><?php esc_html_e('Exclude URLs', 'wp-allstars'); ?></label>
<textarea id="wp_allstars_exclude_urls"
name="wp_allstars_exclude_urls"
rows="3"
placeholder="example.com&#10;another-domain.com"
><?php echo esc_textarea(get_option('wp_allstars_exclude_urls', '')); ?></textarea>
<p class="description"><?php esc_html_e('Enter domains to exclude (one per line). Images from these domains will not be imported.', 'wp-allstars'); ?></p>
</div>
<div class="wp-allstars-setting-row">
<label for="wp_allstars_image_name"><?php esc_html_e('Image Name Pattern', 'wp-allstars'); ?></label>
<input type="text"
id="wp_allstars_image_name"
name="wp_allstars_image_name"
value="<?php echo esc_attr(get_option('wp_allstars_image_name_pattern', '%filename%')); ?>"
/>
<p class="description">
<?php esc_html_e('Available patterns:', 'wp-allstars'); ?> %filename%, %post_id%, %postname%, %timestamp%, %date%, %year%, %month%, %day%
</p>
</div>
<div class="wp-allstars-setting-row">
<label for="wp_allstars_image_alt"><?php esc_html_e('Image Alt Pattern', 'wp-allstars'); ?></label>
<input type="text"
id="wp_allstars_image_alt"
name="wp_allstars_image_alt"
value="<?php echo esc_attr(get_option('wp_allstars_image_alt_pattern', '%filename%')); ?>"
/>
<p class="description">
<?php esc_html_e('Available patterns:', 'wp-allstars'); ?> %filename%, %post_title%, %post_id%, %postname%, %timestamp%
</p>
</div>
</div>
</div>
</div>
<?php
}
/**
* Save workflow settings via AJAX
*/
public static function save_settings() {
// 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');
return;
}
$options = array();
// Auto upload images setting
$options['auto_upload_images'] = isset($_POST['auto_upload_images']) ?
(bool) $_POST['auto_upload_images'] :
false;
// Max dimensions
$options['max_width'] = isset($_POST['max_width']) ?
absint($_POST['max_width']) :
2560;
$options['max_height'] = isset($_POST['max_height']) ?
absint($_POST['max_height']) :
2560;
// Exclude URLs
$options['exclude_urls'] = isset($_POST['exclude_urls']) ?
sanitize_textarea_field($_POST['exclude_urls']) :
'';
// Name and alt patterns
$options['image_name_pattern'] = isset($_POST['image_name_pattern']) ?
sanitize_text_field($_POST['image_name_pattern']) :
'%filename%';
$options['image_alt_pattern'] = isset($_POST['image_alt_pattern']) ?
sanitize_text_field($_POST['image_alt_pattern']) :
'%filename%';
// Update the options
update_option('wp_allstars_workflow_options', $options);
// Also update individual options for backward compatibility
update_option('wp_allstars_auto_upload_images', $options['auto_upload_images']);
update_option('wp_allstars_max_width', $options['max_width']);
update_option('wp_allstars_max_height', $options['max_height']);
update_option('wp_allstars_exclude_urls', $options['exclude_urls']);
update_option('wp_allstars_image_name_pattern', $options['image_name_pattern']);
update_option('wp_allstars_image_alt_pattern', $options['image_alt_pattern']);
wp_send_json_success('Workflow settings saved');
}
}