Code cleanup: Improved documentation and removed backward compatibility code
This commit is contained in:
@ -1,5 +1,13 @@
|
||||
<?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 URI: https://www.wpallstars.com
|
||||
* Description: WP ALLSTARS Plugin for WordPress. Speed Matters.
|
||||
@ -15,83 +23,93 @@
|
||||
*/
|
||||
|
||||
// If this file is called directly, abort.
|
||||
if ( ! defined( 'WPINC' ) ) {
|
||||
if (!defined('WPINC')) {
|
||||
die;
|
||||
}
|
||||
|
||||
// Define plugin version - extract from plugin header
|
||||
/**
|
||||
* Define plugin version from the file header
|
||||
*/
|
||||
if (!function_exists('get_plugin_data')) {
|
||||
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);
|
||||
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)');
|
||||
}
|
||||
$plugin_data = get_plugin_data(__FILE__, false, false);
|
||||
define('WP_ALLSTARS_VERSION', $plugin_data['Version']);
|
||||
|
||||
// Activation hook
|
||||
/**
|
||||
* Plugin activation hook
|
||||
*
|
||||
* Called when the plugin is activated.
|
||||
* Initialize plugin settings and defaults here.
|
||||
*/
|
||||
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';
|
||||
|
||||
// Load admin UI and configurations
|
||||
if ( is_admin() ) {
|
||||
require_once plugin_dir_path( __FILE__ ) . 'admin/pro-plugins-config.php';
|
||||
require_once plugin_dir_path( __FILE__ ) . 'admin/settings.php';
|
||||
/**
|
||||
* Load admin-specific components
|
||||
*/
|
||||
if (is_admin()) {
|
||||
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() {
|
||||
// Enqueue styles
|
||||
wp_enqueue_style(
|
||||
// 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-allstars-admin',
|
||||
plugins_url( 'admin/css/wp-allstars-admin.css', __FILE__ ),
|
||||
array(),
|
||||
plugins_url('admin/css/wp-allstars-admin.css', __FILE__),
|
||||
[],
|
||||
WP_ALLSTARS_VERSION
|
||||
);
|
||||
|
||||
// Enqueue script
|
||||
// Enqueue WordPress updates script for theme installation
|
||||
// Enqueue WordPress updates script for theme/plugin installation
|
||||
wp_enqueue_script('updates');
|
||||
|
||||
wp_enqueue_script(
|
||||
// Enqueue main admin script
|
||||
wp_enqueue_script(
|
||||
'wp-allstars-admin',
|
||||
plugins_url( 'admin/js/wp-allstars-admin.js', __FILE__ ),
|
||||
array('jquery', 'updates'),
|
||||
plugins_url('admin/js/wp-allstars-admin.js', __FILE__),
|
||||
['jquery', 'updates'],
|
||||
WP_ALLSTARS_VERSION,
|
||||
true
|
||||
true
|
||||
);
|
||||
|
||||
// Localize script for AJAX
|
||||
$ajax_data = array(
|
||||
'ajaxurl' => admin_url( 'admin-ajax.php' ),
|
||||
// Localize script with AJAX and security data
|
||||
$ajax_data = [
|
||||
'ajaxurl' => admin_url('admin-ajax.php'),
|
||||
'adminUrl' => admin_url(),
|
||||
'nonce' => wp_create_nonce( 'wp-allstars-nonce' ),
|
||||
'updateNonce' => wp_create_nonce( 'updates' )
|
||||
);
|
||||
wp_localize_script( 'wp-allstars-admin', 'wpAllstars', $ajax_data );
|
||||
'nonce' => wp_create_nonce('wp-allstars-nonce'),
|
||||
'updateNonce' => wp_create_nonce('updates')
|
||||
];
|
||||
|
||||
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();
|
Reference in New Issue
Block a user