- Cambiar de 'appearance_page_apus-theme-settings' a 'toplevel_page_apus-theme-settings' - Necesario para que assets se carguen correctamente en menú de nivel superior - Sin esto, el CSS/JS no se cargaba en la página de configuración
124 lines
2.7 KiB
PHP
124 lines
2.7 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
|
|
* Crea menú de nivel superior en sidebar (NO dentro de Apariencia)
|
|
*/
|
|
public function add_menu_page() {
|
|
add_menu_page(
|
|
'Apus Theme Options', // Page title
|
|
'Apus Theme', // Menu title
|
|
'manage_options', // Capability
|
|
'apus-theme-settings', // Menu slug
|
|
array($this, 'render_admin_page'), // Callback
|
|
'dashicons-admin-generic', // Icon (WordPress Dashicon)
|
|
61 // Position (61 = después de Appearance que es 60)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 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 . 'pages/main.php';
|
|
}
|
|
|
|
/**
|
|
* Encolar assets (CSS/JS)
|
|
*/
|
|
public function enqueue_assets($hook) {
|
|
// Solo cargar en nuestra página (toplevel = menú de nivel superior)
|
|
if ($hook !== 'toplevel_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 . 'assets/css/admin-panel.css',
|
|
array('bootstrap'),
|
|
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
|
|
);
|
|
|
|
|
|
// Admin Panel JS (Core)
|
|
wp_enqueue_script(
|
|
'apus-admin-panel-js',
|
|
APUS_ADMIN_PANEL_URL . 'assets/js/admin-app.js',
|
|
array('jquery', 'axios'),
|
|
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();
|