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>
238 lines
10 KiB
PHP
238 lines
10 KiB
PHP
<?php
|
|
/**
|
|
* Theme Options Settings API
|
|
*
|
|
* @package ROI_Theme
|
|
* @since 1.0.0
|
|
*/
|
|
|
|
// Exit if accessed directly
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Register all theme settings
|
|
*/
|
|
function roi_register_settings() {
|
|
// Register main options group
|
|
register_setting(
|
|
'roi_theme_options_group',
|
|
'roi_theme_options',
|
|
array(
|
|
'sanitize_callback' => 'roi_sanitize_options',
|
|
'default' => roi_get_default_options(),
|
|
)
|
|
);
|
|
|
|
// General Settings Section
|
|
add_settings_section(
|
|
'roi_general_section',
|
|
__('General Settings', 'roi-theme'),
|
|
'roi_general_section_callback',
|
|
'roitheme-options'
|
|
);
|
|
|
|
// Content Settings Section
|
|
add_settings_section(
|
|
'roi_content_section',
|
|
__('Content Settings', 'roi-theme'),
|
|
'roi_content_section_callback',
|
|
'roitheme-options'
|
|
);
|
|
|
|
// Performance Settings Section
|
|
add_settings_section(
|
|
'roi_performance_section',
|
|
__('Performance Settings', 'roi-theme'),
|
|
'roi_performance_section_callback',
|
|
'roitheme-options'
|
|
);
|
|
|
|
// Related Posts Settings Section
|
|
add_settings_section(
|
|
'roi_related_posts_section',
|
|
__('Related Posts Settings', 'roi-theme'),
|
|
'roi_related_posts_section_callback',
|
|
'roitheme-options'
|
|
);
|
|
|
|
// Social Share Settings Section
|
|
add_settings_section(
|
|
'roi_social_share_section',
|
|
__('Social Share Buttons', 'roi-theme'),
|
|
'roi_social_share_section_callback',
|
|
'roitheme-options'
|
|
);
|
|
}
|
|
add_action('admin_init', 'roi_register_settings');
|
|
|
|
/**
|
|
* Get default options
|
|
*
|
|
* @return array
|
|
*/
|
|
function roi_get_default_options() {
|
|
return array(
|
|
// General
|
|
'site_logo' => 0,
|
|
'site_favicon' => 0,
|
|
'enable_breadcrumbs' => true,
|
|
'breadcrumb_separator' => '>',
|
|
'date_format' => 'd/m/Y',
|
|
'time_format' => 'H:i',
|
|
'copyright_text' => sprintf(__('© %s %s. All rights reserved.', 'roi-theme'), date('Y'), get_bloginfo('name')),
|
|
'social_facebook' => '',
|
|
'social_twitter' => '',
|
|
'social_instagram' => '',
|
|
'social_linkedin' => '',
|
|
'social_youtube' => '',
|
|
|
|
// Content
|
|
'excerpt_length' => 55,
|
|
'excerpt_more' => '...',
|
|
'default_post_layout' => 'right-sidebar',
|
|
'default_page_layout' => 'right-sidebar',
|
|
'archive_posts_per_page' => 10,
|
|
'show_featured_image_single' => true,
|
|
'show_author_box' => true,
|
|
'enable_comments_posts' => true,
|
|
'enable_comments_pages' => false,
|
|
'show_post_meta' => true,
|
|
'show_post_tags' => true,
|
|
'show_post_categories' => true,
|
|
|
|
// Performance
|
|
'enable_lazy_loading' => true,
|
|
'performance_remove_emoji' => true,
|
|
'performance_remove_embeds' => false,
|
|
'performance_remove_dashicons' => true,
|
|
'performance_defer_js' => false,
|
|
'performance_minify_html' => false,
|
|
'performance_disable_gutenberg' => false,
|
|
|
|
// Related Posts
|
|
'enable_related_posts' => true,
|
|
'related_posts_count' => 3,
|
|
'related_posts_taxonomy' => 'category',
|
|
'related_posts_title' => __('Related Posts', 'roi-theme'),
|
|
'related_posts_columns' => 3,
|
|
|
|
// Social Share Buttons
|
|
'roi_enable_share_buttons' => '1',
|
|
'roi_share_text' => __('Compartir:', 'roi-theme'),
|
|
|
|
// Advanced
|
|
'custom_css' => '',
|
|
'custom_js_header' => '',
|
|
'custom_js_footer' => '',
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Section Callbacks
|
|
*/
|
|
function roi_general_section_callback() {
|
|
echo '<p>' . __('Configure general theme settings including logo, branding, and social media.', 'roi-theme') . '</p>';
|
|
}
|
|
|
|
function roi_content_section_callback() {
|
|
echo '<p>' . __('Configure content display settings for posts, pages, and archives.', 'roi-theme') . '</p>';
|
|
}
|
|
|
|
function roi_performance_section_callback() {
|
|
echo '<p>' . __('Optimize your site performance with these settings.', 'roi-theme') . '</p>';
|
|
}
|
|
|
|
function roi_related_posts_section_callback() {
|
|
echo '<p>' . __('Configure related posts display on single post pages.', 'roi-theme') . '</p>';
|
|
}
|
|
|
|
function roi_social_share_section_callback() {
|
|
echo '<p>' . __('Configure social share buttons display on single post pages.', 'roi-theme') . '</p>';
|
|
}
|
|
|
|
/**
|
|
* Sanitize all options
|
|
*
|
|
* @param array $input The input array
|
|
* @return array The sanitized array
|
|
*/
|
|
function roi_sanitize_options($input) {
|
|
$sanitized = array();
|
|
|
|
if (!is_array($input)) {
|
|
return $sanitized;
|
|
}
|
|
|
|
// General Settings
|
|
$sanitized['site_logo'] = isset($input['site_logo']) ? absint($input['site_logo']) : 0;
|
|
$sanitized['site_favicon'] = isset($input['site_favicon']) ? absint($input['site_favicon']) : 0;
|
|
$sanitized['enable_breadcrumbs'] = isset($input['enable_breadcrumbs']) ? (bool) $input['enable_breadcrumbs'] : false;
|
|
$sanitized['breadcrumb_separator'] = isset($input['breadcrumb_separator']) ? sanitize_text_field($input['breadcrumb_separator']) : '>';
|
|
$sanitized['date_format'] = isset($input['date_format']) ? sanitize_text_field($input['date_format']) : 'd/m/Y';
|
|
$sanitized['time_format'] = isset($input['time_format']) ? sanitize_text_field($input['time_format']) : 'H:i';
|
|
$sanitized['copyright_text'] = isset($input['copyright_text']) ? wp_kses_post($input['copyright_text']) : '';
|
|
|
|
// Social Media
|
|
$social_fields = array('facebook', 'twitter', 'instagram', 'linkedin', 'youtube');
|
|
foreach ($social_fields as $social) {
|
|
$key = 'social_' . $social;
|
|
$sanitized[$key] = isset($input[$key]) ? esc_url_raw($input[$key]) : '';
|
|
}
|
|
|
|
// Content Settings
|
|
$sanitized['excerpt_length'] = isset($input['excerpt_length']) ? absint($input['excerpt_length']) : 55;
|
|
$sanitized['excerpt_more'] = isset($input['excerpt_more']) ? sanitize_text_field($input['excerpt_more']) : '...';
|
|
$sanitized['default_post_layout'] = isset($input['default_post_layout']) ? sanitize_text_field($input['default_post_layout']) : 'right-sidebar';
|
|
$sanitized['default_page_layout'] = isset($input['default_page_layout']) ? sanitize_text_field($input['default_page_layout']) : 'right-sidebar';
|
|
$sanitized['archive_posts_per_page'] = isset($input['archive_posts_per_page']) ? absint($input['archive_posts_per_page']) : 10;
|
|
$sanitized['show_featured_image_single'] = isset($input['show_featured_image_single']) ? (bool) $input['show_featured_image_single'] : false;
|
|
$sanitized['show_author_box'] = isset($input['show_author_box']) ? (bool) $input['show_author_box'] : false;
|
|
$sanitized['enable_comments_posts'] = isset($input['enable_comments_posts']) ? (bool) $input['enable_comments_posts'] : false;
|
|
$sanitized['enable_comments_pages'] = isset($input['enable_comments_pages']) ? (bool) $input['enable_comments_pages'] : false;
|
|
$sanitized['show_post_meta'] = isset($input['show_post_meta']) ? (bool) $input['show_post_meta'] : false;
|
|
$sanitized['show_post_tags'] = isset($input['show_post_tags']) ? (bool) $input['show_post_tags'] : false;
|
|
$sanitized['show_post_categories'] = isset($input['show_post_categories']) ? (bool) $input['show_post_categories'] : false;
|
|
|
|
// Performance Settings
|
|
$sanitized['enable_lazy_loading'] = isset($input['enable_lazy_loading']) ? (bool) $input['enable_lazy_loading'] : false;
|
|
$sanitized['performance_remove_emoji'] = isset($input['performance_remove_emoji']) ? (bool) $input['performance_remove_emoji'] : false;
|
|
$sanitized['performance_remove_embeds'] = isset($input['performance_remove_embeds']) ? (bool) $input['performance_remove_embeds'] : false;
|
|
$sanitized['performance_remove_dashicons'] = isset($input['performance_remove_dashicons']) ? (bool) $input['performance_remove_dashicons'] : false;
|
|
$sanitized['performance_defer_js'] = isset($input['performance_defer_js']) ? (bool) $input['performance_defer_js'] : false;
|
|
$sanitized['performance_minify_html'] = isset($input['performance_minify_html']) ? (bool) $input['performance_minify_html'] : false;
|
|
$sanitized['performance_disable_gutenberg'] = isset($input['performance_disable_gutenberg']) ? (bool) $input['performance_disable_gutenberg'] : false;
|
|
|
|
// Related Posts
|
|
$sanitized['enable_related_posts'] = isset($input['enable_related_posts']) ? (bool) $input['enable_related_posts'] : false;
|
|
$sanitized['related_posts_count'] = isset($input['related_posts_count']) ? absint($input['related_posts_count']) : 3;
|
|
$sanitized['related_posts_taxonomy'] = isset($input['related_posts_taxonomy']) ? sanitize_text_field($input['related_posts_taxonomy']) : 'category';
|
|
$sanitized['related_posts_title'] = isset($input['related_posts_title']) ? sanitize_text_field($input['related_posts_title']) : __('Related Posts', 'roi-theme');
|
|
$sanitized['related_posts_columns'] = isset($input['related_posts_columns']) ? absint($input['related_posts_columns']) : 3;
|
|
|
|
// Social Share Buttons
|
|
$sanitized['roi_enable_share_buttons'] = isset($input['roi_enable_share_buttons']) ? sanitize_text_field($input['roi_enable_share_buttons']) : '1';
|
|
$sanitized['roi_share_text'] = isset($input['roi_share_text']) ? sanitize_text_field($input['roi_share_text']) : __('Compartir:', 'roi-theme');
|
|
|
|
// Advanced Settings
|
|
$sanitized['custom_css'] = isset($input['custom_css']) ? roi_sanitize_css($input['custom_css']) : '';
|
|
$sanitized['custom_js_header'] = isset($input['custom_js_header']) ? roi_sanitize_js($input['custom_js_header']) : '';
|
|
$sanitized['custom_js_footer'] = isset($input['custom_js_footer']) ? roi_sanitize_js($input['custom_js_footer']) : '';
|
|
|
|
return $sanitized;
|
|
}
|
|
|
|
/**
|
|
* NOTE: All sanitization functions have been moved to inc/sanitize-functions.php
|
|
* to avoid function redeclaration errors. This includes:
|
|
* - roi_sanitize_css()
|
|
* - roi_sanitize_js()
|
|
* - roi_sanitize_integer()
|
|
* - roi_sanitize_text()
|
|
* - roi_sanitize_url()
|
|
* - roi_sanitize_html()
|
|
* - roi_sanitize_checkbox()
|
|
* - roi_sanitize_select()
|
|
*/
|