refactor: Remove legacy roi_get_option() calls from Inc/ files

- Clean Inc/adsense-delay.php
- Clean Inc/category-badge.php
- Clean Inc/enqueue-scripts.php
- Clean Inc/featured-image.php
- Clean Inc/social-share.php
- Clean sidebar.php - use roi_render_component('table-of-contents')
- Add roi_get_component_setting() helper to functions-addon.php

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
FrankZamora
2025-11-26 21:58:44 -06:00
parent 7a8daa72c6
commit 8878afe168
7 changed files with 117 additions and 120 deletions

View File

@@ -26,10 +26,10 @@ function roi_delay_adsense_scripts() {
return;
}
// Verificar si el retardo de AdSense está habilitado en las opciones del tema
$delay_enabled = roi_get_option('roi_adsense_delay_enabled', '1');
// Verificar si el retardo de AdSense está habilitado (Clean Architecture)
$is_enabled = roi_get_component_setting('adsense-delay', 'visibility', 'is_enabled', true);
if ($delay_enabled !== '1') {
if (!$is_enabled) {
return;
}
@@ -106,9 +106,10 @@ function roi_replace_adsense_scripts($html) {
* después de que adsense-loader.js ha sido enqueued.
*/
function roi_add_adsense_init_script() {
$delay_enabled = roi_get_option('roi_adsense_delay_enabled', '1');
// Verificar si el retardo de AdSense está habilitado (Clean Architecture)
$is_enabled = roi_get_component_setting('adsense-delay', 'visibility', 'is_enabled', true);
if ($delay_enabled !== '1' || is_admin()) {
if (!$is_enabled || is_admin()) {
return;
}

View File

@@ -24,9 +24,9 @@ if (!defined('ABSPATH')) {
* @return string HTML del badge de categoría o string vacío
*/
function roi_get_category_badge() {
// Verificar si la función está habilitada en las opciones del tema
$enabled = roi_get_option('show_category_badge', true);
if (!$enabled) {
// Verificar si la función está habilitada (Clean Architecture)
$is_enabled = roi_get_component_setting('category-badge', 'visibility', 'is_enabled', true);
if (!$is_enabled) {
return '';
}

View File

@@ -361,10 +361,10 @@ function roi_enqueue_adsense_loader() {
return;
}
// Verificar si el retardo de AdSense está habilitado
$delay_enabled = roi_get_option('roi_adsense_delay_enabled', '1');
// Verificar si el retardo de AdSense está habilitado (Clean Architecture)
$is_enabled = roi_get_component_setting('adsense-delay', 'visibility', 'is_enabled', true);
if ($delay_enabled !== '1') {
if (!$is_enabled) {
return;
}

View File

@@ -53,26 +53,24 @@ function roi_get_featured_image($post_id = null, $size = 'roi-featured-large', $
// Obtener tipo de post
$post_type = get_post_type($post_id);
// Verificar configuración global según tipo de contenido
// Verificar configuración global desde BD (Clean Architecture)
if (!$force_show) {
// Primero intentar con roi_get_option (sistema de opciones del tema)
if (function_exists('roi_get_option')) {
if ($post_type === 'post') {
$enabled = roi_get_option('featured_image_single', true);
} elseif ($post_type === 'page') {
$enabled = roi_get_option('featured_image_page', true);
} else {
$enabled = roi_get_option('featured_image_' . $post_type, true);
}
} else {
// Fallback a theme_mod
$option_key = 'roi_featured_image_' . $post_type;
$enabled = get_theme_mod($option_key, true);
}
// Leer configuración desde wp_roi_theme_component_settings
$is_enabled = roi_get_component_setting('featured-image', 'visibility', 'is_enabled', true);
$show_on_pages = roi_get_component_setting('featured-image', 'visibility', 'show_on_pages', 'posts');
if (!$enabled) {
if (!$is_enabled) {
return '';
}
// Verificar tipo de contenido según configuración
if ($show_on_pages === 'posts' && $post_type !== 'post') {
return '';
}
if ($show_on_pages === 'pages' && $post_type !== 'page') {
return '';
}
// 'all' = mostrar en todo
}
// Atributos por defecto con Bootstrap img-fluid
@@ -292,22 +290,23 @@ function roi_should_show_featured_image($post_id = null) {
// Obtener tipo de post
$post_type = get_post_type($post_id);
// Verificar configuración global según tipo de contenido
if (function_exists('roi_get_option')) {
if ($post_type === 'post') {
$enabled = roi_get_option('featured_image_single', true);
} elseif ($post_type === 'page') {
$enabled = roi_get_option('featured_image_page', true);
} else {
$enabled = roi_get_option('featured_image_' . $post_type, true);
}
} else {
// Fallback a theme_mod
$option_key = 'roi_featured_image_' . $post_type;
$enabled = get_theme_mod($option_key, true);
// Leer configuración desde BD (Clean Architecture)
$is_enabled = roi_get_component_setting('featured-image', 'visibility', 'is_enabled', true);
$show_on_pages = roi_get_component_setting('featured-image', 'visibility', 'show_on_pages', 'posts');
if (!$is_enabled) {
return false;
}
return (bool) $enabled;
// Verificar tipo de contenido según configuración
if ($show_on_pages === 'posts' && $post_type !== 'post') {
return false;
}
if ($show_on_pages === 'pages' && $post_type !== 'page') {
return false;
}
return true;
}
/**
@@ -394,7 +393,7 @@ function roi_the_featured_image_responsive($post_id = null, $size = 'roi-feature
/**
* Verifica si las imágenes destacadas están habilitadas para un tipo de post
*
* Función legacy mantenida por compatibilidad.
* Lee configuración desde BD (Clean Architecture)
*
* @param string $post_type Tipo de post (vacío = post actual)
* @return bool True si habilitadas, false en caso contrario
@@ -408,71 +407,28 @@ function roi_is_featured_image_enabled($post_type = '') {
return true; // Default habilitado
}
// Intentar con roi_get_option primero
if (function_exists('roi_get_option')) {
if ($post_type === 'post') {
return roi_get_option('featured_image_single', true);
} elseif ($post_type === 'page') {
return roi_get_option('featured_image_page', true);
} else {
return roi_get_option('featured_image_' . $post_type, true);
}
// Leer configuración desde BD (Clean Architecture)
$is_enabled = roi_get_component_setting('featured-image', 'visibility', 'is_enabled', true);
$show_on_pages = roi_get_component_setting('featured-image', 'visibility', 'show_on_pages', 'posts');
if (!$is_enabled) {
return false;
}
// Fallback a theme_mod
$option_key = 'roi_featured_image_' . $post_type;
return (bool) get_theme_mod($option_key, true);
// Verificar tipo de contenido según configuración
if ($show_on_pages === 'posts' && $post_type !== 'post') {
return false;
}
if ($show_on_pages === 'pages' && $post_type !== 'page') {
return false;
}
return true;
}
/**
* Registra configuración de imágenes destacadas en Customizer
*
* Agrega controles para habilitar/deshabilitar imágenes destacadas por tipo de post.
* Funciona como fallback si no hay panel de opciones del tema.
*
* @param WP_Customize_Manager $wp_customize Objeto Theme Customizer
*/
function roi_featured_image_customizer($wp_customize) {
// Solo agregar si no existe el panel de opciones del tema
if (function_exists('roi_get_option')) {
return; // El panel de opciones manejará esto
}
// Agregar sección
$wp_customize->add_section('roi_featured_images', array(
'title' => __('Imágenes Destacadas', 'roi-theme'),
'description' => __('Configurar visualización de imágenes destacadas por tipo de contenido.', 'roi-theme'),
'priority' => 30,
));
// Obtener tipos de post públicos
$post_types = get_post_types(array('public' => true), 'objects');
foreach ($post_types as $post_type) {
// Saltar attachments
if ($post_type->name === 'attachment') {
continue;
}
$setting_id = 'roi_featured_image_' . $post_type->name;
// Agregar setting
$wp_customize->add_setting($setting_id, array(
'default' => true,
'sanitize_callback' => 'wp_validate_boolean',
'transport' => 'refresh',
));
// Agregar control
$wp_customize->add_control($setting_id, array(
'label' => sprintf(
/* translators: %s: nombre del tipo de post */
__('Habilitar para %s', 'roi-theme'),
$post_type->labels->name
),
'section' => 'roi_featured_images',
'type' => 'checkbox',
));
}
}
add_action('customize_register', 'roi_featured_image_customizer');
// =============================================================================
// NOTA: Customizer eliminado - Clean Architecture
// La configuración de imágenes destacadas se gestiona desde:
// - Admin Panel: Admin/FeaturedImage/Infrastructure/Ui/FeaturedImageFormBuilder.php
// - Base de datos: wp_roi_theme_component_settings (component_name = 'featured-image')
// =============================================================================

View File

@@ -44,8 +44,8 @@ function roi_get_social_share_buttons( $post_id = 0 ) {
$whatsapp_url = 'https://api.whatsapp.com/send?text=' . $post_title_encoded . '%20' . $post_url_encoded;
$email_url = 'mailto:?subject=' . $post_title_encoded . '&body=' . $post_url_encoded;
// Obtener texto de compartir desde las opciones del tema
$share_text = roi_get_option( 'roi_share_text', __( 'Compartir:', 'roi-theme' ) );
// Obtener texto de compartir desde BD (Clean Architecture)
$share_text = roi_get_component_setting( 'social-share', 'content', 'share_text', __( 'Compartir:', 'roi-theme' ) );
// Construir el HTML
ob_start();
@@ -116,9 +116,9 @@ function roi_display_social_share( $post_id = 0 ) {
return;
}
// Verificar si los botones de compartir están habilitados
$enable_share = roi_get_option( 'roi_enable_share_buttons', '1' );
if ( $enable_share !== '1' ) {
// Verificar si los botones de compartir están habilitados (Clean Architecture)
$is_enabled = roi_get_component_setting( 'social-share', 'visibility', 'is_enabled', true );
if ( !$is_enabled ) {
return;
}