You've already forked wp-prometheus
Initial plugin setup (v0.0.1)
Some checks failed
Create Release Package / build-release (push) Failing after 48s
Some checks failed
Create Release Package / build-release (push) Failing after 48s
- Create initial WordPress plugin structure - Add Prometheus metrics collector with default metrics - Implement authenticated /metrics endpoint with Bearer token - Add license management integration - Create admin settings page under Settings > Metrics - Set up Gitea CI/CD pipeline for automated releases - Add extensibility via wp_prometheus_collect_metrics hook Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
103
src/Installer.php
Normal file
103
src/Installer.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?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',
|
||||
);
|
||||
|
||||
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',
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user