modo debug WP
This commit is contained in:
@@ -16,6 +16,7 @@ function alcastromol_default_modules() {
|
||||
'tailwind' => '1',
|
||||
'cache' => '1',
|
||||
'optimizer' => '0',
|
||||
'debug' => '0',
|
||||
'animejs' => '0',
|
||||
];
|
||||
|
||||
@@ -47,6 +48,7 @@ function alcastromol_module_icon($name) {
|
||||
'tailwind' => '<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M12 6.2c-2.6 0-4.2 1.3-5 3.8 1.1-1.5 2.4-2.1 4-1.7.9.2 1.6.8 2.3 1.5.9 1 1.9 1.9 3.7 1.9 2.6 0 4.2-1.3 5-3.8-1.1 1.5-2.4 2.1-4 1.7-.9-.2-1.6-.8-2.3-1.5-.9-1-1.9-1.9-3.7-1.9z"/><path d="M6.3 12.1c-2.6 0-4.2 1.3-5 3.8 1.1-1.5 2.4-2.1 4-1.7.9.2 1.6.8 2.3 1.5.9 1 1.9 1.9 3.7 1.9 2.6 0 4.2-1.3 5-3.8-1.1 1.5-2.4 2.1-4 1.7-.9-.2-1.6-.8-2.3-1.5-.9-1-1.9-1.9-3.7-1.9z"/></svg>',
|
||||
'cache' => '<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true"><ellipse cx="12" cy="6.5" rx="6.5" ry="2.6"/><path d="M5.5 6.5v5.2c0 1.5 2.9 2.6 6.5 2.6s6.5-1.1 6.5-2.6V6.5"/><path d="M5.5 11.7v5.2c0 1.5 2.9 2.6 6.5 2.6s6.5-1.1 6.5-2.6v-5.2"/></svg>',
|
||||
'optimizer' => '<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 3.5H7.2A1.7 1.7 0 0 0 5.5 5.2v13.6A1.7 1.7 0 0 0 7.2 20.5h9.6a1.7 1.7 0 0 0 1.7-1.7V8z"/><path d="M14 3.5V8h4.5"/><path d="M12 11.2v5.2"/><path d="M9.6 14.6 12 17l2.4-2.4"/></svg>',
|
||||
'debug' => '<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 20v-3"/><path d="M8 7.5V6a4 4 0 0 1 8 0v1.5"/><rect x="5" y="7.5" width="14" height="9.5" rx="2"/><path d="M3 12h2M19 12h2M8.5 20.5 7 23M15.5 20.5 17 23"/><path d="M9 13h.01M15 13h.01"/></svg>',
|
||||
'animejs' => '<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 16c2.2-6 4.2-9 8-9s5.8 3 8 9"/><path d="M8 16.5 12 8l4 8.5"/></svg>',
|
||||
];
|
||||
|
||||
@@ -87,6 +89,16 @@ function alcastromol_get_module_cards() {
|
||||
'badge' => '',
|
||||
'locked' => false,
|
||||
],
|
||||
'debug' => [
|
||||
'title' => 'Modo debug',
|
||||
'desc' => 'Activa o desactiva WP_DEBUG, WP_DEBUG_LOG y WP_DEBUG_DISPLAY en wp-config.php. Encendido muestra los errores y los guarda en debug.log.',
|
||||
'settings' => admin_url('admin.php?page=alcastromol-debug'),
|
||||
'bg' => '#fff4e5',
|
||||
'color' => '#d97706',
|
||||
'icon' => 'debug',
|
||||
'badge' => '',
|
||||
'locked' => false,
|
||||
],
|
||||
'animejs' => [
|
||||
'title' => 'Anime.js',
|
||||
'desc' => 'Carga Anime.js 4 desde el CDN. Cada import (animate, text, utils y el resto) se activa por separado y solo entra al sitio el que esté encendido.',
|
||||
@@ -134,12 +146,22 @@ add_action('wp_ajax_alcastromol_toggle_module', function () {
|
||||
|
||||
$module = sanitize_key($_POST['module'] ?? '');
|
||||
$active = ($_POST['active'] ?? '0') === '1' ? '1' : '0';
|
||||
$allowed = ['tailwind', 'cache', 'optimizer', 'animejs'];
|
||||
$allowed = ['tailwind', 'cache', 'optimizer', 'debug', 'animejs'];
|
||||
|
||||
if (!in_array($module, $allowed, true)) {
|
||||
wp_send_json_error(['message' => 'Esta función todavía no se puede activar.'], 400);
|
||||
}
|
||||
|
||||
if ($module === 'debug') {
|
||||
$result = function_exists('alcastromol_debug_set')
|
||||
? alcastromol_debug_set($active === '1')
|
||||
: new WP_Error('alcastromol_debug_missing', 'El módulo de debug no está disponible.');
|
||||
|
||||
if (is_wp_error($result)) {
|
||||
wp_send_json_error(['message' => $result->get_error_message()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
$modules = alcastromol_get_modules();
|
||||
$modules[$module] = $active;
|
||||
|
||||
@@ -172,6 +194,15 @@ function alcastromol_functions_dashboard_page() {
|
||||
<?php
|
||||
$active = !empty($modules[$id]) && $modules[$id] === '1';
|
||||
$locked = !empty($card['locked']);
|
||||
|
||||
if ($id === 'debug' && function_exists('alcastromol_debug_status')) {
|
||||
$debug_status = alcastromol_debug_status();
|
||||
|
||||
if (!is_wp_error($debug_status)) {
|
||||
$active = !empty($debug_status['enabled']);
|
||||
$locked = empty($debug_status['writable']);
|
||||
}
|
||||
}
|
||||
?>
|
||||
<article class="alcastromol-module<?php echo $active ? ' is-active' : ''; ?><?php echo $locked ? ' is-locked' : ''; ?>">
|
||||
<div class="alcastromol-module-icon" style="background:<?php echo esc_attr($card['bg']); ?>;color:<?php echo esc_attr($card['color']); ?>;">
|
||||
@@ -386,6 +417,8 @@ function alcastromol_functions_dashboard_page() {
|
||||
data.append('module', input.value);
|
||||
data.append('active', checked ? '1' : '0');
|
||||
|
||||
var message = 'No se pudo guardar el cambio.';
|
||||
|
||||
fetch(ajaxurl, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
@@ -394,11 +427,15 @@ function alcastromol_functions_dashboard_page() {
|
||||
return response.json();
|
||||
}).then(function (json) {
|
||||
if (!json || !json.success) {
|
||||
throw new Error('toggle failed');
|
||||
if (json && json.data && json.data.message) {
|
||||
message = json.data.message;
|
||||
}
|
||||
throw new Error(message);
|
||||
}
|
||||
}).catch(function () {
|
||||
input.checked = !checked;
|
||||
card.classList.toggle('is-active', input.checked);
|
||||
window.alert(message);
|
||||
}).finally(function () {
|
||||
card.classList.remove('is-saving');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user