Files
roi-theme/inc/theme-options-helpers.php
FrankZamora de5fff4f5c Fase 1: Estructura Base y DI Container - Clean Architecture
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>
2025-11-17 13:48:24 -06:00

346 lines
6.5 KiB
PHP

<?php
/**
* Theme Options Helper Functions
*
* @package ROI_Theme
* @since 1.0.0
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}
/**
* Get theme option value
*
* @param string $option_name The option name
* @param mixed $default Default value if option doesn't exist
* @return mixed The option value
*/
function roi_get_option($option_name, $default = '') {
$options = get_option('roi_theme_options', array());
if (isset($options[$option_name])) {
return $options[$option_name];
}
return $default;
}
/**
* Check if option is enabled (checkbox/switch)
*
* @param string $option_name The option name
* @return bool True if enabled, false otherwise
*/
function roi_is_option_enabled($option_name) {
return (bool) roi_get_option($option_name, false);
}
/**
* Get breadcrumbs separator
*
* @return string The separator
*/
function roi_get_breadcrumb_separator() {
return roi_get_option('breadcrumb_separator', '>');
}
/**
* Check if breadcrumbs should be shown
*
* @return bool
*/
function roi_show_breadcrumbs() {
return roi_is_option_enabled('enable_breadcrumbs');
}
/**
* Get excerpt length
*
* @return int The excerpt length
*/
function roi_get_excerpt_length() {
return (int) roi_get_option('excerpt_length', 55);
}
/**
* Get excerpt more text
*
* @return string The excerpt more text
*/
function roi_get_excerpt_more() {
return roi_get_option('excerpt_more', '...');
}
/**
* Check if related posts should be shown
*
* @return bool
*/
function roi_show_related_posts() {
return roi_is_option_enabled('enable_related_posts');
}
/**
* Get number of related posts to show
*
* @return int
*/
function roi_get_related_posts_count() {
return (int) roi_get_option('related_posts_count', 3);
}
/**
* Get related posts taxonomy
*
* @return string
*/
function roi_get_related_posts_taxonomy() {
return roi_get_option('related_posts_taxonomy', 'category');
}
/**
* Get related posts title
*
* @return string
*/
function roi_get_related_posts_title() {
return roi_get_option('related_posts_title', __('Related Posts', 'roi-theme'));
}
/**
* Check if specific performance optimization is enabled
*
* @param string $optimization The optimization name
* @return bool
*/
function roi_is_performance_enabled($optimization) {
return roi_is_option_enabled('performance_' . $optimization);
}
/**
* Get copyright text
*
* @return string
*/
function roi_get_copyright_text() {
$default = sprintf(
__('&copy; %s %s. All rights reserved.', 'roi-theme'),
date('Y'),
get_bloginfo('name')
);
return roi_get_option('copyright_text', $default);
}
/**
* Get social media links
*
* @return array Array of social media links
*/
function roi_get_social_links() {
return array(
'facebook' => roi_get_option('social_facebook', ''),
'twitter' => roi_get_option('social_twitter', ''),
'instagram' => roi_get_option('social_instagram', ''),
'linkedin' => roi_get_option('social_linkedin', ''),
'youtube' => roi_get_option('social_youtube', ''),
);
}
/**
* Check if comments are enabled for posts
*
* @return bool
*/
function roi_comments_enabled_for_posts() {
return roi_is_option_enabled('enable_comments_posts');
}
/**
* Check if comments are enabled for pages
*
* @return bool
*/
function roi_comments_enabled_for_pages() {
return roi_is_option_enabled('enable_comments_pages');
}
/**
* Get default post layout
*
* @return string
*/
function roi_get_default_post_layout() {
return roi_get_option('default_post_layout', 'right-sidebar');
}
/**
* Get default page layout
*
* @return string
*/
function roi_get_default_page_layout() {
return roi_get_option('default_page_layout', 'right-sidebar');
}
/**
* Get posts per page for archive
*
* @return int
*/
function roi_get_archive_posts_per_page() {
$custom = (int) roi_get_option('archive_posts_per_page', 0);
return $custom > 0 ? $custom : get_option('posts_per_page', 10);
}
/**
* Check if featured image should be shown on single posts
*
* @return bool
*/
function roi_show_featured_image_single() {
return roi_is_option_enabled('show_featured_image_single');
}
/**
* Check if author box should be shown on single posts
*
* @return bool
*/
function roi_show_author_box() {
return roi_is_option_enabled('show_author_box');
}
/**
* Get date format
*
* @return string
*/
function roi_get_date_format() {
return roi_get_option('date_format', 'd/m/Y');
}
/**
* Get time format
*
* @return string
*/
function roi_get_time_format() {
return roi_get_option('time_format', 'H:i');
}
/**
* Get logo URL
*
* @return string
*/
function roi_get_logo_url() {
$logo_id = roi_get_option('site_logo', 0);
if ($logo_id) {
$logo = wp_get_attachment_image_url($logo_id, 'full');
if ($logo) {
return $logo;
}
}
return '';
}
/**
* Get favicon URL
*
* @return string
*/
function roi_get_favicon_url() {
$favicon_id = roi_get_option('site_favicon', 0);
if ($favicon_id) {
$favicon = wp_get_attachment_image_url($favicon_id, 'full');
if ($favicon) {
return $favicon;
}
}
return '';
}
/**
* Get custom CSS
*
* @return string
*/
function roi_get_custom_css() {
return roi_get_option('custom_css', '');
}
/**
* Get custom JS (header)
*
* @return string
*/
function roi_get_custom_js_header() {
return roi_get_option('custom_js_header', '');
}
/**
* Get custom JS (footer)
*
* @return string
*/
function roi_get_custom_js_footer() {
return roi_get_option('custom_js_footer', '');
}
/**
* Check if lazy loading is enabled
*
* @return bool
*/
function roi_is_lazy_loading_enabled() {
return roi_is_option_enabled('enable_lazy_loading');
}
/**
* Get all theme options
*
* @return array
*/
function roi_get_all_options() {
return get_option('roi_theme_options', array());
}
/**
* Reset theme options to defaults
*
* @return bool
*/
function roi_reset_options() {
return delete_option('roi_theme_options');
}
/**
* Check if Table of Contents is enabled
*
* @return bool
*/
function roi_is_toc_enabled() {
return roi_get_option('enable_toc', true);
}
/**
* Get minimum headings required to display TOC
*
* @return int
*/
function roi_get_toc_min_headings() {
return (int) roi_get_option('toc_min_headings', 2);
}
/**
* Get TOC title
*
* @return string
*/
function roi_get_toc_title() {
return roi_get_option('toc_title', __('Table of Contents', 'roi-theme'));
}