Repository navigation
Expand file tree
/
Copy pathperfbase.php
More file actions
134 lines (122 loc) · 4.75 KB
/
Copy pathperfbase.php
File metadata and controls
134 lines (122 loc) · 4.75 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
<?php
/**
* Plugin Name: Perfbase
* Plugin URI: https://perfbase.com/integrations/wordpress/
* Description: WordPress integration for the Perfbase APM platform. Provides comprehensive performance monitoring and profiling for WordPress applications.
* Version: 0.0.0-dev
* Requires at least: 5.3
* Tested up to: 7.1
* Requires PHP: 7.4
* Author: Perfbase Team
* Author URI: https://perfbase.com
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: perfbase
*
* @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', '0.0.0-dev');
define('PERFBASE_MIN_PHP_VERSION', '7.4');
define('PERFBASE_MIN_WP_VERSION', '5.3');
// 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>';
printf(
/* translators: 1: required PHP version, 2: current PHP version. */
esc_html__('Perfbase requires PHP version %1$s or higher. You are running PHP %2$s.', 'perfbase'),
esc_html(PERFBASE_MIN_PHP_VERSION),
esc_html(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>';
printf(
/* translators: 1: required WordPress version, 2: current WordPress version. */
esc_html__('Perfbase requires WordPress version %1$s or higher. You are running WordPress %2$s.', 'perfbase'),
esc_html(PERFBASE_MIN_WP_VERSION),
esc_html($GLOBALS['wp_version'])
);
echo '</p></div>';
});
return;
}
// Load Composer autoloader if available
$perfbase_autoloader = PERFBASE_PLUGIN_DIR . 'vendor/autoload.php';
if (file_exists($perfbase_autoloader)) {
require_once $perfbase_autoloader;
}
/**
* Initialize the plugin
*
* @return void
*/
function perfbase_init() {
try {
$plugin = new Perfbase\WordPress\PerfbasePlugin();
$plugin->init();
} catch (\Throwable $e) {
// Throwable, not Exception: a missing or broken vendor/ directory
// surfaces as an Error, and that must not take the site down.
add_action('admin_notices', function() use ($e) {
echo '<div class="notice notice-error"><p>';
printf(
/* translators: %s: initialization error message. */
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(
/* translators: 1: required PHP version, 2: current PHP version. */
esc_html__('Perfbase requires PHP version %1$s or higher. You are running PHP %2$s.', 'perfbase'),
esc_html(PERFBASE_MIN_PHP_VERSION),
esc_html(PHP_VERSION)
));
}
if (version_compare($GLOBALS['wp_version'], PERFBASE_MIN_WP_VERSION, '<')) {
deactivate_plugins(plugin_basename(__FILE__));
wp_die(sprintf(
/* translators: 1: required WordPress version, 2: current WordPress version. */
esc_html__('Perfbase requires WordPress version %1$s or higher. You are running WordPress %2$s.', 'perfbase'),
esc_html(PERFBASE_MIN_WP_VERSION),
esc_html($GLOBALS['wp_version'])
));
}
// Create default options. Activation must not fail when the plugin's
// classes cannot be loaded: the settings fall back to the built-in
// defaults, and perfbase_init() reports the reason in the admin area.
if (!class_exists(Perfbase\WordPress\Helpers\ConfigManager::class)) {
return;
}
$defaults = (new Perfbase\WordPress\Helpers\ConfigManager())->getDefaultConfig();
add_option('perfbase_settings', $defaults);
}
register_activation_hook(__FILE__, 'perfbase_activate');
// Uninstall handling lives in uninstall.php (loaded by WordPress when the
// plugin is deleted). Using uninstall.php instead of register_uninstall_hook
// keeps the callback discoverable and lets us be multisite-aware.