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:
@@ -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')
|
||||
// =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user