Code cleanup: Improved documentation and removed backward compatibility code
This commit is contained in:
@ -2,21 +2,35 @@
|
|||||||
/**
|
/**
|
||||||
* WP ALLSTARS Admin Manager
|
* WP ALLSTARS Admin Manager
|
||||||
*
|
*
|
||||||
* Handles admin-related functionality including menu registration,
|
* Main controller for the plugin's admin interface. Responsible for:
|
||||||
* script enqueueing, and admin page rendering.
|
* - 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')) {
|
if (!defined('ABSPATH')) {
|
||||||
exit; // Exit if accessed directly
|
exit; // Exit if accessed directly
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WP_Allstars_Admin_Manager class
|
||||||
|
*
|
||||||
|
* Centralizes all admin-related functionality for the WP ALLSTARS plugin.
|
||||||
|
*/
|
||||||
class WP_Allstars_Admin_Manager {
|
class WP_Allstars_Admin_Manager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the class
|
* Initialize the class and register all hooks
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
// Register hooks - we'll add more as we refactor each function
|
// Register admin hooks
|
||||||
add_action('admin_menu', array(__CLASS__, 'register_admin_menu'));
|
add_action('admin_menu', array(__CLASS__, 'register_admin_menu'));
|
||||||
add_action('wp_ajax_wp_allstars_update_option', array(__CLASS__, 'update_option'));
|
add_action('wp_ajax_wp_allstars_update_option', array(__CLASS__, 'update_option'));
|
||||||
add_action('admin_init', array(__CLASS__, 'register_settings'));
|
add_action('admin_init', array(__CLASS__, 'register_settings'));
|
||||||
@ -26,17 +40,36 @@ class WP_Allstars_Admin_Manager {
|
|||||||
/**
|
/**
|
||||||
* Enqueue admin scripts and styles
|
* 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
|
* @param string $hook The current admin page hook
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function enqueue_admin_scripts($hook) {
|
public static function enqueue_admin_scripts($hook) {
|
||||||
|
// Only load on our plugin's admin page
|
||||||
if ('settings_page_wp-allstars' !== $hook) {
|
if ('settings_page_wp-allstars' !== $hook) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_enqueue_style('wp-allstars-admin', plugins_url('css/wp-allstars-admin.css', dirname(__FILE__)));
|
// Enqueue admin stylesheet
|
||||||
wp_enqueue_script('wp-allstars-admin', plugins_url('js/wp-allstars-admin.js', dirname(__FILE__)), array('jquery'), WP_ALLSTARS_VERSION, true);
|
wp_enqueue_style(
|
||||||
|
'wp-allstars-admin',
|
||||||
|
plugins_url('css/wp-allstars-admin.css', dirname(__FILE__)),
|
||||||
|
array(),
|
||||||
|
WP_ALLSTARS_VERSION
|
||||||
|
);
|
||||||
|
|
||||||
// Localize the script with new data
|
// 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(
|
wp_localize_script('wp-allstars-admin', 'wpAllstars', array(
|
||||||
'nonce' => wp_create_nonce('wp-allstars-nonce'),
|
'nonce' => wp_create_nonce('wp-allstars-nonce'),
|
||||||
'ajaxurl' => admin_url('admin-ajax.php')
|
'ajaxurl' => admin_url('admin-ajax.php')
|
||||||
@ -45,10 +78,18 @@ class WP_Allstars_Admin_Manager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Register plugin settings
|
* Register plugin settings
|
||||||
|
*
|
||||||
|
* Registers all settings fields with the WordPress Settings API
|
||||||
|
* for proper data sanitization and storage.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function register_settings() {
|
public static function register_settings() {
|
||||||
// Removed minification settings
|
// Register settings for each tab as needed
|
||||||
// This is a placeholder for future settings registration
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,10 +2,14 @@
|
|||||||
/**
|
/**
|
||||||
* WP ALLSTARS Plugin Manager
|
* WP ALLSTARS Plugin Manager
|
||||||
*
|
*
|
||||||
* Handles all plugin-related functionality including:
|
* Core class for handling WordPress plugin data and operations:
|
||||||
* - Plugin data caching
|
* - Plugin data retrieval and caching mechanism
|
||||||
* - AJAX handlers for plugin data
|
* - AJAX handlers for asynchronous plugin data loading
|
||||||
* - Plugin card generation
|
* - Plugin card UI generation with install/update actions
|
||||||
|
* - Cache clearing on plugin changes
|
||||||
|
*
|
||||||
|
* @package WP_ALLSTARS
|
||||||
|
* @since 0.2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Exit if accessed directly
|
// Exit if accessed directly
|
||||||
@ -13,15 +17,23 @@ if (!defined('ABSPATH')) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WP_Allstars_Plugin_Manager class
|
||||||
|
*
|
||||||
|
* Manages the Free Plugins tab and provides core plugin functionality
|
||||||
|
* for other plugin-related managers.
|
||||||
|
*/
|
||||||
class WP_Allstars_Plugin_Manager {
|
class WP_Allstars_Plugin_Manager {
|
||||||
/**
|
/**
|
||||||
* Initialize the class
|
* Initialize the class and register all action hooks
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
// Add AJAX handlers
|
// Register AJAX handler for plugin data retrieval
|
||||||
add_action('wp_ajax_wp_allstars_get_plugins', [self::class, 'ajax_get_plugins']);
|
add_action('wp_ajax_wp_allstars_get_plugins', [self::class, 'ajax_get_plugins']);
|
||||||
|
|
||||||
// Plugin cache clearing
|
// Register hooks for automatic cache clearing when plugins change
|
||||||
add_action('upgrader_process_complete', [self::class, 'clear_plugin_cache'], 10, 0);
|
add_action('upgrader_process_complete', [self::class, 'clear_plugin_cache'], 10, 0);
|
||||||
add_action('activated_plugin', [self::class, 'clear_plugin_cache']);
|
add_action('activated_plugin', [self::class, 'clear_plugin_cache']);
|
||||||
add_action('deactivated_plugin', [self::class, 'clear_plugin_cache']);
|
add_action('deactivated_plugin', [self::class, 'clear_plugin_cache']);
|
||||||
@ -30,13 +42,16 @@ class WP_Allstars_Plugin_Manager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get cached plugin data for a category
|
* Get cached plugin data for a specific category
|
||||||
*
|
*
|
||||||
* @param string $category The plugin category
|
* Uses the WordPress transients API to store plugin data
|
||||||
* @return mixed The cached plugin data or false if no cache
|
* for improved performance and reduced API calls.
|
||||||
|
*
|
||||||
|
* @param string $category The plugin category to retrieve (e.g., 'featured', 'popular')
|
||||||
|
* @return mixed Array of plugin data if cache exists, false otherwise
|
||||||
*/
|
*/
|
||||||
public static function get_cached_plugins($category) {
|
public static function get_cached_plugins($category) {
|
||||||
$cache_key = 'wp_allstars_plugins_' . $category;
|
$cache_key = 'wp_allstars_plugins_' . sanitize_key($category);
|
||||||
$cached_data = get_transient($cache_key);
|
$cached_data = get_transient($cache_key);
|
||||||
|
|
||||||
if ($cached_data !== false) {
|
if ($cached_data !== false) {
|
||||||
|
@ -1,8 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Pro Plugins Manager Class
|
* WP ALLSTARS Pro Plugins Manager
|
||||||
*
|
*
|
||||||
* Handles the display and management of pro plugin recommendations.
|
* Handles premium plugin recommendations including:
|
||||||
|
* - Premium plugin information display
|
||||||
|
* - Purchase links and affiliate management
|
||||||
|
* - Plugin feature highlighting
|
||||||
|
* - Price and promotion display
|
||||||
|
*
|
||||||
|
* @package WP_ALLSTARS
|
||||||
|
* @since 0.2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// If this file is called directly, abort.
|
// If this file is called directly, abort.
|
||||||
@ -10,44 +17,63 @@ if ( ! defined( 'WPINC' ) ) {
|
|||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WP_Allstars_Pro_Plugins_Manager class
|
||||||
|
*
|
||||||
|
* Responsible for the Pro Plugins tab in the plugin interface.
|
||||||
|
*/
|
||||||
class WP_Allstars_Pro_Plugins_Manager {
|
class WP_Allstars_Pro_Plugins_Manager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the class
|
* Initialize the class and register required hooks
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
// Hook into WordPress if needed
|
// Enqueue pro plugins specific styles
|
||||||
add_action('admin_enqueue_scripts', array(self::class, 'enqueue_styles'));
|
add_action('admin_enqueue_scripts', array(self::class, 'enqueue_styles'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all pro plugin configurations
|
* Get all pro plugin configurations
|
||||||
*
|
*
|
||||||
* @return array Pro plugin configurations
|
* Retrieves premium plugin information from configuration,
|
||||||
|
* including pricing, features, and purchase links.
|
||||||
|
*
|
||||||
|
* @return array Array of premium plugin data
|
||||||
*/
|
*/
|
||||||
public static function get_pro_plugins() {
|
public static function get_pro_plugins() {
|
||||||
// Using the existing function to maintain compatibility
|
// Load pro plugin configuration from data file
|
||||||
return wp_allstars_get_pro_plugins_config();
|
global $wp_allstars_pro_plugins;
|
||||||
|
return $wp_allstars_pro_plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display the pro plugins tab content
|
* Display the pro plugins tab content
|
||||||
|
*
|
||||||
|
* Renders the premium plugins tab with plugin cards
|
||||||
|
* in alphabetical order by name.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function display_tab_content() {
|
public static function display_tab_content() {
|
||||||
|
// Get premium plugin data
|
||||||
$pro_plugins = self::get_pro_plugins();
|
$pro_plugins = self::get_pro_plugins();
|
||||||
|
|
||||||
// Sort plugins alphabetically by name
|
// Sort plugins alphabetically by name for consistent display
|
||||||
uasort($pro_plugins, function($a, $b) {
|
uasort($pro_plugins, function($a, $b) {
|
||||||
return strcasecmp($a['name'], $b['name']);
|
return strcasecmp($a['name'], $b['name']);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Output the HTML for the pro plugins tab
|
// 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="wpa-pro-plugins">';
|
||||||
|
|
||||||
|
// Render each plugin card
|
||||||
foreach ($pro_plugins as $plugin) {
|
foreach ($pro_plugins as $plugin) {
|
||||||
self::display_plugin_card($plugin);
|
self::display_plugin_card($plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close the container
|
||||||
echo '</div></div>';
|
echo '</div></div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,27 +2,46 @@
|
|||||||
/**
|
/**
|
||||||
* WP ALLSTARS Recommended Plugins Manager
|
* WP ALLSTARS Recommended Plugins Manager
|
||||||
*
|
*
|
||||||
* Manages the recommended plugins tab and functionality
|
* 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')) {
|
if (!defined('ABSPATH')) {
|
||||||
exit; // Exit if accessed directly
|
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 {
|
class WP_Allstars_Recommended_Plugins_Manager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the class
|
* Initialize the class and register hooks if needed
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
// No specific initialization needed currently
|
// Register AJAX handlers if needed for future functionality
|
||||||
|
add_action('wp_ajax_wp_allstars_load_recommended_plugins', array(self::class, 'ajax_load_recommended_plugins'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display the recommended plugins tab content
|
* 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() {
|
public static function display_tab_content() {
|
||||||
// Get the active category from query params or default to 'minimal'
|
// Get the active category from query params or use default
|
||||||
$active_category = isset($_GET['category']) ? sanitize_text_field($_GET['category']) : 'minimal';
|
$active_category = isset($_GET['category']) ? sanitize_text_field($_GET['category']) : 'minimal';
|
||||||
?>
|
?>
|
||||||
<div class="wp-allstars-settings-content tab-content" id="recommended">
|
<div class="wp-allstars-settings-content tab-content" id="recommended">
|
||||||
|
@ -1,8 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Theme Manager Class
|
* WP ALLSTARS Theme Manager
|
||||||
*
|
*
|
||||||
* Handles the display and management of recommended themes.
|
* Manages the Theme tab functionality including:
|
||||||
|
* - Theme data retrieval and caching
|
||||||
|
* - AJAX handlers for theme browsing
|
||||||
|
* - Theme activation and installation
|
||||||
|
* - Theme UI rendering
|
||||||
|
*
|
||||||
|
* @package WP_ALLSTARS
|
||||||
|
* @since 0.2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// If this file is called directly, abort.
|
// If this file is called directly, abort.
|
||||||
@ -10,45 +17,66 @@ if (!defined('WPINC')) {
|
|||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WP_Allstars_Theme_Manager class
|
||||||
|
*
|
||||||
|
* Provides theme discovery and management functionality
|
||||||
|
*/
|
||||||
class WP_Allstars_Theme_Manager {
|
class WP_Allstars_Theme_Manager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the class
|
* Initialize the class and register all action hooks
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
// Register AJAX handlers
|
// Register AJAX handlers for theme operations
|
||||||
add_action('wp_ajax_wp_allstars_get_themes', array(self::class, 'ajax_get_themes'));
|
add_action('wp_ajax_wp_allstars_get_themes', array(self::class, 'ajax_get_themes'));
|
||||||
add_action('wp_ajax_wp_allstars_activate_theme', array(self::class, 'activate_theme'));
|
add_action('wp_ajax_wp_allstars_activate_theme', array(self::class, 'activate_theme'));
|
||||||
|
|
||||||
// Cache clearing hooks
|
// Register hooks for automatic cache clearing when themes change
|
||||||
add_action('upgrader_process_complete', array(self::class, 'clear_theme_cache'), 10, 0);
|
add_action('upgrader_process_complete', array(self::class, 'clear_theme_cache'), 10, 0);
|
||||||
add_action('switch_theme', array(self::class, 'clear_theme_cache'));
|
add_action('switch_theme', array(self::class, 'clear_theme_cache'));
|
||||||
|
|
||||||
// Enqueue assets when needed
|
// Enqueue theme-specific assets when needed
|
||||||
add_action('admin_enqueue_scripts', array(self::class, 'enqueue_scripts'));
|
add_action('admin_enqueue_scripts', array(self::class, 'enqueue_scripts'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enqueue scripts and styles for the theme tab
|
* Enqueue scripts and styles for the theme tab
|
||||||
|
*
|
||||||
|
* Loads necessary WordPress core scripts and stylesheets
|
||||||
|
* required for theme browsing and installation.
|
||||||
|
*
|
||||||
|
* @param string $hook The current admin page hook
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function enqueue_scripts($hook) {
|
public static function enqueue_scripts($hook) {
|
||||||
|
// Only load on plugin pages
|
||||||
if (strpos($hook, 'wp-allstars') === false) {
|
if (strpos($hook, 'wp-allstars') === false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only load on theme tab
|
// Only load when theme tab is active
|
||||||
if (!isset($_GET['tab']) || $_GET['tab'] !== 'theme') {
|
if (!isset($_GET['tab']) || $_GET['tab'] !== 'theme') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Required for theme installation
|
// Load WordPress core theme functionality
|
||||||
require_once ABSPATH . 'wp-admin/includes/theme.php';
|
require_once ABSPATH . 'wp-admin/includes/theme.php';
|
||||||
|
|
||||||
|
// Enqueue core WordPress scripts for theme operations
|
||||||
wp_enqueue_script('theme-install');
|
wp_enqueue_script('theme-install');
|
||||||
wp_enqueue_script('updates');
|
wp_enqueue_script('updates');
|
||||||
add_thickbox();
|
add_thickbox();
|
||||||
|
|
||||||
// Styles
|
// Enqueue theme tab specific styles
|
||||||
wp_enqueue_style('wp-allstars-admin', plugins_url('css/wp-allstars-admin.css', dirname(__FILE__)));
|
wp_enqueue_style(
|
||||||
|
'wp-allstars-admin',
|
||||||
|
plugins_url('css/wp-allstars-admin.css', dirname(__FILE__)),
|
||||||
|
array(),
|
||||||
|
WP_ALLSTARS_VERSION
|
||||||
|
);
|
||||||
wp_enqueue_style('wp-allstars-plugins', plugins_url('css/wp-allstars-plugins.css', dirname(__FILE__)));
|
wp_enqueue_style('wp-allstars-plugins', plugins_url('css/wp-allstars-plugins.css', dirname(__FILE__)));
|
||||||
|
|
||||||
// Enqueue the main admin script before adding inline script
|
// Enqueue the main admin script before adding inline script
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Admin settings page - Delegates to the WP_Allstars_Admin_Manager class
|
* WP ALLSTARS Admin System Loader
|
||||||
*
|
*
|
||||||
* This file serves as a compatibility layer to keep backward compatibility
|
* Loads all admin components and initializes manager classes
|
||||||
* with existing code that might still call the old procedural functions.
|
* responsible for different tabs in the plugin interface.
|
||||||
* All actual functionality has been moved to dedicated manager classes.
|
*
|
||||||
|
* @package WP_ALLSTARS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Include data files
|
// Include data configuration files
|
||||||
require_once dirname(__FILE__) . '/data/tools.php';
|
require_once dirname(__FILE__) . '/data/tools.php';
|
||||||
require_once dirname(__FILE__) . '/data/hosting-providers.php';
|
require_once dirname(__FILE__) . '/data/hosting-providers.php';
|
||||||
require_once dirname(__FILE__) . '/data/recommended-plugins.php';
|
require_once dirname(__FILE__) . '/data/recommended-plugins.php';
|
||||||
|
|
||||||
// Include manager classes
|
// Include manager classes - each handles a specific plugin functionality area
|
||||||
require_once dirname(__FILE__) . '/includes/class-plugin-manager.php';
|
require_once dirname(__FILE__) . '/includes/class-plugin-manager.php';
|
||||||
require_once dirname(__FILE__) . '/includes/class-pro-plugins-manager.php';
|
require_once dirname(__FILE__) . '/includes/class-pro-plugins-manager.php';
|
||||||
require_once dirname(__FILE__) . '/includes/class-settings-manager.php';
|
require_once dirname(__FILE__) . '/includes/class-settings-manager.php';
|
||||||
@ -22,7 +23,12 @@ require_once dirname(__FILE__) . '/includes/class-hosting-manager.php';
|
|||||||
require_once dirname(__FILE__) . '/includes/class-recommended-plugins-manager.php';
|
require_once dirname(__FILE__) . '/includes/class-recommended-plugins-manager.php';
|
||||||
require_once dirname(__FILE__) . '/includes/class-admin-manager.php';
|
require_once dirname(__FILE__) . '/includes/class-admin-manager.php';
|
||||||
|
|
||||||
// Initialize the managers
|
/**
|
||||||
|
* Initialize all manager classes
|
||||||
|
*
|
||||||
|
* Each manager is responsible for a specific tab or functionality area
|
||||||
|
* within the plugin's admin interface.
|
||||||
|
*/
|
||||||
WP_Allstars_Plugin_Manager::init();
|
WP_Allstars_Plugin_Manager::init();
|
||||||
WP_Allstars_Pro_Plugins_Manager::init();
|
WP_Allstars_Pro_Plugins_Manager::init();
|
||||||
WP_Allstars_Settings_Manager::init();
|
WP_Allstars_Settings_Manager::init();
|
||||||
@ -31,41 +37,3 @@ WP_Allstars_Theme_Manager::init();
|
|||||||
WP_Allstars_Hosting_Manager::init();
|
WP_Allstars_Hosting_Manager::init();
|
||||||
WP_Allstars_Recommended_Plugins_Manager::init();
|
WP_Allstars_Recommended_Plugins_Manager::init();
|
||||||
WP_Allstars_Admin_Manager::init();
|
WP_Allstars_Admin_Manager::init();
|
||||||
|
|
||||||
// Remove the old plugins API filter since we're handling everything in the AJAX endpoint
|
|
||||||
remove_filter('plugins_api_result', 'wp_allstars_plugins_api_result');
|
|
||||||
|
|
||||||
// Add menu item - now handled by WP_Allstars_Admin_Manager class, but kept for backward compatibility
|
|
||||||
function wp_allstars_admin_menu() {
|
|
||||||
// This function now redirects to the Admin Manager class
|
|
||||||
// Kept for backward compatibility
|
|
||||||
WP_Allstars_Admin_Manager::register_admin_menu();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register settings - now handled by WP_Allstars_Admin_Manager class, but kept for backward compatibility
|
|
||||||
function wp_allstars_register_settings() {
|
|
||||||
// This function now redirects to the Admin Manager class
|
|
||||||
// Kept for backward compatibility
|
|
||||||
WP_Allstars_Admin_Manager::register_settings();
|
|
||||||
}
|
|
||||||
|
|
||||||
// AJAX handler for settings - now handled by WP_Allstars_Admin_Manager class, but kept for backward compatibility
|
|
||||||
function wp_allstars_update_option() {
|
|
||||||
// This function now redirects to the Admin Manager class
|
|
||||||
// Kept for backward compatibility
|
|
||||||
WP_Allstars_Admin_Manager::update_option();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register settings page HTML - now handled by WP_Allstars_Admin_Manager class, but kept for backward compatibility
|
|
||||||
function wp_allstars_settings_page() {
|
|
||||||
// This function now redirects to the Admin Manager class
|
|
||||||
// Kept for backward compatibility
|
|
||||||
WP_Allstars_Admin_Manager::render_settings_page();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enqueue admin scripts and styles - now handled by WP_Allstars_Admin_Manager class, but kept for backward compatibility
|
|
||||||
function wp_allstars_admin_enqueue_scripts($hook) {
|
|
||||||
// This function now redirects to the Admin Manager class
|
|
||||||
// Kept for backward compatibility
|
|
||||||
WP_Allstars_Admin_Manager::enqueue_scripts($hook);
|
|
||||||
}
|
|
@ -1,5 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
|
* WP ALLSTARS Plugin
|
||||||
|
*
|
||||||
|
* A comprehensive WordPress optimization and management tool designed to enhance
|
||||||
|
* site performance, improve workflow, and provide recommendations for plugins and hosting.
|
||||||
|
*
|
||||||
|
* @package WP_ALLSTARS
|
||||||
|
* @version v0.2.0
|
||||||
|
*
|
||||||
* Plugin Name: WP ALLSTARS Plugin
|
* Plugin Name: WP ALLSTARS Plugin
|
||||||
* Plugin URI: https://www.wpallstars.com
|
* Plugin URI: https://www.wpallstars.com
|
||||||
* Description: WP ALLSTARS Plugin for WordPress. Speed Matters.
|
* Description: WP ALLSTARS Plugin for WordPress. Speed Matters.
|
||||||
@ -19,79 +27,89 @@ if ( ! defined( 'WPINC' ) ) {
|
|||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define plugin version - extract from plugin header
|
/**
|
||||||
|
* Define plugin version from the file header
|
||||||
|
*/
|
||||||
if (!function_exists('get_plugin_data')) {
|
if (!function_exists('get_plugin_data')) {
|
||||||
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define the version constant - first try get_plugin_data() if available,
|
|
||||||
// otherwise fall back to direct string extraction
|
|
||||||
if (function_exists('get_plugin_data')) {
|
|
||||||
$plugin_data = get_plugin_data(__FILE__, false, false);
|
$plugin_data = get_plugin_data(__FILE__, false, false);
|
||||||
define('WP_ALLSTARS_VERSION', $plugin_data['Version']);
|
define('WP_ALLSTARS_VERSION', $plugin_data['Version']);
|
||||||
} else {
|
|
||||||
// Manual extraction as fallback
|
|
||||||
$plugin_file = file_get_contents(__FILE__);
|
|
||||||
preg_match('/Version:\s*([^\s]+)/i', $plugin_file, $matches);
|
|
||||||
define('WP_ALLSTARS_VERSION', isset($matches[1]) ? $matches[1] : '0.1.0 (Beta)');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Activation hook
|
/**
|
||||||
|
* Plugin activation hook
|
||||||
|
*
|
||||||
|
* Called when the plugin is activated.
|
||||||
|
* Initialize plugin settings and defaults here.
|
||||||
|
*/
|
||||||
function wp_allstars_activate() {
|
function wp_allstars_activate() {
|
||||||
// Add activation logic later if needed
|
// Create initial plugin settings
|
||||||
|
// Register cron jobs if needed
|
||||||
|
// Initialize defaults
|
||||||
}
|
}
|
||||||
register_activation_hook(__FILE__, 'wp_allstars_activate');
|
register_activation_hook(__FILE__, 'wp_allstars_activate');
|
||||||
|
|
||||||
// Load core functionality
|
/**
|
||||||
|
* Load core plugin components
|
||||||
|
*/
|
||||||
require_once plugin_dir_path(__FILE__) . 'includes/class-wp-allstars-auto-upload.php';
|
require_once plugin_dir_path(__FILE__) . 'includes/class-wp-allstars-auto-upload.php';
|
||||||
|
|
||||||
// Load admin UI and configurations
|
/**
|
||||||
|
* Load admin-specific components
|
||||||
|
*/
|
||||||
if (is_admin()) {
|
if (is_admin()) {
|
||||||
require_once plugin_dir_path( __FILE__ ) . 'admin/pro-plugins-config.php';
|
|
||||||
require_once plugin_dir_path(__FILE__) . 'admin/settings.php';
|
require_once plugin_dir_path(__FILE__) . 'admin/settings.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function is not needed as we're localizing in wp_allstars_admin_assets
|
|
||||||
// function wp_allstars_localize_script() {
|
|
||||||
// wp_localize_script( 'wp-allstars-admin', 'wpAllstars', [
|
|
||||||
// 'ajaxurl' => admin_url( 'admin-ajax.php' ),
|
|
||||||
// 'nonce' => wp_create_nonce( 'wp-allstars-nonce' )
|
|
||||||
// ] );
|
|
||||||
// }
|
|
||||||
// add_action( 'admin_enqueue_scripts', 'wp_allstars_localize_script' );
|
|
||||||
|
|
||||||
// Admin assets
|
|
||||||
|
/**
|
||||||
|
* Enqueue admin assets
|
||||||
|
*
|
||||||
|
* Loads the CSS and JavaScript files for the admin interface.
|
||||||
|
* Localizes the JavaScript with necessary data for AJAX operations.
|
||||||
|
*/
|
||||||
function wp_allstars_admin_assets() {
|
function wp_allstars_admin_assets() {
|
||||||
// Enqueue styles
|
// Only load assets on plugin pages to avoid conflicts
|
||||||
|
$screen = get_current_screen();
|
||||||
|
if (!isset($screen->id) || strpos($screen->id, 'wp-allstars') === false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enqueue CSS
|
||||||
wp_enqueue_style(
|
wp_enqueue_style(
|
||||||
'wp-allstars-admin',
|
'wp-allstars-admin',
|
||||||
plugins_url('admin/css/wp-allstars-admin.css', __FILE__),
|
plugins_url('admin/css/wp-allstars-admin.css', __FILE__),
|
||||||
array(),
|
[],
|
||||||
WP_ALLSTARS_VERSION
|
WP_ALLSTARS_VERSION
|
||||||
);
|
);
|
||||||
|
|
||||||
// Enqueue script
|
// Enqueue WordPress updates script for theme/plugin installation
|
||||||
// Enqueue WordPress updates script for theme installation
|
|
||||||
wp_enqueue_script('updates');
|
wp_enqueue_script('updates');
|
||||||
|
|
||||||
|
// Enqueue main admin script
|
||||||
wp_enqueue_script(
|
wp_enqueue_script(
|
||||||
'wp-allstars-admin',
|
'wp-allstars-admin',
|
||||||
plugins_url('admin/js/wp-allstars-admin.js', __FILE__),
|
plugins_url('admin/js/wp-allstars-admin.js', __FILE__),
|
||||||
array('jquery', 'updates'),
|
['jquery', 'updates'],
|
||||||
WP_ALLSTARS_VERSION,
|
WP_ALLSTARS_VERSION,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
// Localize script for AJAX
|
// Localize script with AJAX and security data
|
||||||
$ajax_data = array(
|
$ajax_data = [
|
||||||
'ajaxurl' => admin_url('admin-ajax.php'),
|
'ajaxurl' => admin_url('admin-ajax.php'),
|
||||||
'adminUrl' => admin_url(),
|
'adminUrl' => admin_url(),
|
||||||
'nonce' => wp_create_nonce('wp-allstars-nonce'),
|
'nonce' => wp_create_nonce('wp-allstars-nonce'),
|
||||||
'updateNonce' => wp_create_nonce('updates')
|
'updateNonce' => wp_create_nonce('updates')
|
||||||
);
|
];
|
||||||
|
|
||||||
wp_localize_script('wp-allstars-admin', 'wpAllstars', $ajax_data);
|
wp_localize_script('wp-allstars-admin', 'wpAllstars', $ajax_data);
|
||||||
}
|
}
|
||||||
add_action('admin_enqueue_scripts', 'wp_allstars_admin_assets');
|
add_action('admin_enqueue_scripts', 'wp_allstars_admin_assets');
|
||||||
|
|
||||||
// Initialize classes
|
/**
|
||||||
|
* Initialize core plugin classes
|
||||||
|
*/
|
||||||
$wp_allstars_auto_upload = new WP_Allstars_Auto_Upload();
|
$wp_allstars_auto_upload = new WP_Allstars_Auto_Upload();
|
Reference in New Issue
Block a user