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>
395 lines
11 KiB
PHP
395 lines
11 KiB
PHP
<?php
|
|
/**
|
|
* Theme Options Usage Examples
|
|
*
|
|
* This file contains examples of how to use theme options throughout the theme.
|
|
* DO NOT include this file in functions.php - it's for reference only.
|
|
*
|
|
* @package ROI_Theme
|
|
* @since 1.0.0
|
|
*/
|
|
|
|
// Exit if accessed directly
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* EXAMPLE 1: Using options in header.php
|
|
*/
|
|
function example_display_logo() {
|
|
$logo_url = roi_get_logo_url();
|
|
|
|
if ($logo_url) {
|
|
?>
|
|
<a href="<?php echo esc_url(home_url('/')); ?>" class="custom-logo-link">
|
|
<img src="<?php echo esc_url($logo_url); ?>" alt="<?php bloginfo('name'); ?>" class="custom-logo" />
|
|
</a>
|
|
<?php
|
|
} else {
|
|
?>
|
|
<h1 class="site-title">
|
|
<a href="<?php echo esc_url(home_url('/')); ?>"><?php bloginfo('name'); ?></a>
|
|
</h1>
|
|
<?php
|
|
}
|
|
}
|
|
|
|
/**
|
|
* EXAMPLE 2: Displaying breadcrumbs
|
|
*/
|
|
function example_show_breadcrumbs() {
|
|
if (roi_show_breadcrumbs() && !is_front_page()) {
|
|
$separator = roi_get_breadcrumb_separator();
|
|
|
|
echo '<nav class="breadcrumbs">';
|
|
echo '<a href="' . esc_url(home_url('/')) . '">Home</a>';
|
|
echo ' ' . esc_html($separator) . ' ';
|
|
|
|
if (is_single()) {
|
|
the_category(' ' . esc_html($separator) . ' ');
|
|
echo ' ' . esc_html($separator) . ' ';
|
|
the_title();
|
|
} elseif (is_category()) {
|
|
single_cat_title();
|
|
}
|
|
|
|
echo '</nav>';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* EXAMPLE 3: Customizing excerpt
|
|
*/
|
|
function example_custom_excerpt_length($length) {
|
|
return roi_get_excerpt_length();
|
|
}
|
|
add_filter('excerpt_length', 'example_custom_excerpt_length');
|
|
|
|
function example_custom_excerpt_more($more) {
|
|
return roi_get_excerpt_more();
|
|
}
|
|
add_filter('excerpt_more', 'example_custom_excerpt_more');
|
|
|
|
/**
|
|
* EXAMPLE 4: Displaying related posts in single.php
|
|
*/
|
|
function example_display_related_posts() {
|
|
if (roi_show_related_posts() && is_single()) {
|
|
$count = roi_get_related_posts_count();
|
|
$taxonomy = roi_get_related_posts_taxonomy();
|
|
$title = roi_get_related_posts_title();
|
|
|
|
// Get related posts
|
|
$post_id = get_the_ID();
|
|
$args = array(
|
|
'posts_per_page' => $count,
|
|
'post__not_in' => array($post_id),
|
|
);
|
|
|
|
if ($taxonomy === 'category') {
|
|
$categories = wp_get_post_categories($post_id);
|
|
if ($categories) {
|
|
$args['category__in'] = $categories;
|
|
}
|
|
} elseif ($taxonomy === 'tag') {
|
|
$tags = wp_get_post_tags($post_id, array('fields' => 'ids'));
|
|
if ($tags) {
|
|
$args['tag__in'] = $tags;
|
|
}
|
|
}
|
|
|
|
$related = new WP_Query($args);
|
|
|
|
if ($related->have_posts()) {
|
|
?>
|
|
<div class="related-posts">
|
|
<h3><?php echo esc_html($title); ?></h3>
|
|
<div class="related-posts-grid">
|
|
<?php
|
|
while ($related->have_posts()) {
|
|
$related->the_post();
|
|
?>
|
|
<article class="related-post-item">
|
|
<?php if (has_post_thumbnail()) : ?>
|
|
<a href="<?php the_permalink(); ?>">
|
|
<?php the_post_thumbnail('roi-thumbnail'); ?>
|
|
</a>
|
|
<?php endif; ?>
|
|
<h4>
|
|
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
|
|
</h4>
|
|
<div class="post-meta">
|
|
<time datetime="<?php echo get_the_date('c'); ?>">
|
|
<?php echo get_the_date(roi_get_date_format()); ?>
|
|
</time>
|
|
</div>
|
|
</article>
|
|
<?php
|
|
}
|
|
wp_reset_postdata();
|
|
?>
|
|
</div>
|
|
</div>
|
|
<?php
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* EXAMPLE 5: Conditional comments display
|
|
*/
|
|
function example_maybe_show_comments() {
|
|
if (is_single() && roi_comments_enabled_for_posts()) {
|
|
comments_template();
|
|
} elseif (is_page() && roi_comments_enabled_for_pages()) {
|
|
comments_template();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* EXAMPLE 6: Featured image on single posts
|
|
*/
|
|
function example_display_featured_image() {
|
|
if (is_single() && roi_show_featured_image_single() && has_post_thumbnail()) {
|
|
?>
|
|
<div class="post-thumbnail">
|
|
<?php the_post_thumbnail('roi-featured-large'); ?>
|
|
</div>
|
|
<?php
|
|
}
|
|
}
|
|
|
|
/**
|
|
* EXAMPLE 7: Author box on single posts
|
|
*/
|
|
function example_display_author_box() {
|
|
if (is_single() && roi_show_author_box()) {
|
|
$author_id = get_the_author_meta('ID');
|
|
?>
|
|
<div class="author-box">
|
|
<div class="author-avatar">
|
|
<?php echo get_avatar($author_id, 80); ?>
|
|
</div>
|
|
<div class="author-info">
|
|
<h4 class="author-name"><?php the_author(); ?></h4>
|
|
<p class="author-bio"><?php the_author_meta('description'); ?></p>
|
|
<a href="<?php echo get_author_posts_url($author_id); ?>" class="author-link">
|
|
<?php _e('View all posts', 'roi-theme'); ?>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
<?php
|
|
}
|
|
}
|
|
|
|
/**
|
|
* EXAMPLE 8: Social media links in footer
|
|
*/
|
|
function example_display_social_links() {
|
|
$social_links = roi_get_social_links();
|
|
|
|
// Filter out empty links
|
|
$social_links = array_filter($social_links);
|
|
|
|
if (!empty($social_links)) {
|
|
?>
|
|
<div class="social-links">
|
|
<?php foreach ($social_links as $network => $url) : ?>
|
|
<a href="<?php echo esc_url($url); ?>"
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
class="social-link social-<?php echo esc_attr($network); ?>">
|
|
<span class="screen-reader-text"><?php echo ucfirst($network); ?></span>
|
|
<i class="icon-<?php echo esc_attr($network); ?>"></i>
|
|
</a>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php
|
|
}
|
|
}
|
|
|
|
/**
|
|
* EXAMPLE 9: Copyright text in footer
|
|
*/
|
|
function example_display_copyright() {
|
|
$copyright = roi_get_copyright_text();
|
|
|
|
if ($copyright) {
|
|
echo '<div class="copyright">' . wp_kses_post($copyright) . '</div>';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* EXAMPLE 10: Custom CSS in header
|
|
*/
|
|
function example_add_custom_css() {
|
|
$custom_css = roi_get_custom_css();
|
|
|
|
if ($custom_css) {
|
|
echo '<style type="text/css">' . "\n";
|
|
echo strip_tags($custom_css);
|
|
echo "\n</style>\n";
|
|
}
|
|
}
|
|
add_action('wp_head', 'example_add_custom_css', 100);
|
|
|
|
/**
|
|
* EXAMPLE 11: Custom JS in header
|
|
*/
|
|
function example_add_custom_js_header() {
|
|
$custom_js = roi_get_custom_js_header();
|
|
|
|
if ($custom_js) {
|
|
echo '<script type="text/javascript">' . "\n";
|
|
echo $custom_js;
|
|
echo "\n</script>\n";
|
|
}
|
|
}
|
|
add_action('wp_head', 'example_add_custom_js_header', 100);
|
|
|
|
/**
|
|
* EXAMPLE 12: Custom JS in footer
|
|
*/
|
|
function example_add_custom_js_footer() {
|
|
$custom_js = roi_get_custom_js_footer();
|
|
|
|
if ($custom_js) {
|
|
echo '<script type="text/javascript">' . "\n";
|
|
echo $custom_js;
|
|
echo "\n</script>\n";
|
|
}
|
|
}
|
|
add_action('wp_footer', 'example_add_custom_js_footer', 100);
|
|
|
|
/**
|
|
* EXAMPLE 13: Posts per page for archives
|
|
*/
|
|
function example_set_archive_posts_per_page($query) {
|
|
if ($query->is_archive() && !is_admin() && $query->is_main_query()) {
|
|
$posts_per_page = roi_get_archive_posts_per_page();
|
|
$query->set('posts_per_page', $posts_per_page);
|
|
}
|
|
}
|
|
add_action('pre_get_posts', 'example_set_archive_posts_per_page');
|
|
|
|
/**
|
|
* EXAMPLE 14: Performance optimizations
|
|
*/
|
|
function example_apply_performance_settings() {
|
|
// Remove emoji scripts
|
|
if (roi_is_performance_enabled('remove_emoji')) {
|
|
remove_action('wp_head', 'print_emoji_detection_script', 7);
|
|
remove_action('wp_print_styles', 'print_emoji_styles');
|
|
}
|
|
|
|
// Remove embeds
|
|
if (roi_is_performance_enabled('remove_embeds')) {
|
|
wp_deregister_script('wp-embed');
|
|
}
|
|
|
|
// Remove Dashicons for non-logged users
|
|
if (roi_is_performance_enabled('remove_dashicons') && !is_user_logged_in()) {
|
|
wp_deregister_style('dashicons');
|
|
}
|
|
}
|
|
add_action('wp_enqueue_scripts', 'example_apply_performance_settings', 100);
|
|
|
|
/**
|
|
* EXAMPLE 15: Lazy loading images
|
|
*/
|
|
function example_add_lazy_loading($attr, $attachment, $size) {
|
|
if (roi_is_lazy_loading_enabled()) {
|
|
$attr['loading'] = 'lazy';
|
|
}
|
|
return $attr;
|
|
}
|
|
add_filter('wp_get_attachment_image_attributes', 'example_add_lazy_loading', 10, 3);
|
|
|
|
/**
|
|
* EXAMPLE 16: Layout classes based on settings
|
|
*/
|
|
function example_get_layout_class() {
|
|
$layout = 'right-sidebar'; // default
|
|
|
|
if (is_single()) {
|
|
$layout = roi_get_default_post_layout();
|
|
} elseif (is_page()) {
|
|
$layout = roi_get_default_page_layout();
|
|
}
|
|
|
|
return 'layout-' . $layout;
|
|
}
|
|
|
|
/**
|
|
* EXAMPLE 17: Display post meta conditionally
|
|
*/
|
|
function example_display_post_meta() {
|
|
if (!roi_get_option('show_post_meta', true)) {
|
|
return;
|
|
}
|
|
|
|
?>
|
|
<div class="post-meta">
|
|
<span class="post-date">
|
|
<time datetime="<?php echo get_the_date('c'); ?>">
|
|
<?php echo get_the_date(roi_get_date_format()); ?>
|
|
</time>
|
|
</span>
|
|
<span class="post-author">
|
|
<?php the_author(); ?>
|
|
</span>
|
|
<?php if (roi_get_option('show_post_categories', true)) : ?>
|
|
<span class="post-categories">
|
|
<?php the_category(', '); ?>
|
|
</span>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php
|
|
}
|
|
|
|
/**
|
|
* EXAMPLE 18: Display post tags conditionally
|
|
*/
|
|
function example_display_post_tags() {
|
|
if (is_single() && roi_get_option('show_post_tags', true)) {
|
|
the_tags('<div class="post-tags">', ', ', '</div>');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* EXAMPLE 19: Get all options (for debugging)
|
|
*/
|
|
function example_debug_all_options() {
|
|
if (current_user_can('manage_options') && isset($_GET['debug_options'])) {
|
|
$all_options = roi_get_all_options();
|
|
echo '<pre>';
|
|
print_r($all_options);
|
|
echo '</pre>';
|
|
}
|
|
}
|
|
add_action('wp_footer', 'example_debug_all_options');
|
|
|
|
/**
|
|
* EXAMPLE 20: Check if specific feature is enabled
|
|
*/
|
|
function example_check_feature() {
|
|
// Multiple ways to check boolean options
|
|
|
|
// Method 1: Using helper function
|
|
if (roi_is_option_enabled('enable_breadcrumbs')) {
|
|
// Breadcrumbs are enabled
|
|
}
|
|
|
|
// Method 2: Using get_option with default
|
|
if (roi_get_option('enable_related_posts', true)) {
|
|
// Related posts are enabled
|
|
}
|
|
|
|
// Method 3: Direct check
|
|
$options = roi_get_all_options();
|
|
if (isset($options['enable_lazy_loading']) && $options['enable_lazy_loading']) {
|
|
// Lazy loading is enabled
|
|
}
|
|
}
|