From 1e8ae1bb70449d8f01d216d65bb119a6969906aa Mon Sep 17 00:00:00 2001 From: Joshua Abenazer Date: Thu, 18 Jul 2024 18:07:54 +0530 Subject: [PATCH 1/2] #161 - Allow defining support monitor constants to override settings. --- includes/classes/SupportMonitor/Monitor.php | 55 +++++++++++++++++---- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/includes/classes/SupportMonitor/Monitor.php b/includes/classes/SupportMonitor/Monitor.php index 60c380b..398e847 100644 --- a/includes/classes/SupportMonitor/Monitor.php +++ b/includes/classes/SupportMonitor/Monitor.php @@ -26,9 +26,11 @@ class Monitor { public function setup() { if ( TENUP_EXPERIENCE_IS_NETWORK ) { + add_filter( 'site_option_tenup_support_monitor_settings', [ $this, 'handle_settings' ] ); add_action( 'wpmu_options', [ $this, 'ms_settings' ] ); add_action( 'admin_init', [ $this, 'ms_save_settings' ] ); } else { + add_filter( 'option_tenup_support_monitor_settings', [ $this, 'handle_settings' ] ); add_action( 'admin_init', [ $this, 'register_settings' ] ); } @@ -89,7 +91,6 @@ public function ms_save_settings() { * @since 1.7 */ public function ms_settings() { - $setting = $this->get_setting(); ?>

@@ -100,21 +101,20 @@ public function ms_settings() { - type="radio" id="tenup_enable_support_monitor_yes" value="yes">
- type="radio" id="tenup_enable_support_monitor_no" value="no"> + enable_field(); ?> - + api_key_field(); ?> is_debug_enabled() ) : ?> - + api_server_field(); ?> @@ -140,7 +140,7 @@ public function get_setting( $setting_key = null ) { $settings = ( TENUP_EXPERIENCE_IS_NETWORK ) ? get_site_option( 'tenup_support_monitor_settings', [] ) : get_option( 'tenup_support_monitor_settings', [] ); $settings = wp_parse_args( $settings, $defaults ); - if ( ! Debug::instance()->is_debug_enabled() ) { + if ( ! Debug::instance()->is_debug_enabled() && ! defined( 'SUPPORT_MONITOR_SERVER_URL' ) ) { $settings['server_url'] = 'https://supportmonitor.10up.com'; } @@ -205,6 +205,26 @@ public function setting_section_description() { $setting ) { $settings[ $key ] = sanitize_text_field( $setting ); } @@ -276,8 +311,8 @@ public function sanitize_settings( $settings ) { public function enable_field() { $value = $this->get_setting( 'enable_support_monitor' ); ?> - type="radio" id="tenup_enable_support_monitor_yes" value="yes">
- type="radio" id="tenup_enable_support_monitor_no" value="no"> + type="radio" id="tenup_enable_support_monitor_yes" value="yes">
+ type="radio" id="tenup_enable_support_monitor_no" value="no"> get_setting( 'api_key' ); ?> - + class="regular-text"> get_setting( 'server_url' ); ?> - + class="regular-text"> Date: Thu, 18 Jul 2024 18:25:16 +0530 Subject: [PATCH 2/2] #161 - Update readme with new support monitor constants. --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 3a24151..055c674 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,9 @@ There are 2 filters available here: - `TENUPSSO_DISABLE` - Define this as `true` to force disable SSO. - `TENUPSSO_DISALLOW_ALL_DIRECT_LOGIN` - Define this as `true` to disable username/password log ins completely. +- `SUPPORT_MONITOR_ENABLE` - Overrides the settings to enable Support Monitor. Possible values `yes` and `no`. +- `SUPPORT_MONITOR_API_KEY` - Overrides the settings to Support Monitor API key. +- `SUPPORT_MONITOR_SERVER_URL` - Overrides the settings to Support Monitor server url. ### Activity Log