feat: add admin-controlled authentication debug mode

This commit is contained in:
2026-08-23 16:01:09 +03:30
parent 6419f82ea5
commit 572a740d46
11 changed files with 187 additions and 42 deletions
+24 -1
View File
@@ -1,9 +1,10 @@
<?php
if (!function_exists('view')) {
function view(string $view): string
function view(string $view, array $data = []): string
{
$basedir = plugin_dir_path(__FILE__);
extract($data, EXTR_SKIP);
ob_start();
include "{$basedir}resources/views/$view.php";
@@ -11,6 +12,28 @@ if (!function_exists('view')) {
}
}
if (!function_exists('mahak_debug_enabled')) {
function mahak_debug_enabled(): bool
{
return (bool) get_configured_option('debug-mode', false);
}
}
if (!function_exists('mahak_render_error')) {
function mahak_render_error(\Throwable $exception, int $status = 500, string $fallbackView = 'server-error'): void
{
if (mahak_debug_enabled()) {
wp_die(
view('debug-error', ['exception' => $exception]),
'Mahak Authentication Error',
['response' => $status]
);
}
wp_die(view($fallbackView), 'Authentication Error', ['response' => $status]);
}
}
if (!function_exists('dd')) {
function dd(): void
{