You've already forked wp-prometheus
All checks were successful
Create Release Package / build-release (push) Successful in 59s
- Custom Metrics Builder with admin UI for gauge metrics - Support for static values and WordPress option-based values - JSON-based export/import with skip/overwrite/rename modes - Three Grafana dashboard templates (overview, runtime, WooCommerce) - New tabs: Custom Metrics and Dashboards - Reset runtime metrics button Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
106 lines
2.7 KiB
PHP
106 lines
2.7 KiB
PHP
<?php
|
|
/**
|
|
* Plugin installer class.
|
|
*
|
|
* @package WP_Prometheus
|
|
*/
|
|
|
|
namespace Magdev\WpPrometheus;
|
|
|
|
// Prevent direct file access.
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Installer class.
|
|
*
|
|
* Handles plugin activation, deactivation, and uninstallation.
|
|
*/
|
|
final class Installer {
|
|
|
|
/**
|
|
* Plugin activation.
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function activate(): void {
|
|
// Set default options.
|
|
self::set_default_options();
|
|
|
|
// Flush rewrite rules for the metrics endpoint.
|
|
flush_rewrite_rules();
|
|
|
|
// Store activation time for reference.
|
|
update_option( 'wp_prometheus_activated', time() );
|
|
}
|
|
|
|
/**
|
|
* Plugin deactivation.
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function deactivate(): void {
|
|
// Flush rewrite rules.
|
|
flush_rewrite_rules();
|
|
}
|
|
|
|
/**
|
|
* Plugin uninstallation.
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function uninstall(): void {
|
|
// Remove all plugin options.
|
|
$options = array(
|
|
'wp_prometheus_activated',
|
|
'wp_prometheus_license_key',
|
|
'wp_prometheus_license_server_url',
|
|
'wp_prometheus_license_server_secret',
|
|
'wp_prometheus_license_status',
|
|
'wp_prometheus_license_data',
|
|
'wp_prometheus_license_last_check',
|
|
'wp_prometheus_auth_token',
|
|
'wp_prometheus_enable_default_metrics',
|
|
'wp_prometheus_enabled_metrics',
|
|
'wp_prometheus_runtime_metrics',
|
|
'wp_prometheus_custom_metrics',
|
|
);
|
|
|
|
foreach ( $options as $option ) {
|
|
delete_option( $option );
|
|
}
|
|
|
|
// Remove transients.
|
|
delete_transient( 'wp_prometheus_license_check' );
|
|
}
|
|
|
|
/**
|
|
* Set default plugin options.
|
|
*
|
|
* @return void
|
|
*/
|
|
private static function set_default_options(): void {
|
|
// Generate a random auth token if not set.
|
|
if ( ! get_option( 'wp_prometheus_auth_token' ) ) {
|
|
update_option( 'wp_prometheus_auth_token', wp_generate_password( 32, false ) );
|
|
}
|
|
|
|
// Enable default metrics by default.
|
|
if ( false === get_option( 'wp_prometheus_enable_default_metrics' ) ) {
|
|
update_option( 'wp_prometheus_enable_default_metrics', 1 );
|
|
}
|
|
|
|
// Default enabled metrics.
|
|
if ( false === get_option( 'wp_prometheus_enabled_metrics' ) ) {
|
|
update_option( 'wp_prometheus_enabled_metrics', array(
|
|
'wordpress_info',
|
|
'wordpress_users_total',
|
|
'wordpress_posts_total',
|
|
'wordpress_comments_total',
|
|
'wordpress_plugins_total',
|
|
) );
|
|
}
|
|
}
|
|
}
|