feat: add admin-controlled authentication debug mode
This commit is contained in:
@@ -7,7 +7,16 @@ class SettingsPageFormController extends InvocableController
|
||||
public function __invoke()
|
||||
{
|
||||
foreach (config('mahak.options') as $configured => $options_key) {
|
||||
register_setting(config('mahak.settings-group'), $options_key);
|
||||
$args = [];
|
||||
|
||||
if ($configured === 'debug-mode') {
|
||||
$args['sanitize_callback'] = function ($value): int {
|
||||
return (int) filter_var($value, FILTER_VALIDATE_BOOLEAN);
|
||||
};
|
||||
$args['default'] = 0;
|
||||
}
|
||||
|
||||
register_setting(config('mahak.settings-group'), $options_key, $args);
|
||||
}
|
||||
|
||||
add_settings_section(
|
||||
@@ -49,6 +58,14 @@ class SettingsPageFormController extends InvocableController
|
||||
config('mahak.section-id')
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
config('mahak.options.debug-mode'),
|
||||
config('mahak.translations.debug-mode'),
|
||||
fn () => $this->debug_mode(),
|
||||
config('mahak.settings-page'),
|
||||
config('mahak.section-id')
|
||||
);
|
||||
|
||||
$loginRouteOptionName = config('mahak.options.login-route');
|
||||
add_filter("pre_update_option_{$loginRouteOptionName}", function ($value) {
|
||||
return trim($value, '/');
|
||||
@@ -103,4 +120,14 @@ class SettingsPageFormController extends InvocableController
|
||||
echo "<input type='text' name='$name' value='$value' class='regular-text' />";
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
public function debug_mode(): void
|
||||
{
|
||||
$name = config('mahak.options.debug-mode');
|
||||
$enabled = (bool) get_option($name, false);
|
||||
|
||||
echo "<input type='hidden' name='".esc_attr($name)."' value='0' />";
|
||||
echo "<label><input type='checkbox' name='".esc_attr($name)."' value='1' ".checked($enabled, true, false).' /> ';
|
||||
echo esc_html(config('mahak.translations.debug-mode-description')).'</label>';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user