-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperfbase.php
More file actions
138 lines (125 loc) · 4.04 KB
/
perfbase.php
File metadata and controls
138 lines (125 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* Plugin Name: Perfbase
* Plugin URI: https://perfbase.com
* Description: WordPress integration for the Perfbase APM platform. Provides comprehensive performance monitoring and profiling for WordPress applications.
* Version: 1.0.0
* Requires at least: 5.0
* Requires PHP: 7.4
* Author: Perfbase Team
* Author URI: https://perfbase.com
* License: Apache-2.0
* License URI: https://opensource.org/licenses/Apache-2.0
* Text Domain: perfbase
* Domain Path: /languages
* Network: true
*
* @package Perfbase\WordPress
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
// Define plugin constants
define('PERFBASE_PLUGIN_FILE', __FILE__);
define('PERFBASE_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('PERFBASE_PLUGIN_URL', plugin_dir_url(__FILE__));
define('PERFBASE_PLUGIN_VERSION', '1.0.0');
define('PERFBASE_MIN_PHP_VERSION', '7.4');
define('PERFBASE_MIN_WP_VERSION', '5.0');
// Check PHP version compatibility
if (version_compare(PHP_VERSION, PERFBASE_MIN_PHP_VERSION, '<')) {
add_action('admin_notices', function() {
echo '<div class="notice notice-error"><p>';
echo sprintf(
esc_html__('Perfbase requires PHP version %s or higher. You are running PHP %s.', 'perfbase'),
PERFBASE_MIN_PHP_VERSION,
PHP_VERSION
);
echo '</p></div>';
});
return;
}
// Check WordPress version compatibility
if (version_compare($GLOBALS['wp_version'], PERFBASE_MIN_WP_VERSION, '<')) {
add_action('admin_notices', function() {
echo '<div class="notice notice-error"><p>';
echo sprintf(
esc_html__('Perfbase requires WordPress version %s or higher. You are running WordPress %s.', 'perfbase'),
PERFBASE_MIN_WP_VERSION,
$GLOBALS['wp_version']
);
echo '</p></div>';
});
return;
}
// Load Composer autoloader if available
$autoloader = PERFBASE_PLUGIN_DIR . 'vendor/autoload.php';
if (file_exists($autoloader)) {
require_once $autoloader;
}
/**
* Initialize the plugin
*
* @return void
*/
function perfbase_init() {
try {
$plugin = new Perfbase\WordPress\PerfbasePlugin();
$plugin->init();
} catch (Exception $e) {
add_action('admin_notices', function() use ($e) {
echo '<div class="notice notice-error"><p>';
echo sprintf(
esc_html__('Perfbase initialization failed: %s', 'perfbase'),
esc_html($e->getMessage())
);
echo '</p></div>';
});
}
}
// Initialize the plugin
add_action('plugins_loaded', 'perfbase_init');
/**
* Plugin activation hook
*/
function perfbase_activate() {
// Check system requirements during activation
if (version_compare(PHP_VERSION, PERFBASE_MIN_PHP_VERSION, '<')) {
deactivate_plugins(plugin_basename(__FILE__));
wp_die(sprintf(
esc_html__('Perfbase requires PHP version %s or higher. You are running PHP %s.', 'perfbase'),
PERFBASE_MIN_PHP_VERSION,
PHP_VERSION
));
}
if (version_compare($GLOBALS['wp_version'], PERFBASE_MIN_WP_VERSION, '<')) {
deactivate_plugins(plugin_basename(__FILE__));
wp_die(sprintf(
esc_html__('Perfbase requires WordPress version %s or higher. You are running WordPress %s.', 'perfbase'),
PERFBASE_MIN_WP_VERSION,
$GLOBALS['wp_version']
));
}
// Create default options
$defaults = (new Perfbase\WordPress\Helpers\ConfigManager())->getDefaultConfig();
add_option('perfbase_settings', $defaults);
}
register_activation_hook(__FILE__, 'perfbase_activate');
/**
* Plugin deactivation hook
*/
function perfbase_deactivate() {
// No-op: plugin does not manage rewrite rules.
}
register_deactivation_hook(__FILE__, 'perfbase_deactivate');
/**
* Plugin uninstall hook
*/
function perfbase_uninstall() {
// Remove plugin options
delete_option('perfbase_settings');
// Clean up any cached data
wp_cache_delete('perfbase_config');
}
register_uninstall_hook(__FILE__, 'perfbase_uninstall');