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,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()
// =============================================================================