diff --git a/CHANGELOG.md b/CHANGELOG.md index a802ad9..acdad6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.1.1] - 2026-02-02 + +### Changed + +- Reorganized settings page with tabbed interface (License, Metrics, Help tabs) +- Moved Prometheus configuration help to dedicated Help tab +- Separated static and runtime metrics in settings with descriptions +- Added admin CSS for improved tab styling + +### Added + +- New Help tab with endpoint information, curl examples, and metrics reference table +- Custom code examples section in Help tab + ## [0.1.0] - 2026-02-02 ### Added diff --git a/assets/css/admin.css b/assets/css/admin.css new file mode 100644 index 0000000..6f56f3d --- /dev/null +++ b/assets/css/admin.css @@ -0,0 +1,47 @@ +/** + * WP Prometheus Admin Styles + * + * @package WP_Prometheus + */ + +/* Tab content styling */ +.wp-prometheus-tab-content { + margin-top: 20px; +} + +/* License status box */ +.wp-prometheus-license-status { + margin: 15px 0; +} + +/* Help tab code blocks */ +.wp-prometheus-tab-content pre { + background: #f1f1f1; + padding: 15px; + overflow-x: auto; + margin: 15px 0; + border-radius: 3px; + border: 1px solid #ddd; +} + +/* Help tab tables */ +.wp-prometheus-tab-content .widefat { + margin: 15px 0; +} + +.wp-prometheus-tab-content .widefat code { + background: none; + padding: 0; +} + +/* Metrics fieldset */ +.wp-prometheus-tab-content fieldset p strong { + display: block; + margin-bottom: 8px; + font-size: 14px; +} + +/* Form table adjustments for tabs */ +.wp-prometheus-tab-content .form-table { + margin-top: 10px; +} diff --git a/src/Admin/Settings.php b/src/Admin/Settings.php index b0dc424..c86a550 100644 --- a/src/Admin/Settings.php +++ b/src/Admin/Settings.php @@ -21,15 +21,38 @@ if ( ! defined( 'ABSPATH' ) ) { */ class Settings { + /** + * Available tabs. + * + * @var array + */ + private array $tabs = array(); + /** * Constructor. */ public function __construct() { + $this->tabs = array( + 'license' => __( 'License', 'wp-prometheus' ), + 'metrics' => __( 'Metrics', 'wp-prometheus' ), + 'help' => __( 'Help', 'wp-prometheus' ), + ); + add_action( 'admin_menu', array( $this, 'add_settings_page' ) ); add_action( 'admin_init', array( $this, 'register_settings' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); } + /** + * Get current tab. + * + * @return string + */ + private function get_current_tab(): string { + $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'license'; + return array_key_exists( $tab, $this->tabs ) ? $tab : 'license'; + } + /** * Add settings page to admin menu. * @@ -51,56 +74,48 @@ class Settings { * @return void */ public function register_settings(): void { - // License settings section. - add_settings_section( - 'wp_prometheus_license_section', - __( 'License Settings', 'wp-prometheus' ), - array( $this, 'render_license_section' ), - 'wp-prometheus' - ); + // Register settings for metrics tab. + register_setting( 'wp_prometheus_metrics_settings', 'wp_prometheus_auth_token', array( + 'type' => 'string', + 'sanitize_callback' => 'sanitize_text_field', + ) ); + + register_setting( 'wp_prometheus_metrics_settings', 'wp_prometheus_enabled_metrics', array( + 'type' => 'array', + 'sanitize_callback' => array( $this, 'sanitize_metrics' ), + ) ); // Auth token section. add_settings_section( 'wp_prometheus_auth_section', __( 'Authentication', 'wp-prometheus' ), array( $this, 'render_auth_section' ), - 'wp-prometheus' + 'wp-prometheus-metrics' ); // Metrics section. add_settings_section( 'wp_prometheus_metrics_section', - __( 'Default Metrics', 'wp-prometheus' ), + __( 'Enabled Metrics', 'wp-prometheus' ), array( $this, 'render_metrics_section' ), - 'wp-prometheus' + 'wp-prometheus-metrics' ); - // Register settings. - register_setting( 'wp_prometheus_settings', 'wp_prometheus_auth_token', array( - 'type' => 'string', - 'sanitize_callback' => 'sanitize_text_field', - ) ); - - register_setting( 'wp_prometheus_settings', 'wp_prometheus_enabled_metrics', array( - 'type' => 'array', - 'sanitize_callback' => array( $this, 'sanitize_metrics' ), - ) ); - // Auth token field. add_settings_field( 'wp_prometheus_auth_token', __( 'Auth Token', 'wp-prometheus' ), array( $this, 'render_auth_token_field' ), - 'wp-prometheus', + 'wp-prometheus-metrics', 'wp_prometheus_auth_section' ); // Enabled metrics field. add_settings_field( 'wp_prometheus_enabled_metrics', - __( 'Enabled Metrics', 'wp-prometheus' ), + __( 'Select Metrics', 'wp-prometheus' ), array( $this, 'render_enabled_metrics_field' ), - 'wp-prometheus', + 'wp-prometheus-metrics', 'wp_prometheus_metrics_section' ); } @@ -116,6 +131,13 @@ class Settings { return; } + wp_enqueue_style( + 'wp-prometheus-admin', + WP_PROMETHEUS_URL . 'assets/css/admin.css', + array(), + WP_PROMETHEUS_VERSION + ); + wp_enqueue_script( 'wp-prometheus-admin', WP_PROMETHEUS_URL . 'assets/js/admin.js', @@ -140,8 +162,10 @@ class Settings { return; } + $current_tab = $this->get_current_tab(); + // Handle license settings save. - if ( isset( $_POST['wp_prometheus_license_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_prometheus_license_nonce'] ), 'wp_prometheus_save_license' ) ) { + if ( 'license' === $current_tab && isset( $_POST['wp_prometheus_license_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_prometheus_license_nonce'] ), 'wp_prometheus_save_license' ) ) { LicenseManager::save_settings( array( 'license_key' => isset( $_POST['license_key'] ) ? sanitize_text_field( wp_unslash( $_POST['license_key'] ) ) : '', 'server_url' => isset( $_POST['license_server_url'] ) ? esc_url_raw( wp_unslash( $_POST['license_server_url'] ) ) : '', @@ -154,27 +178,64 @@ class Settings {

- render_license_form(); ?> + render_tabs( $current_tab ); ?> -
+
render_license_tab(); + break; + case 'metrics': + $this->render_metrics_tab(); + break; + case 'help': + $this->render_help_tab(); + break; + } ?> - - - render_endpoint_info(); ?> +
+ + -
+

@@ -233,7 +294,7 @@ class Settings {
- +