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:
@@ -26,6 +26,52 @@ spl_autoload_register(function ($class) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// =============================================================================
|
||||||
|
// HELPER FUNCTION: roi_get_component_setting() - GENÉRICA
|
||||||
|
// =============================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtiene un valor de configuración de cualquier componente desde la BD
|
||||||
|
*
|
||||||
|
* Reemplaza a roi_get_option() legacy - lee de wp_roi_theme_component_settings
|
||||||
|
*
|
||||||
|
* @param string $component Nombre del componente (ej: 'featured-image', 'navbar')
|
||||||
|
* @param string $group Nombre del grupo (ej: 'visibility', 'content')
|
||||||
|
* @param string $attribute Nombre del atributo (ej: 'is_enabled', 'show_on_pages')
|
||||||
|
* @param mixed $default Valor por defecto si no existe
|
||||||
|
* @return mixed Valor del atributo
|
||||||
|
*/
|
||||||
|
function roi_get_component_setting(string $component, string $group, string $attribute, $default = null) {
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
$table = $wpdb->prefix . 'roi_theme_component_settings';
|
||||||
|
$value = $wpdb->get_var($wpdb->prepare(
|
||||||
|
"SELECT attribute_value FROM {$table}
|
||||||
|
WHERE component_name = %s
|
||||||
|
AND group_name = %s
|
||||||
|
AND attribute_name = %s",
|
||||||
|
$component,
|
||||||
|
$group,
|
||||||
|
$attribute
|
||||||
|
));
|
||||||
|
|
||||||
|
if ($value === null) {
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convertir booleanos
|
||||||
|
if ($value === '1') return true;
|
||||||
|
if ($value === '0') return false;
|
||||||
|
|
||||||
|
// Intentar decodificar JSON
|
||||||
|
$decoded = json_decode($value, true);
|
||||||
|
if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) {
|
||||||
|
return $decoded;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
// HELPER FUNCTION: roi_get_navbar_setting()
|
// HELPER FUNCTION: roi_get_navbar_setting()
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ function roi_delay_adsense_scripts() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verificar si el retardo de AdSense está habilitado en las opciones del tema
|
// Verificar si el retardo de AdSense está habilitado (Clean Architecture)
|
||||||
$delay_enabled = roi_get_option('roi_adsense_delay_enabled', '1');
|
$is_enabled = roi_get_component_setting('adsense-delay', 'visibility', 'is_enabled', true);
|
||||||
|
|
||||||
if ($delay_enabled !== '1') {
|
if (!$is_enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,9 +106,10 @@ function roi_replace_adsense_scripts($html) {
|
|||||||
* después de que adsense-loader.js ha sido enqueued.
|
* después de que adsense-loader.js ha sido enqueued.
|
||||||
*/
|
*/
|
||||||
function roi_add_adsense_init_script() {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ if (!defined('ABSPATH')) {
|
|||||||
* @return string HTML del badge de categoría o string vacío
|
* @return string HTML del badge de categoría o string vacío
|
||||||
*/
|
*/
|
||||||
function roi_get_category_badge() {
|
function roi_get_category_badge() {
|
||||||
// Verificar si la función está habilitada en las opciones del tema
|
// Verificar si la función está habilitada (Clean Architecture)
|
||||||
$enabled = roi_get_option('show_category_badge', true);
|
$is_enabled = roi_get_component_setting('category-badge', 'visibility', 'is_enabled', true);
|
||||||
if (!$enabled) {
|
if (!$is_enabled) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -361,10 +361,10 @@ function roi_enqueue_adsense_loader() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verificar si el retardo de AdSense está habilitado
|
// Verificar si el retardo de AdSense está habilitado (Clean Architecture)
|
||||||
$delay_enabled = roi_get_option('roi_adsense_delay_enabled', '1');
|
$is_enabled = roi_get_component_setting('adsense-delay', 'visibility', 'is_enabled', true);
|
||||||
|
|
||||||
if ($delay_enabled !== '1') {
|
if (!$is_enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,26 +53,24 @@ function roi_get_featured_image($post_id = null, $size = 'roi-featured-large', $
|
|||||||
// Obtener tipo de post
|
// Obtener tipo de post
|
||||||
$post_type = get_post_type($post_id);
|
$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) {
|
if (!$force_show) {
|
||||||
// Primero intentar con roi_get_option (sistema de opciones del tema)
|
// Leer configuración desde wp_roi_theme_component_settings
|
||||||
if (function_exists('roi_get_option')) {
|
$is_enabled = roi_get_component_setting('featured-image', 'visibility', 'is_enabled', true);
|
||||||
if ($post_type === 'post') {
|
$show_on_pages = roi_get_component_setting('featured-image', 'visibility', 'show_on_pages', 'posts');
|
||||||
$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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$enabled) {
|
if (!$is_enabled) {
|
||||||
return '';
|
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
|
// Atributos por defecto con Bootstrap img-fluid
|
||||||
@@ -292,22 +290,23 @@ function roi_should_show_featured_image($post_id = null) {
|
|||||||
// Obtener tipo de post
|
// Obtener tipo de post
|
||||||
$post_type = get_post_type($post_id);
|
$post_type = get_post_type($post_id);
|
||||||
|
|
||||||
// Verificar configuración global según tipo de contenido
|
// Leer configuración desde BD (Clean Architecture)
|
||||||
if (function_exists('roi_get_option')) {
|
$is_enabled = roi_get_component_setting('featured-image', 'visibility', 'is_enabled', true);
|
||||||
if ($post_type === 'post') {
|
$show_on_pages = roi_get_component_setting('featured-image', 'visibility', 'show_on_pages', 'posts');
|
||||||
$enabled = roi_get_option('featured_image_single', true);
|
|
||||||
} elseif ($post_type === 'page') {
|
if (!$is_enabled) {
|
||||||
$enabled = roi_get_option('featured_image_page', true);
|
return false;
|
||||||
} 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
* 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)
|
* @param string $post_type Tipo de post (vacío = post actual)
|
||||||
* @return bool True si habilitadas, false en caso contrario
|
* @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
|
return true; // Default habilitado
|
||||||
}
|
}
|
||||||
|
|
||||||
// Intentar con roi_get_option primero
|
// Leer configuración desde BD (Clean Architecture)
|
||||||
if (function_exists('roi_get_option')) {
|
$is_enabled = roi_get_component_setting('featured-image', 'visibility', 'is_enabled', true);
|
||||||
if ($post_type === 'post') {
|
$show_on_pages = roi_get_component_setting('featured-image', 'visibility', 'show_on_pages', 'posts');
|
||||||
return roi_get_option('featured_image_single', true);
|
|
||||||
} elseif ($post_type === 'page') {
|
if (!$is_enabled) {
|
||||||
return roi_get_option('featured_image_page', true);
|
return false;
|
||||||
} else {
|
|
||||||
return roi_get_option('featured_image_' . $post_type, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback a theme_mod
|
// Verificar tipo de contenido según configuración
|
||||||
$option_key = 'roi_featured_image_' . $post_type;
|
if ($show_on_pages === 'posts' && $post_type !== 'post') {
|
||||||
return (bool) get_theme_mod($option_key, true);
|
return false;
|
||||||
|
}
|
||||||
|
if ($show_on_pages === 'pages' && $post_type !== 'page') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// =============================================================================
|
||||||
* Registra configuración de imágenes destacadas en Customizer
|
// NOTA: Customizer eliminado - Clean Architecture
|
||||||
*
|
// La configuración de imágenes destacadas se gestiona desde:
|
||||||
* Agrega controles para habilitar/deshabilitar imágenes destacadas por tipo de post.
|
// - Admin Panel: Admin/FeaturedImage/Infrastructure/Ui/FeaturedImageFormBuilder.php
|
||||||
* Funciona como fallback si no hay panel de opciones del tema.
|
// - Base de datos: wp_roi_theme_component_settings (component_name = 'featured-image')
|
||||||
*
|
// =============================================================================
|
||||||
* @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');
|
|
||||||
|
|||||||
@@ -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;
|
$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;
|
$email_url = 'mailto:?subject=' . $post_title_encoded . '&body=' . $post_url_encoded;
|
||||||
|
|
||||||
// Obtener texto de compartir desde las opciones del tema
|
// Obtener texto de compartir desde BD (Clean Architecture)
|
||||||
$share_text = roi_get_option( 'roi_share_text', __( 'Compartir:', 'roi-theme' ) );
|
$share_text = roi_get_component_setting( 'social-share', 'content', 'share_text', __( 'Compartir:', 'roi-theme' ) );
|
||||||
|
|
||||||
// Construir el HTML
|
// Construir el HTML
|
||||||
ob_start();
|
ob_start();
|
||||||
@@ -116,9 +116,9 @@ function roi_display_social_share( $post_id = 0 ) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verificar si los botones de compartir están habilitados
|
// Verificar si los botones de compartir están habilitados (Clean Architecture)
|
||||||
$enable_share = roi_get_option( 'roi_enable_share_buttons', '1' );
|
$is_enabled = roi_get_component_setting( 'social-share', 'visibility', 'is_enabled', true );
|
||||||
if ( $enable_share !== '1' ) {
|
if ( !$is_enabled ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
sidebar.php
12
sidebar.php
@@ -20,16 +20,10 @@ if ( ! is_active_sidebar( 'sidebar-1' ) ) {
|
|||||||
/**
|
/**
|
||||||
* Display Table of Contents (TOC) on single posts
|
* Display Table of Contents (TOC) on single posts
|
||||||
* Issue #86 - TOC should be displayed in sidebar
|
* Issue #86 - TOC should be displayed in sidebar
|
||||||
|
* Clean Architecture: Usa TableOfContentsRenderer
|
||||||
*/
|
*/
|
||||||
if (is_single() && function_exists('roi_extract_headings') && function_exists('roi_generate_toc')) {
|
if (is_single() && function_exists('roi_render_component')) {
|
||||||
global $post;
|
echo roi_render_component('table-of-contents'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
if (!empty($post->post_content)) {
|
|
||||||
$headings = roi_extract_headings($post->post_content);
|
|
||||||
$toc_html = roi_generate_toc($headings);
|
|
||||||
if (!empty($toc_html)) {
|
|
||||||
echo $toc_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user