PluginProbe
Memory Limit Manager / 1.0.2
Memory Limit Manager v1.0.2
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4
memory-limit-manager / memory-limit-manager.php

memory-limit-manager.php in Memory Limit Manager 1.0.2, at memory-limit-manager.php

159 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Memory Limit Manager
4 * Plugin URI: https://wordpress.org/plugins/memory-limit-manager/
5 * Description: Easily manage memory limits (WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT) through a beautiful admin interface with advanced conflict detection.
6 * Version: 1.0.2
7 * Requires at least: 6.0
8 * Requires PHP: 7.4
9 * Tested up to: 7.1
10 * Author: Muhammad Shakeel
11 * Author URI: https://muhammadshakeel.com/
12 * License: GPL v2 or later
13 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
14 * Text Domain: memory-limit-manager
15 * Domain Path: /languages
16 */
17
18 // Exit if accessed directly
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit;
21 }
22
23 // Check minimum requirements
24 function memory_limit_manager_check_requirements() {
25 $wp_version = get_bloginfo( 'version' );
26 $php_version = phpversion();
27
28 $errors = array();
29
30 // Check WordPress version
31 if ( version_compare( $wp_version, '6.0', '<' ) ) {
32 $errors[] = sprintf(
33 /* translators: %s: Current version */
34 __( 'Memory Limit Manager requires version 6.0 or higher. You are running version %s.', 'memory-limit-manager' ),
35 $wp_version
36 );
37 }
38
39 // Check PHP version
40 if ( version_compare( $php_version, '7.4', '<' ) ) {
41 $errors[] = sprintf(
42 /* translators: %s: Current PHP version */
43 __( 'Memory Limit Manager requires PHP 7.4 or higher. You are running PHP %s.', 'memory-limit-manager' ),
44 $php_version
45 );
46 }
47
48 if ( ! empty( $errors ) ) {
49 deactivate_plugins( plugin_basename( __FILE__ ) );
50 wp_die(
51 '<h1>' . esc_html__( 'Plugin Activation Error', 'memory-limit-manager' ) . '</h1>' .
52 '<p>' . implode( '</p><p>', array_map( 'esc_html', $errors ) ) . '</p>' .
53 '<p><a href="' . esc_url( admin_url( 'plugins.php' ) ) . '">' . esc_html__( '&larr; Back to Plugins', 'memory-limit-manager' ) . '</a></p>',
54 esc_html__( 'Plugin Activation Error', 'memory-limit-manager' ),
55 array( 'back_link' => true )
56 );
57 }
58 }
59 register_activation_hook( __FILE__, 'memory_limit_manager_check_requirements' );
60
61 // Define plugin constants
62 define( 'MEMORY_MANAGER_WP_VERSION', '1.0.2' );
63 define( 'MEMORY_MANAGER_WP_PLUGIN_FILE', __FILE__ );
64 define( 'MEMORY_MANAGER_WP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
65 define( 'MEMORY_MANAGER_WP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
66
67 /**
68 * Main plugin class
69 */
70 class Memory_Manager_WP {
71
72 /**
73 * Instance of this class
74 */
75 private static $instance = null;
76
77 /**
78 * Get instance of this class
79 */
80 public static function get_instance() {
81 if ( null === self::$instance ) {
82 self::$instance = new self();
83 }
84 return self::$instance;
85 }
86
87 /**
88 * Constructor
89 */
90 private function __construct() {
91 $this->load_dependencies();
92 $this->init_hooks();
93 }
94
95 /**
96 * Load required files
97 */
98 private function load_dependencies() {
99 require_once MEMORY_MANAGER_WP_PLUGIN_DIR . 'includes/class-config-handler.php';
100 require_once MEMORY_MANAGER_WP_PLUGIN_DIR . 'includes/class-admin.php';
101 }
102
103 /**
104 * Initialize hooks
105 */
106 private function init_hooks() {
107 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) );
108
109 // Initialize admin
110 if ( is_admin() ) {
111 Memory_Manager_WP_Admin::get_instance();
112 }
113 }
114
115 /**
116 * Enqueue admin assets
117 */
118 public function enqueue_admin_assets( $hook ) {
119 // Only load on our plugin page
120 if ( 'settings_page_memory-limit-manager' !== $hook ) {
121 return;
122 }
123
124 wp_enqueue_style(
125 'memory-limit-manager-admin',
126 MEMORY_MANAGER_WP_PLUGIN_URL . 'assets/css/admin.css',
127 array(),
128 MEMORY_MANAGER_WP_VERSION
129 );
130
131 wp_enqueue_script(
132 'memory-limit-manager-admin',
133 MEMORY_MANAGER_WP_PLUGIN_URL . 'assets/js/admin.js',
134 array( 'jquery' ),
135 MEMORY_MANAGER_WP_VERSION,
136 true
137 );
138
139 wp_localize_script(
140 'memory-limit-manager-admin',
141 'memoryManagerWP',
142 array(
143 'ajaxurl' => admin_url( 'admin-ajax.php' ),
144 'nonce' => wp_create_nonce( 'memory_limit_manager_nonce' ),
145 )
146 );
147 }
148 }
149
150 /**
151 * Initialize the plugin
152 */
153 function memory_limit_manager_init() {
154 return Memory_Manager_WP::get_instance();
155 }
156
157 // Start the plugin
158 memory_limit_manager_init();
159