<?php
/**
* Plugin Name: Working English System
* Plugin URI: https://workingenglish.com
* Description: Sistema académico y administrativo completo para gestión de estudiantes, maestros, grupos y finanzas
* Version: 1.0.0
* Author: Working English Team
* License: GPL v2 or later
* Text Domain: working-english-system
* Domain Path: /languages
*/
// Prevenir acceso directo
if (!defined('ABSPATH')) {
exit;
}
// Constantes del plugin
define('WES_VERSION', '1.0.0');
define('WES_PLUGIN_FILE', __FILE__);
define('WES_PLUGIN_PATH', plugin_dir_path(__FILE__));
define('WES_PLUGIN_URL', plugin_dir_url(__FILE__));
define('WES_PLUGIN_BASENAME', plugin_basename(__FILE__));
/**
* Clase principal del plugin Working English System
*/
class WorkingEnglishSystem {
/**
* Instancia única del plugin
*/
private static $instance = null;
/**
* Obtener instancia única
*/
public static function get_instance() {
if (null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor privado
*/
private function __construct() {
$this->init_hooks();
$this->load_dependencies();
}
/**
* Inicializar hooks principales
*/
private function init_hooks() {
register_activation_hook(__FILE__, array($this, 'activate'));
register_deactivation_hook(__FILE__, array($this, 'deactivate'));
add_action('init', array($this, 'init'));
add_action('admin_menu', array($this, 'admin_menu'));
add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
add_action('wes_weekly_cleanup', array($this, 'weekly_cleanup'));
add_action('wes_monthly_cleanup', array($this, 'monthly_cleanup'));
}
/**
* Cargar dependencias
*/
private function load_dependencies() {
// Cargar clases principales (solo si existen)
$includes = array(
'includes/class-wes-permissions.php'
);
foreach ($includes as $file) {
$file_path = WES_PLUGIN_PATH . $file;
if (file_exists($file_path)) {
require_once $file_path;
}
}
// Cargar módulos
$this->load_modules();
}
/**
* Cargar módulos dinámicamente
*/
private function load_modules() {
$modules = array(
'students' => 'WES_Students_Module',
'teachers' => 'WES_Teachers_Module',
'groups' => 'WES_Groups_Module',
'finance' => 'WES_Finance_Module'
);
foreach ($modules as $module => $class) {
$file = WES_PLUGIN_PATH . "modules/{$module}/class-wes-{$module}-module.php";
if (file_exists($file)) {
require_once $file;
if (class_exists($class)) {
new $class();
}
}
}
}
/**
* Activación del plugin
*/
public function activate() {
// Crear tablas de base de datos
$this->create_database_tables();
// Configuraciones iniciales
$this->set_default_options();
// Limpiar rewrite rules
flush_rewrite_rules();
$this->schedule_cleanup_tasks();
}
/**
* Desactivación del plugin
*/
public function deactivate() {
// Limpiar tareas programadas si las hay
wp_clear_scheduled_hook('wes_daily_cleanup');
wp_clear_scheduled_hook('wes_weekly_cleanup');
wp_clear_scheduled_hook('wes_monthly_cleanup');
// Limpiar rewrite rules
flush_rewrite_rules();
}
/**
* Inicialización del plugin
*/
public function init() {
// Cargar traducciones
load_plugin_textdomain('working-english-system', false, dirname(WES_PLUGIN_BASENAME) . '/languages');
// Ocultar admin bar en frontend
add_filter('show_admin_bar', '__return_false');
}
/**
* Configurar menú de administración
*/
public function admin_menu() {
// Menú principal
add_menu_page(
'Working English System',
'WE System',
'manage_options',
'wes-dashboard',
array($this, 'dashboard_page'),
'dashicons-education',
30
);
// Submenu para estudiantes
add_submenu_page(
'wes-dashboard',
'Estudiantes',
'Estudiantes',
'manage_options',
'wes-students',
array($this, 'students_page')
);
}
/**
* Página principal del dashboard
*/
public function dashboard_page() {
$dashboard_file = WES_PLUGIN_PATH . 'templates/admin/dashboard.php';
if (file_exists($dashboard_file)) {
include $dashboard_file;
} else {
// Fallback si no existe el template
echo '<div class="wrap">';
echo '<h1>Working English System</h1>';
echo '<p>¡Bienvenido al sistema de gestión de tu academia de inglés!</p>';
echo '<p>El plugin se ha instalado correctamente.</p>';
echo '<div class="card">';
echo '<h2>Módulos Disponibles:</h2>';
echo '<ul>';
echo '<li><a href="' . admin_url('admin.php?page=wes-students') . '">📚 Gestión de Estudiantes</a></li>';
echo '<li>👨🏫 Gestión de Maestros (Próximamente)</li>';
echo '<li>🏫 Gestión de Grupos (Próximamente)</li>';
echo '<li>💰 Gestión Financiera (Próximamente)</li>';
echo '</ul>';
echo '</div>';
echo '</div>';
}
}
/**
* Página del módulo de estudiantes
*/
public function students_page() {
if (class_exists('WES_Students_Module')) {
$students_module = new WES_Students_Module();
$students_module->render_students_page();
} else {
echo '<div class="wrap">';
echo '<h1>Error: Módulo de Estudiantes</h1>';
echo '<p>El módulo de estudiantes no está disponible. Verifica que todos los archivos estén instalados correctamente.</p>';
echo '</div>';
}
}
/**
* Cargar scripts y estilos del admin
*/
public function admin_scripts($hook) {
// Solo cargar en páginas del plugin
if (strpos($hook, 'wes-') === false && $hook !== 'toplevel_page_wes-dashboard') {
return;
}
// CSS principal (solo si existe)
$main_css = WES_PLUGIN_URL . 'assets/css/admin.css';
if (file_exists(WES_PLUGIN_PATH . 'assets/css/admin.css')) {
wp_enqueue_style(
'wes-admin-style',
$main_css,
array(),
WES_VERSION
);
}
// Bootstrap CSS
wp_enqueue_style(
'wes-bootstrap',
'https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css',
array(),
'5.3.0'
);
// Font Awesome para iconos
wp_enqueue_style(
'wes-fontawesome',
'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css',
array(),
'6.4.0'
);
// JavaScript principal (solo si existe)
$main_js = WES_PLUGIN_URL . 'assets/js/admin.js';
if (file_exists(WES_PLUGIN_PATH . 'assets/js/admin.js')) {
wp_enqueue_script(
'wes-admin-script',
$main_js,
array('jquery'),
WES_VERSION,
true
);
}
// Bootstrap JS
wp_enqueue_script(
'wes-bootstrap-js',
'https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js',
array(),
'5.3.0',
true
);
// Localizar script para AJAX - CORREGIDO
wp_localize_script('jquery', 'wesAjax', array(
'ajaxUrl' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('wes_nonce'),
'strings' => array(
'confirm_delete' => __('¿Estás seguro de eliminar este elemento?', 'working-english-system'),
'loading' => __('Cargando...', 'working-english-system'),
'error' => __('Ha ocurrido un error', 'working-english-system'),
'success' => __('Operación completada exitosamente', 'working-english-system')
)
));
// NUEVO: También crear wes_ajax para compatibilidad
wp_localize_script('jquery', 'wes_ajax', array(
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('wes_nonce'),
'strings' => array(
'confirm_delete' => __('¿Estás seguro de eliminar este elemento?', 'working-english-system'),
'loading' => __('Cargando...', 'working-english-system'),
'error' => __('Ha ocurrido un error', 'working-english-system'),
'success' => __('Operación completada exitosamente', 'working-english-system')
)
));
}
/**
* Crear tablas de base de datos completas
*/
private function create_database_tables() {
global $wpdb;
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
// 1️⃣ TABLA DE SEDES
$table_branches = $wpdb->prefix . 'wes_branches';
$sql_branches = "CREATE TABLE $table_branches (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(100) NOT NULL,
code varchar(10) NOT NULL,
address text,
city varchar(100),
country varchar(100),
manager_name varchar(100),
phone varchar(20),
email varchar(100),
status enum('active','inactive') DEFAULT 'active',
created_at datetime DEFAULT CURRENT_TIMESTAMP,
updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
deleted_at datetime NULL,
PRIMARY KEY (id),
UNIQUE KEY code (code),
KEY status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
// 2️⃣ TABLA DE IDIOMAS
$table_languages = $wpdb->prefix . 'wes_languages';
$sql_languages = "CREATE TABLE $table_languages (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(100) NOT NULL,
code varchar(10) NOT NULL,
status enum('active','inactive') DEFAULT 'active',
created_at datetime DEFAULT CURRENT_TIMESTAMP,
updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
deleted_at datetime NULL,
PRIMARY KEY (id),
UNIQUE KEY code (code),
KEY status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
// 3️⃣ TABLA DE RELACIÓN SEDE-IDIOMAS
$table_branch_languages = $wpdb->prefix . 'wes_branch_languages';
$sql_branch_languages = "CREATE TABLE $table_branch_languages (
id int(11) NOT NULL AUTO_INCREMENT,
branch_id int(11) NOT NULL,
language_id int(11) NOT NULL,
status enum('active','inactive') DEFAULT 'active',
created_at datetime DEFAULT CURRENT_TIMESTAMP,
updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY branch_language (branch_id, language_id),
KEY branch_id (branch_id),
KEY language_id (language_id),
FOREIGN KEY (branch_id) REFERENCES $table_branches(id) ON DELETE CASCADE,
FOREIGN KEY (language_id) REFERENCES $table_languages(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
// 4️⃣ TABLA DE PROGRAMAS
$table_programs = $wpdb->prefix . 'wes_programs';
$sql_programs = "CREATE TABLE $table_programs (
id int(11) NOT NULL AUTO_INCREMENT,
language_id int(11) NOT NULL,
name varchar(100) NOT NULL,
code varchar(20) NOT NULL,
description text,
status enum('active','inactive') DEFAULT 'active',
created_at datetime DEFAULT CURRENT_TIMESTAMP,
updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
deleted_at datetime NULL,
PRIMARY KEY (id),
UNIQUE KEY language_code (language_id, code),
KEY language_id (language_id),
KEY status (status),
FOREIGN KEY (language_id) REFERENCES $table_languages(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
// 5️⃣ TABLA DE NIVELES
$table_levels = $wpdb->prefix . 'wes_levels';
$sql_levels = "CREATE TABLE $table_levels (
id int(11) NOT NULL AUTO_INCREMENT,
program_id int(11) NOT NULL,
name varchar(50) NOT NULL,
code varchar(10) NOT NULL,
order_number int(11) NOT NULL DEFAULT 1,
status enum('active','inactive') DEFAULT 'active',
created_at datetime DEFAULT CURRENT_TIMESTAMP,
updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
deleted_at datetime NULL,
PRIMARY KEY (id),
UNIQUE KEY program_code (program_id, code),
KEY program_id (program_id),
KEY order_number (order_number),
KEY status (status),
FOREIGN KEY (program_id) REFERENCES $table_programs(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
// 6️⃣ TABLA DE CURSOS
$table_courses = $wpdb->prefix . 'wes_courses';
$sql_courses = "CREATE TABLE $table_courses (
id int(11) NOT NULL AUTO_INCREMENT,
branch_id int(11) NOT NULL,
level_id int(11) NOT NULL,
teacher_id int(11) NULL,
course_code varchar(50) NOT NULL,
start_date date NOT NULL,
end_date date,
monthly_fee decimal(10,2) NOT NULL DEFAULT 0.00,
schedule_time varchar(50),
monday tinyint(1) DEFAULT 0,
tuesday tinyint(1) DEFAULT 0,
wednesday tinyint(1) DEFAULT 0,
thursday tinyint(1) DEFAULT 0,
friday tinyint(1) DEFAULT 0,
saturday tinyint(1) DEFAULT 0,
sunday tinyint(1) DEFAULT 0,
max_students int(11) DEFAULT 20,
current_students int(11) DEFAULT 0,
status enum('active','inactive','completed','cancelled') DEFAULT 'active',
notes text,
created_at datetime DEFAULT CURRENT_TIMESTAMP,
updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
deleted_at datetime NULL,
PRIMARY KEY (id),
UNIQUE KEY course_code (course_code),
KEY branch_id (branch_id),
KEY level_id (level_id),
KEY teacher_id (teacher_id),
KEY start_date (start_date),
KEY status (status),
FOREIGN KEY (branch_id) REFERENCES $table_branches(id) ON DELETE CASCADE,
FOREIGN KEY (level_id) REFERENCES $table_levels(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
// 7️⃣ TABLA DE ESTUDIANTES (ACTUALIZADA)
$table_students = $wpdb->prefix . 'wes_students';
$sql_students = "CREATE TABLE $table_students (
id int(11) NOT NULL AUTO_INCREMENT,
student_id varchar(20) NOT NULL,
-- Datos Personales
first_name varchar(100) NOT NULL,
last_name varchar(100) NOT NULL,
date_of_birth date,
gender varchar(20),
country_of_origin varchar(100),
nationality varchar(100),
identity_document varchar(50),
-- Información de Contacto
email varchar(100) NULL,
phone varchar(20),
city varchar(100),
address text,
-- Responsables/Contacto de Emergencia
emergency_contact varchar(100),
emergency_email varchar(100),
emergency_phone varchar(20),
emergency_relationship varchar(50),
-- Información Adicional
how_did_you_hear varchar(100),
referred_by varchar(100),
special_notes text,
-- Campos del sistema
current_level varchar(50) DEFAULT 'beginner',
status varchar(20) DEFAULT 'active',
notes text,
created_at datetime DEFAULT CURRENT_TIMESTAMP,
updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
deleted_at datetime NULL,
PRIMARY KEY (id),
UNIQUE KEY student_id (student_id),
KEY email (email),
KEY country_of_origin (country_of_origin),
KEY status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
// 8️⃣ TABLA DE INSCRIPCIONES (ESTUDIANTE-CURSO)
$table_enrollments = $wpdb->prefix . 'wes_enrollments';
$sql_enrollments = "CREATE TABLE $table_enrollments (
id int(11) NOT NULL AUTO_INCREMENT,
student_id int(11) NOT NULL,
course_id int(11) NOT NULL,
enrollment_date date NOT NULL,
completion_date date NULL,
final_grade decimal(5,2) NULL,
status enum('active','completed','dropped','transferred') DEFAULT 'active',
notes text,
created_at datetime DEFAULT CURRENT_TIMESTAMP,
updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
deleted_at datetime NULL,
PRIMARY KEY (id),
UNIQUE KEY student_course (student_id, course_id),
KEY student_id (student_id),
KEY course_id (course_id),
KEY enrollment_date (enrollment_date),
KEY status (status),
FOREIGN KEY (student_id) REFERENCES $table_students(id) ON DELETE CASCADE,
FOREIGN KEY (course_id) REFERENCES $table_courses(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
// 9️⃣ TABLA DE PAGOS (ACTUALIZADA)
$table_payments = $wpdb->prefix . 'wes_payments';
$sql_payments = "CREATE TABLE $table_payments (
id int(11) NOT NULL AUTO_INCREMENT,
enrollment_id int(11) NOT NULL,
student_id int(11) NOT NULL,
course_id int(11) NOT NULL,
amount decimal(10,2) NOT NULL,
payment_date date NOT NULL,
payment_method enum('cash','card','transfer','check','other') NOT NULL,
reference_number varchar(100),
receipt_number varchar(50),
status enum('pending','completed','cancelled','refunded') DEFAULT 'completed',
notes text,
created_at datetime DEFAULT CURRENT_TIMESTAMP,
updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
deleted_at datetime NULL,
PRIMARY KEY (id),
KEY enrollment_id (enrollment_id),
KEY student_id (student_id),
KEY course_id (course_id),
KEY payment_date (payment_date),
KEY status (status),
FOREIGN KEY (enrollment_id) REFERENCES $table_enrollments(id) ON DELETE CASCADE,
FOREIGN KEY (student_id) REFERENCES $table_students(id) ON DELETE CASCADE,
FOREIGN KEY (course_id) REFERENCES $table_courses(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
// EJECUTAR TODAS LAS CONSULTAS
dbDelta($sql_branches);
dbDelta($sql_languages);
dbDelta($sql_branch_languages);
dbDelta($sql_programs);
dbDelta($sql_levels);
dbDelta($sql_courses);
dbDelta($sql_students);
dbDelta($sql_enrollments);
dbDelta($sql_payments);
// INSERTAR DATOS INICIALES
$this->insert_initial_course_data();
}
/**
* Insertar datos iniciales para el sistema de cursos
*/
private function insert_initial_course_data() {
global $wpdb;
// 1️⃣ SEDE PRINCIPAL
$wpdb->insert(
$wpdb->prefix . 'wes_branches',
array(
'name' => 'Sede Principal',
'code' => 'MAIN',
'address' => 'Casper, Wyoming, USA',
'city' => 'Casper',
'country' => 'United States',
'manager_name' => 'Director General'
)
);
$main_branch_id = $wpdb->insert_id;
// 2️⃣ IDIOMAS INICIALES
$languages = array(
array('name' => 'English', 'code' => 'EN'),
array('name' => 'Spanish', 'code' => 'ES'),
array('name' => 'French', 'code' => 'FR')
);
$language_ids = array();
foreach ($languages as $lang) {
$wpdb->insert($wpdb->prefix . 'wes_languages', $lang);
$language_ids[$lang['code']] = $wpdb->insert_id;
}
// 3️⃣ ASIGNAR IDIOMAS A SEDE PRINCIPAL
foreach ($language_ids as $code => $id) {
$wpdb->insert(
$wpdb->prefix . 'wes_branch_languages',
array(
'branch_id' => $main_branch_id,
'language_id' => $id
)
);
}
// 4️⃣ PROGRAMAS PARA INGLÉS
$english_programs = array(
array('name' => 'Kids Program', 'code' => 'KIDS', 'description' => 'Programa enfocado en niños'),
array('name' => 'Professional Program', 'code' => 'PROF', 'description' => 'Programa para adolescentes y adultos')
);
$program_ids = array();
foreach ($english_programs as $program) {
$program['language_id'] = $language_ids['EN'];
$wpdb->insert($wpdb->prefix . 'wes_programs', $program);
$program_ids[$program['code']] = $wpdb->insert_id;
}
// 5️⃣ NIVELES PARA PROGRAMA KIDS
$kids_levels = array(
array('name' => 'Pre-A1', 'code' => 'PA1', 'order_number' => 1),
array('name' => 'A1', 'code' => 'A1', 'order_number' => 2),
array('name' => 'A2', 'code' => 'A2', 'order_number' => 3),
array('name' => 'B1', 'code' => 'B1', 'order_number' => 4)
);
foreach ($kids_levels as $level) {
$level['program_id'] = $program_ids['KIDS'];
$wpdb->insert($wpdb->prefix . 'wes_levels', $level);
}
// 6️⃣ NIVELES PARA PROGRAMA PROFESIONAL
$prof_levels = array(
array('name' => 'Beginner', 'code' => 'BEG', 'order_number' => 1),
array('name' => 'Elementary', 'code' => 'ELE', 'order_number' => 2),
array('name' => 'Pre-Intermediate', 'code' => 'PRE', 'order_number' => 3),
array('name' => 'Intermediate', 'code' => 'INT', 'order_number' => 4),
array('name' => 'Upper-Intermediate', 'code' => 'UPP', 'order_number' => 5),
array('name' => 'Advanced', 'code' => 'ADV', 'order_number' => 6)
);
foreach ($prof_levels as $level) {
$level['program_id'] = $program_ids['PROF'];
$wpdb->insert($wpdb->prefix . 'wes_levels', $level);
}
}
/**
* Configurar opciones por defecto
*/
private function set_default_options() {
$default_options = array(
'wes_currency' => 'USD',
'wes_date_format' => 'Y-m-d',
'wes_time_format' => 'H:i',
'wes_pagination_limit' => 20,
'wes_backup_enabled' => true,
'wes_version' => WES_VERSION
);
foreach ($default_options as $option => $value) {
if (get_option($option) === false) {
add_option($option, $value);
}
}
}
private function schedule_cleanup_tasks() {
if (!wp_next_scheduled('wes_weekly_cleanup')) {
wp_schedule_event(strtotime('next Sunday 3:00 AM'), 'weekly', 'wes_weekly_cleanup');
}
if (!wp_next_scheduled('wes_monthly_cleanup')) {
wp_schedule_event(strtotime('first day of next month 2:00 AM'), 'monthly', 'wes_monthly_cleanup');
}
}
public function weekly_cleanup() {
global $wpdb;
$cleanup_date = date('Y-m-d H:i:s', strtotime('-30 days'));
$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}wes_student_payments WHERE deleted_at IS NOT NULL AND deleted_at < %s", $cleanup_date));
$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}wes_student_charges WHERE deleted_at IS NOT NULL AND deleted_at < %s", $cleanup_date));
}
public function monthly_cleanup() {
global $wpdb;
$cleanup_date = date('Y-m-d H:i:s', strtotime('-1 year'));
$tables = array('wes_branches', 'wes_languages', 'wes_programs', 'wes_levels');
foreach ($tables as $table) {
$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}{$table} WHERE deleted_at IS NOT NULL AND deleted_at < %s", $cleanup_date));
}
}
}
// Crear páginas en el frontend
add_action('init', 'wes_create_frontend_pages');
function wes_create_frontend_pages() {
add_rewrite_rule('^dashboard/?$', 'index.php?wes_page=dashboard', 'top');
add_rewrite_rule('^estudiantes/?$', 'index.php?wes_page=estudiantes', 'top');
}
add_filter('query_vars', 'wes_add_query_vars');
function wes_add_query_vars($vars) {
$vars[] = 'wes_page';
return $vars;
}
add_action('template_redirect', 'wes_frontend_template');
function wes_frontend_template() {
$wes_page = get_query_var('wes_page');
switch($wes_page) {
case 'dashboard':
include WES_PLUGIN_PATH . 'templates/frontend/dashboard.php';
exit;
case 'estudiantes':
include WES_PLUGIN_PATH . 'modules/students/templates/frontend-students.php';
exit;
}
}
/**
* Inicializar el plugin
*/
function wes_init() {
return WorkingEnglishSystem::get_instance();
}
// Inicializar cuando WordPress esté listo
add_action('plugins_loaded', 'wes_init');
// AGREGAR ESTAS LÍNEAS AL FINAL DE working-english-system.php
// (antes de las funciones de utilidad globales)
// Cargar módulo de configuración
require_once WES_PLUGIN_PATH . 'modules/config/class-wes-config-module.php';
// Agregar ruta de configuración
add_action('init', 'wes_add_config_route');
function wes_add_config_route() {
add_rewrite_rule('^configuracion/?$', 'index.php?wes_page=configuracion', 'top');
}
// Agregar variable de consulta
add_filter('query_vars', 'wes_add_config_query_var');
function wes_add_config_query_var($vars) {
$vars[] = 'wes_page';
return $vars;
}
// Actualizar el template redirect para incluir configuración
add_action('template_redirect', 'wes_frontend_template_updated');
function wes_frontend_template_updated() {
$wes_page = get_query_var('wes_page');
switch($wes_page) {
case 'dashboard':
include WES_PLUGIN_PATH . 'templates/frontend/dashboard.php';
exit;
case 'estudiantes':
include WES_PLUGIN_PATH . 'modules/students/templates/frontend-students.php';
exit;
case 'configuracion':
include WES_PLUGIN_PATH . 'modules/config/templates/frontend-config.php';
exit;
}
}
/**
* Funciones de utilidad globales
*/
function wes_get_current_user_role() {
$user = wp_get_current_user();
return !empty($user->roles) ? $user->roles[0] : '';
}
function wes_user_can_access_module($module) {
return current_user_can('manage_options');
}
function wes_format_currency($amount) {
$currency = get_option('wes_currency', 'USD');
return $currency . ' ' . number_format($amount, 2);
}
function wes_format_date($date, $format = null) {
if (empty($format)) {
$format = get_option('wes_date_format', 'Y-m-d');
}
return date($format, strtotime($date));
}