Skip to content

Commit d0f06ee

Browse files
authored
Merge pull request #164 from 10up/feature/161-support-monitor-constants
#161 - Allow defining support monitor constants to override settings.
2 parents e58b1d4 + 80c9716 commit d0f06ee

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ There are 2 filters available here:
107107

108108
- `TENUPSSO_DISABLE` - Define this as `true` to force disable SSO.
109109
- `TENUPSSO_DISALLOW_ALL_DIRECT_LOGIN` - Define this as `true` to disable username/password log ins completely.
110+
- `SUPPORT_MONITOR_ENABLE` - Overrides the settings to enable Support Monitor. Possible values `yes` and `no`.
111+
- `SUPPORT_MONITOR_API_KEY` - Overrides the settings to Support Monitor API key.
112+
- `SUPPORT_MONITOR_SERVER_URL` - Overrides the settings to Support Monitor server url.
110113

111114
### Activity Log
112115

includes/classes/SupportMonitor/Monitor.php

+19-9
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ public function ms_save_settings() {
8888
* @since 1.7
8989
*/
9090
public function ms_settings() {
91-
$setting = $this->get_setting();
9291
?>
9392
<h2><?php esc_html_e( 'Monitor', 'tenup' ); ?></h2>
9493

@@ -99,21 +98,20 @@ public function ms_settings() {
9998
<tr>
10099
<th scope="row"><?php esc_html_e( 'Enable', 'tenup' ); ?></th>
101100
<td>
102-
<input name="tenup_support_monitor_settings[enable_support_monitor]" <?php checked( 'yes', $setting['enable_support_monitor'] ); ?> type="radio" id="tenup_enable_support_monitor_yes" value="yes"> <label for="tenup_enable_support_monitor_yes"><?php esc_html_e( 'Yes', 'tenup' ); ?></label><br>
103-
<input name="tenup_support_monitor_settings[enable_support_monitor]" <?php checked( 'no', $setting['enable_support_monitor'] ); ?> type="radio" id="tenup_enable_support_monitor_no" value="no"> <label for="tenup_enable_support_monitor_no"><?php esc_html_e( 'No', 'tenup' ); ?></label>
101+
<?php $this->enable_field(); ?>
104102
</td>
105103
</tr>
106104
<tr>
107105
<th scope="row"><?php esc_html_e( 'API Key', 'tenup' ); ?></th>
108106
<td>
109-
<input name="tenup_support_monitor_settings[api_key]" type="text" id="tenup_api_key" value="<?php echo esc_attr( $setting['api_key'] ); ?>" class="regular-text">
107+
<?php $this->api_key_field(); ?>
110108
</td>
111109
</tr>
112110
<?php if ( Debug::instance()->is_debug_enabled() ) : ?>
113111
<tr>
114112
<th scope="row"><?php esc_html_e( 'API Server', 'tenup' ); ?></th>
115113
<td>
116-
<input name="tenup_support_monitor_settings[server_url]" type="url" id="tenup_server_url" value="<?php echo esc_attr( $setting['server_url'] ); ?>" class="regular-text">
114+
<?php $this->api_server_field(); ?>
117115
</td>
118116
</tr>
119117
<?php endif; ?>
@@ -143,6 +141,18 @@ public function get_setting( $setting_key = null ) {
143141
$settings['server_url'] = 'https://monitor.10up.com';
144142
}
145143

144+
if ( defined( 'SUPPORT_MONITOR_SERVER_URL' ) ) {
145+
$settings['server_url'] = SUPPORT_MONITOR_SERVER_URL;
146+
}
147+
148+
if ( defined( 'SUPPORT_MONITOR_API_KEY' ) ) {
149+
$settings['api_key'] = SUPPORT_MONITOR_API_KEY;
150+
}
151+
152+
if ( defined( 'SUPPORT_MONITOR_ENABLE' ) ) {
153+
$settings['enable_support_monitor'] = SUPPORT_MONITOR_ENABLE;
154+
}
155+
146156
if ( ! empty( $setting_key ) ) {
147157
return $settings[ $setting_key ];
148158
}
@@ -234,8 +244,8 @@ public function sanitize_settings( $settings ) {
234244
public function enable_field() {
235245
$value = $this->get_setting( 'enable_support_monitor' );
236246
?>
237-
<input name="tenup_support_monitor_settings[enable_support_monitor]" <?php checked( 'yes', $value ); ?> type="radio" id="tenup_enable_support_monitor_yes" value="yes"> <label for="tenup_enable_support_monitor_yes"><?php esc_html_e( 'Yes', 'tenup' ); ?></label><br>
238-
<input name="tenup_support_monitor_settings[enable_support_monitor]" <?php checked( 'no', $value ); ?> type="radio" id="tenup_enable_support_monitor_no" value="no"> <label for="tenup_enable_support_monitor_no"><?php esc_html_e( 'No', 'tenup' ); ?></label>
247+
<input name="tenup_support_monitor_settings[enable_support_monitor]" <?php checked( 'yes', $value ); ?><?php disabled( defined( 'SUPPORT_MONITOR_ENABLE' ) ); ?> type="radio" id="tenup_enable_support_monitor_yes" value="yes"> <label for="tenup_enable_support_monitor_yes"><?php esc_html_e( 'Yes', 'tenup' ); ?></label><br>
248+
<input name="tenup_support_monitor_settings[enable_support_monitor]" <?php checked( 'no', $value ); ?><?php disabled( defined( 'SUPPORT_MONITOR_ENABLE' ) ); ?> type="radio" id="tenup_enable_support_monitor_no" value="no"> <label for="tenup_enable_support_monitor_no"><?php esc_html_e( 'No', 'tenup' ); ?></label>
239249
<?php
240250
}
241251

@@ -247,7 +257,7 @@ public function enable_field() {
247257
public function api_key_field() {
248258
$value = $this->get_setting( 'api_key' );
249259
?>
250-
<input name="tenup_support_monitor_settings[api_key]" type="text" id="tenup_api_key" value="<?php echo esc_attr( $value ); ?>" class="regular-text">
260+
<input name="tenup_support_monitor_settings[api_key]" type="text" id="tenup_api_key" value="<?php echo esc_attr( $value ); ?>"<?php disabled( defined( 'SUPPORT_MONITOR_API_KEY' ) ); ?> class="regular-text">
251261
<?php
252262
}
253263

@@ -260,7 +270,7 @@ public function api_server_field() {
260270
$value = $this->get_setting( 'server_url' );
261271

262272
?>
263-
<input placeholder="https://monitor.10up.com" name="tenup_support_monitor_settings[server_url]" type="text" id="server_url" value="<?php echo esc_attr( $value ); ?>" class="regular-text">
273+
<input placeholder="https://monitor.10up.com" name="tenup_support_monitor_settings[server_url]" type="text" id="server_url" value="<?php echo esc_attr( $value ); ?>"<?php disabled( defined( 'SUPPORT_MONITOR_SERVER_URL' ) ); ?> class="regular-text">
264274
<?php
265275
}
266276

0 commit comments

Comments
 (0)