Fix critical bug where navbar configuration was not being saved. The component-navbar.js file existed but was not being loaded by WordPress, causing window.NavbarComponent to be undefined and preventing data collection. Changes: - Added wp_enqueue_script for component-navbar.js (lines 126-133) - Updated admin-app.js dependencies to include navbar component (line 139) Impact: Navbar settings now save correctly to database 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
154 lines
3.6 KiB
PHP
154 lines
3.6 KiB
PHP
<?php
|
|
/**
|
|
* Admin Menu Class
|
|
*
|
|
* Registra menú en WordPress admin y carga assets
|
|
*
|
|
* @package Apus_Theme
|
|
* @since 2.0.0
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class APUS_Admin_Menu {
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public function __construct() {
|
|
add_action('admin_menu', array($this, 'add_menu_page'));
|
|
add_action('admin_enqueue_scripts', array($this, 'enqueue_assets'));
|
|
}
|
|
|
|
/**
|
|
* Registrar página de admin
|
|
*/
|
|
public function add_menu_page() {
|
|
add_theme_page(
|
|
'APUs Theme Settings', // Page title
|
|
'Tema APUs', // Menu title
|
|
'manage_options', // Capability
|
|
'apus-theme-settings', // Menu slug
|
|
array($this, 'render_admin_page'), // Callback
|
|
59 // Position
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Renderizar página de admin
|
|
*/
|
|
public function render_admin_page() {
|
|
if (!current_user_can('manage_options')) {
|
|
wp_die(__('No tienes permisos para acceder a esta página.'));
|
|
}
|
|
|
|
require_once APUS_ADMIN_PANEL_PATH . 'admin/pages/main.php';
|
|
}
|
|
|
|
/**
|
|
* Encolar assets (CSS/JS)
|
|
*/
|
|
public function enqueue_assets($hook) {
|
|
// Solo cargar en nuestra página
|
|
if ($hook !== 'appearance_page_apus-theme-settings') {
|
|
return;
|
|
}
|
|
|
|
// Bootstrap 5.3.2 CSS
|
|
wp_enqueue_style(
|
|
'bootstrap',
|
|
'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css',
|
|
array(),
|
|
'5.3.2'
|
|
);
|
|
|
|
// Bootstrap Icons
|
|
wp_enqueue_style(
|
|
'bootstrap-icons',
|
|
'https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css',
|
|
array(),
|
|
'1.11.1'
|
|
);
|
|
|
|
// Admin Panel CSS (Core)
|
|
wp_enqueue_style(
|
|
'apus-admin-panel-css',
|
|
APUS_ADMIN_PANEL_URL . 'admin/assets/css/admin-panel.css',
|
|
array('bootstrap'),
|
|
APUS_ADMIN_PANEL_VERSION
|
|
);
|
|
|
|
// Frontend Component: Top Bar CSS (para preview - reusa el CSS del frontend)
|
|
wp_enqueue_style(
|
|
'apus-frontend-top-bar-css',
|
|
get_template_directory_uri() . '/assets/css/componente-top-bar.css',
|
|
array('apus-admin-panel-css'),
|
|
APUS_ADMIN_PANEL_VERSION
|
|
);
|
|
|
|
// Component: Top Bar CSS (estilos admin específicos)
|
|
wp_enqueue_style(
|
|
'apus-component-top-bar-css',
|
|
APUS_ADMIN_PANEL_URL . 'admin/assets/css/component-top-bar.css',
|
|
array('apus-frontend-top-bar-css'),
|
|
APUS_ADMIN_PANEL_VERSION
|
|
);
|
|
|
|
// Bootstrap 5.3.2 JS
|
|
wp_enqueue_script(
|
|
'bootstrap',
|
|
'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js',
|
|
array(),
|
|
'5.3.2',
|
|
true
|
|
);
|
|
|
|
// Axios (para AJAX)
|
|
wp_enqueue_script(
|
|
'axios',
|
|
'https://cdn.jsdelivr.net/npm/axios@1.6.0/dist/axios.min.js',
|
|
array(),
|
|
'1.6.0',
|
|
true
|
|
);
|
|
|
|
// Component: Top Bar JS (cargar antes de admin-app.js)
|
|
wp_enqueue_script(
|
|
'apus-component-top-bar-js',
|
|
APUS_ADMIN_PANEL_URL . 'admin/assets/js/component-top-bar.js',
|
|
array('jquery'),
|
|
APUS_ADMIN_PANEL_VERSION,
|
|
true
|
|
);
|
|
|
|
// Component: Navbar JS (cargar antes de admin-app.js)
|
|
wp_enqueue_script(
|
|
'apus-component-navbar-js',
|
|
APUS_ADMIN_PANEL_URL . 'admin/assets/js/component-navbar.js',
|
|
array('jquery'),
|
|
APUS_ADMIN_PANEL_VERSION,
|
|
true
|
|
);
|
|
|
|
// Admin Panel JS (Core - depende de componentes)
|
|
wp_enqueue_script(
|
|
'apus-admin-panel-js',
|
|
APUS_ADMIN_PANEL_URL . 'admin/assets/js/admin-app.js',
|
|
array('jquery', 'axios', 'apus-component-top-bar-js', 'apus-component-navbar-js'),
|
|
APUS_ADMIN_PANEL_VERSION,
|
|
true
|
|
);
|
|
|
|
// Pasar datos a JavaScript
|
|
wp_localize_script('apus-admin-panel-js', 'apusAdminData', array(
|
|
'ajaxUrl' => admin_url('admin-ajax.php'),
|
|
'nonce' => wp_create_nonce('apus_admin_nonce')
|
|
));
|
|
}
|
|
}
|
|
|
|
// Instanciar clase
|
|
new APUS_Admin_Menu();
|