COMPLETADO: Fase 1 de la migración a Clean Architecture + POO ## Estructura de Carpetas - ✓ Estructura completa de 4 capas (Domain, Application, Infrastructure, Presentation) - ✓ Carpetas de Use Cases (SaveComponent, GetComponent, DeleteComponent, SyncSchema) - ✓ Estructura de tests (Unit, Integration, E2E) - ✓ Carpetas de schemas y templates ## Composer y Autoloading - ✓ PSR-4 autoloading configurado para ROITheme namespace - ✓ Autoloader optimizado regenerado ## DI Container - ✓ DIContainer implementado con patrón Singleton - ✓ Métodos set(), get(), has() para gestión de servicios - ✓ Getters específicos para ComponentRepository, ValidationService, CacheService - ✓ Placeholders que serán implementados en Fase 5 - ✓ Prevención de clonación y deserialización ## Interfaces - ✓ ComponentRepositoryInterface (Domain) - ✓ ValidationServiceInterface (Application) - ✓ CacheServiceInterface (Application) - ✓ Component entity placeholder (Domain) ## Bootstrap - ✓ functions.php actualizado con carga de Composer autoloader - ✓ Inicialización del DIContainer - ✓ Helper function roi_container() disponible globalmente ## Tests - ✓ 10 tests unitarios para DIContainer (100% cobertura) - ✓ Total: 13 tests unitarios, 28 assertions - ✓ Suite de tests pasando correctamente ## Validación - ✓ Script de validación automatizado (48/48 checks pasados) - ✓ 100% de validaciones exitosas La arquitectura base está lista para la Fase 2. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
218 lines
6.7 KiB
PHP
218 lines
6.7 KiB
PHP
<?php
|
|
/**
|
|
* Theme Options Admin Page
|
|
*
|
|
* @package ROI_Theme
|
|
* @since 1.0.0
|
|
*/
|
|
|
|
// Exit if accessed directly
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Add admin menu
|
|
* DESACTIVADO: Ahora se usa el nuevo Admin Panel en admin/includes/class-admin-menu.php
|
|
*/
|
|
/*
|
|
function roi_add_admin_menu() {
|
|
add_theme_page(
|
|
__('ROI Theme Options', 'roi-theme'), // Page title
|
|
__('Theme Options', 'roi-theme'), // Menu title
|
|
'manage_options', // Capability
|
|
'roi-theme-options', // Menu slug
|
|
'roi_render_options_page', // Callback function
|
|
30 // Position
|
|
);
|
|
}
|
|
add_action('admin_menu', 'roi_add_admin_menu');
|
|
*/
|
|
|
|
/**
|
|
* Render the options page
|
|
*/
|
|
function roi_render_options_page() {
|
|
// Check user capabilities
|
|
if (!current_user_can('manage_options')) {
|
|
wp_die(__('You do not have sufficient permissions to access this page.', 'roi-theme'));
|
|
}
|
|
|
|
// Load the template
|
|
include get_template_directory() . '/admin/theme-options/options-page-template.php';
|
|
}
|
|
|
|
/**
|
|
* Enqueue admin scripts and styles
|
|
*/
|
|
function roi_enqueue_admin_scripts($hook) {
|
|
// Only load on our theme options page
|
|
if ($hook !== 'appearance_page_roi-theme-options') {
|
|
return;
|
|
}
|
|
|
|
// Enqueue WordPress media uploader
|
|
wp_enqueue_media();
|
|
|
|
// Enqueue admin styles
|
|
wp_enqueue_style(
|
|
'roiadmin-options',
|
|
get_template_directory_uri() . '/admin/assets/css/theme-options.css',
|
|
array(),
|
|
ROI_VERSION
|
|
);
|
|
|
|
// Enqueue admin scripts
|
|
wp_enqueue_script(
|
|
'roiadmin-options',
|
|
get_template_directory_uri() . '/admin/assets/js/theme-options.js',
|
|
array('jquery', 'wp-color-picker'),
|
|
ROI_VERSION,
|
|
true
|
|
);
|
|
|
|
// Localize script
|
|
wp_localize_script('roiadmin-options', 'rroiminOptions', array(
|
|
'ajaxUrl' => admin_url('admin-ajax.php'),
|
|
'nonce' => wp_create_nonce('roi_admin_nonce'),
|
|
'strings' => array(
|
|
'selectImage' => __('Select Image', 'roi-theme'),
|
|
'useImage' => __('Use Image', 'roi-theme'),
|
|
'removeImage' => __('Remove Image', 'roi-theme'),
|
|
'confirmReset' => __('Are you sure you want to reset all options to default values? This cannot be undone.', 'roi-theme'),
|
|
'saved' => __('Settings saved successfully!', 'roi-theme'),
|
|
'error' => __('An error occurred while saving settings.', 'roi-theme'),
|
|
),
|
|
));
|
|
}
|
|
add_action('admin_enqueue_scripts', 'roi_enqueue_admin_scripts');
|
|
|
|
/**
|
|
* Add settings link to theme actions
|
|
*/
|
|
function roi_add_settings_link($links) {
|
|
$settings_link = '<a href="' . admin_url('themes.php?page=roi-theme-options') . '">' . __('Settings', 'roi-theme') . '</a>';
|
|
array_unshift($links, $settings_link);
|
|
return $links;
|
|
}
|
|
add_filter('theme_action_links_' . get_template(), 'roi_add_settings_link');
|
|
|
|
/**
|
|
* AJAX handler for resetting options
|
|
*/
|
|
function roi_reset_options_ajax() {
|
|
check_ajax_referer('roi_admin_nonce', 'nonce');
|
|
|
|
if (!current_user_can('manage_options')) {
|
|
wp_send_json_error(array('message' => __('Insufficient permissions.', 'roi-theme')));
|
|
}
|
|
|
|
// Delete options to reset to defaults
|
|
delete_option('roi_theme_options');
|
|
|
|
wp_send_json_success(array('message' => __('Options reset to defaults successfully.', 'roi-theme')));
|
|
}
|
|
add_action('wp_ajax_roi_reset_options', 'roi_reset_options_ajax');
|
|
|
|
/**
|
|
* AJAX handler for exporting options
|
|
*/
|
|
function roi_export_options_ajax() {
|
|
check_ajax_referer('roi_admin_nonce', 'nonce');
|
|
|
|
if (!current_user_can('manage_options')) {
|
|
wp_send_json_error(array('message' => __('Insufficient permissions.', 'roi-theme')));
|
|
}
|
|
|
|
$options = get_option('roi_theme_options', array());
|
|
|
|
wp_send_json_success(array(
|
|
'data' => json_encode($options, JSON_PRETTY_PRINT),
|
|
'filename' => 'roi-theme-options-' . date('Y-m-d') . '.json'
|
|
));
|
|
}
|
|
add_action('wp_ajax_roi_export_options', 'roi_export_options_ajax');
|
|
|
|
/**
|
|
* AJAX handler for importing options
|
|
*/
|
|
function roi_import_options_ajax() {
|
|
check_ajax_referer('roi_admin_nonce', 'nonce');
|
|
|
|
if (!current_user_can('manage_options')) {
|
|
wp_send_json_error(array('message' => __('Insufficient permissions.', 'roi-theme')));
|
|
}
|
|
|
|
if (!isset($_POST['import_data'])) {
|
|
wp_send_json_error(array('message' => __('No import data provided.', 'roi-theme')));
|
|
}
|
|
|
|
$import_data = json_decode(stripslashes($_POST['import_data']), true);
|
|
|
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
wp_send_json_error(array('message' => __('Invalid JSON data.', 'roi-theme')));
|
|
}
|
|
|
|
// Sanitize imported data
|
|
$sanitized_data = roi_sanitize_options($import_data);
|
|
|
|
// Update options
|
|
update_option('roi_theme_options', $sanitized_data);
|
|
|
|
wp_send_json_success(array('message' => __('Options imported successfully.', 'roi-theme')));
|
|
}
|
|
add_action('wp_ajax_roi_import_options', 'roi_import_options_ajax');
|
|
|
|
/**
|
|
* Add admin notices
|
|
*/
|
|
function roi_admin_notices() {
|
|
$screen = get_current_screen();
|
|
if ($screen->id !== 'appearance_page_roi-theme-options') {
|
|
return;
|
|
}
|
|
|
|
// Check if settings were updated
|
|
if (isset($_GET['settings-updated']) && $_GET['settings-updated'] === 'true') {
|
|
?>
|
|
<div class="notice notice-success is-dismissible">
|
|
<p><?php _e('Settings saved successfully!', 'roi-theme'); ?></p>
|
|
</div>
|
|
<?php
|
|
}
|
|
}
|
|
add_action('admin_notices', 'roi_admin_notices');
|
|
|
|
/**
|
|
* Register theme options in Customizer as well (for preview)
|
|
*/
|
|
function roi_customize_register($wp_customize) {
|
|
// Add a panel for theme options
|
|
$wp_customize->add_panel('roi_theme_options', array(
|
|
'title' => __('ROI Theme Options', 'roi-theme'),
|
|
'description' => __('Configure theme options (Also available in Theme Options page)', 'roi-theme'),
|
|
'priority' => 10,
|
|
));
|
|
|
|
// General Section
|
|
$wp_customize->add_section('roi_general', array(
|
|
'title' => __('General Settings', 'roi-theme'),
|
|
'panel' => 'roi_theme_options',
|
|
'priority' => 10,
|
|
));
|
|
|
|
// Enable breadcrumbs
|
|
$wp_customize->add_setting('roi_theme_options[enable_breadcrumbs]', array(
|
|
'default' => true,
|
|
'type' => 'option',
|
|
'sanitize_callback' => 'roi_sanitize_checkbox',
|
|
));
|
|
|
|
$wp_customize->add_control('roi_theme_options[enable_breadcrumbs]', array(
|
|
'label' => __('Enable Breadcrumbs', 'roi-theme'),
|
|
'section' => 'roi_general',
|
|
'type' => 'checkbox',
|
|
));
|
|
}
|
|
add_action('customize_register', 'roi_customize_register');
|