chore: Remove legacy theme options files
BREAKING: Remove deprecated files replaced by Clean Architecture - Remove Inc/theme-options-helpers.php (replaced by roi_get_component_setting) - Remove Inc/theme-settings.php (replaced by ThemeSettingsInjector) - Remove Inc/customizer-fonts.php (fonts now in navbar component) - Remove Inc/toc.php (replaced by TableOfContentsRenderer) - Update functions.php - remove require_once for deleted files 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -36,10 +36,10 @@ require_once __DIR__ . '/functions-addon.php';
|
||||
// para que los estilos y scripts se registren correctamente
|
||||
|
||||
require_once get_template_directory() . '/Inc/sanitize-functions.php';
|
||||
require_once get_template_directory() . '/Inc/theme-options-helpers.php';
|
||||
// ELIMINADO: Inc/theme-options-helpers.php (FASE 6 - Clean Architecture)
|
||||
require_once get_template_directory() . '/Inc/nav-walker.php';
|
||||
require_once get_template_directory() . '/Inc/enqueue-scripts.php';
|
||||
require_once get_template_directory() . '/Inc/customizer-fonts.php';
|
||||
// ELIMINADO: Inc/customizer-fonts.php (FASE 6 - Clean Architecture)
|
||||
require_once get_template_directory() . '/Inc/seo.php';
|
||||
require_once get_template_directory() . '/Inc/performance.php';
|
||||
require_once get_template_directory() . '/Inc/critical-css.php';
|
||||
@@ -50,7 +50,7 @@ require_once get_template_directory() . '/Inc/featured-image.php';
|
||||
require_once get_template_directory() . '/Inc/category-badge.php';
|
||||
require_once get_template_directory() . '/Inc/adsense-delay.php';
|
||||
require_once get_template_directory() . '/Inc/related-posts.php';
|
||||
require_once get_template_directory() . '/Inc/toc.php';
|
||||
// ELIMINADO: Inc/toc.php (FASE 6 - Clean Architecture: usa TableOfContentsRenderer)
|
||||
require_once get_template_directory() . '/Inc/apu-tables.php';
|
||||
require_once get_template_directory() . '/Inc/search-disable.php';
|
||||
require_once get_template_directory() . '/Inc/comments-disable.php';
|
||||
@@ -148,6 +148,14 @@ try {
|
||||
);
|
||||
$newsletterAjaxHandler->register();
|
||||
|
||||
// Crear y registrar el inyector de Theme Settings (GA, Custom CSS/JS)
|
||||
$themeSettingsRenderer = new \ROITheme\Public\ThemeSettings\Infrastructure\Ui\ThemeSettingsRenderer();
|
||||
$themeSettingsInjector = new \ROITheme\Public\ThemeSettings\Infrastructure\Services\ThemeSettingsInjector(
|
||||
$container->getComponentSettingsRepository(),
|
||||
$themeSettingsRenderer
|
||||
);
|
||||
$themeSettingsInjector->register();
|
||||
|
||||
// Log en modo debug
|
||||
if (defined('WP_DEBUG') && WP_DEBUG) {
|
||||
error_log('ROI Theme: Admin Panel initialized successfully');
|
||||
|
||||
@@ -1,145 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Font Options for Theme Customizer
|
||||
*
|
||||
* @package ROI_Theme
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register font settings in the Customizer
|
||||
*/
|
||||
function roi_customize_register_fonts($wp_customize) {
|
||||
|
||||
// Add Typography Section
|
||||
$wp_customize->add_section('roi_typography', array(
|
||||
'title' => __('Typography', 'roi-theme'),
|
||||
'description' => __('Configure font settings for your site.', 'roi-theme'),
|
||||
'priority' => 30,
|
||||
));
|
||||
|
||||
// Setting: Use Custom Fonts
|
||||
$wp_customize->add_setting('roi_use_custom_fonts', array(
|
||||
'default' => false,
|
||||
'sanitize_callback' => 'roi_sanitize_checkbox',
|
||||
'transport' => 'refresh',
|
||||
));
|
||||
|
||||
$wp_customize->add_control('roi_use_custom_fonts', array(
|
||||
'label' => __('Use Custom Fonts', 'roi-theme'),
|
||||
'description' => __('Enable custom fonts instead of system fonts. System fonts load faster and improve Core Web Vitals.', 'roi-theme'),
|
||||
'section' => 'roi_typography',
|
||||
'type' => 'checkbox',
|
||||
));
|
||||
|
||||
// Setting: Font Loading Strategy (only if custom fonts enabled)
|
||||
$wp_customize->add_setting('roi_font_display', array(
|
||||
'default' => 'swap',
|
||||
'sanitize_callback' => 'roi_sanitize_select',
|
||||
'transport' => 'refresh',
|
||||
));
|
||||
|
||||
$wp_customize->add_control('roi_font_display', array(
|
||||
'label' => __('Font Display Strategy', 'roi-theme'),
|
||||
'description' => __('Controls how fonts are displayed during loading. "swap" is recommended for best performance.', 'roi-theme'),
|
||||
'section' => 'roi_typography',
|
||||
'type' => 'select',
|
||||
'choices' => array(
|
||||
'auto' => __('Auto', 'roi-theme'),
|
||||
'block' => __('Block', 'roi-theme'),
|
||||
'swap' => __('Swap (Recommended)', 'roi-theme'),
|
||||
'fallback' => __('Fallback', 'roi-theme'),
|
||||
'optional' => __('Optional', 'roi-theme'),
|
||||
),
|
||||
'active_callback' => 'roi_is_custom_fonts_enabled',
|
||||
));
|
||||
|
||||
// Setting: Preload Fonts
|
||||
$wp_customize->add_setting('roi_preload_fonts', array(
|
||||
'default' => true,
|
||||
'sanitize_callback' => 'roi_sanitize_checkbox',
|
||||
'transport' => 'refresh',
|
||||
));
|
||||
|
||||
$wp_customize->add_control('roi_preload_fonts', array(
|
||||
'label' => __('Preload Font Files', 'roi-theme'),
|
||||
'description' => __('Preload critical font files for faster rendering. Recommended for better LCP scores.', 'roi-theme'),
|
||||
'section' => 'roi_typography',
|
||||
'type' => 'checkbox',
|
||||
'active_callback' => 'roi_is_custom_fonts_enabled',
|
||||
));
|
||||
}
|
||||
|
||||
add_action('customize_register', 'roi_customize_register_fonts');
|
||||
|
||||
/**
|
||||
* Check if custom fonts are enabled
|
||||
*/
|
||||
function roi_is_custom_fonts_enabled() {
|
||||
return get_theme_mod('roi_use_custom_fonts', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add body class based on font settings
|
||||
*/
|
||||
function roi_font_body_class($classes) {
|
||||
if (roi_is_custom_fonts_enabled()) {
|
||||
$classes[] = 'use-custom-fonts';
|
||||
} else {
|
||||
$classes[] = 'use-system-fonts';
|
||||
}
|
||||
return $classes;
|
||||
}
|
||||
|
||||
add_filter('body_class', 'roi_font_body_class');
|
||||
|
||||
/**
|
||||
* Add preload links for custom fonts
|
||||
*/
|
||||
function roi_preload_custom_fonts() {
|
||||
// Only preload if custom fonts are enabled and preload is enabled
|
||||
if (!roi_is_custom_fonts_enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!get_theme_mod('roi_preload_fonts', true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Example preload links - uncomment and modify when you have custom font files
|
||||
/*
|
||||
?>
|
||||
<link rel="preload" href="<?php echo esc_url(get_template_directory_uri() . '/Assets/fonts/CustomSans-Regular.woff2'); ?>" as="font" type="font/woff2" crossorigin>
|
||||
<link rel="preload" href="<?php echo esc_url(get_template_directory_uri() . '/Assets/fonts/CustomSans-Bold.woff2'); ?>" as="font" type="font/woff2" crossorigin>
|
||||
<?php
|
||||
*/
|
||||
}
|
||||
|
||||
add_action('wp_head', 'roi_preload_custom_fonts', 1);
|
||||
|
||||
/**
|
||||
* Output inline CSS for font display strategy
|
||||
*/
|
||||
function roi_output_font_display_css() {
|
||||
if (!roi_is_custom_fonts_enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$font_display = get_theme_mod('roi_font_display', 'swap');
|
||||
|
||||
// This would be used if you have actual @font-face declarations
|
||||
// For now, it's just a placeholder for future implementation
|
||||
?>
|
||||
<style id="roi-font-display-strategy">
|
||||
/* Font display strategy: <?php echo esc_attr($font_display); ?> */
|
||||
/* This would contain dynamic @font-face rules when custom fonts are added */
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
|
||||
add_action('wp_head', 'roi_output_font_display_css', 5);
|
||||
@@ -1,345 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Theme Options Helper Functions
|
||||
*
|
||||
* @package ROI_Theme
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get theme option value
|
||||
*
|
||||
* @param string $option_name The option name
|
||||
* @param mixed $default Default value if option doesn't exist
|
||||
* @return mixed The option value
|
||||
*/
|
||||
function roi_get_option($option_name, $default = '') {
|
||||
$options = get_option('roi_theme_options', array());
|
||||
|
||||
if (isset($options[$option_name])) {
|
||||
return $options[$option_name];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if option is enabled (checkbox/switch)
|
||||
*
|
||||
* @param string $option_name The option name
|
||||
* @return bool True if enabled, false otherwise
|
||||
*/
|
||||
function roi_is_option_enabled($option_name) {
|
||||
return (bool) roi_get_option($option_name, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get breadcrumbs separator
|
||||
*
|
||||
* @return string The separator
|
||||
*/
|
||||
function roi_get_breadcrumb_separator() {
|
||||
return roi_get_option('breadcrumb_separator', '>');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if breadcrumbs should be shown
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function roi_show_breadcrumbs() {
|
||||
return roi_is_option_enabled('enable_breadcrumbs');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get excerpt length
|
||||
*
|
||||
* @return int The excerpt length
|
||||
*/
|
||||
function roi_get_excerpt_length() {
|
||||
return (int) roi_get_option('excerpt_length', 55);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get excerpt more text
|
||||
*
|
||||
* @return string The excerpt more text
|
||||
*/
|
||||
function roi_get_excerpt_more() {
|
||||
return roi_get_option('excerpt_more', '...');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if related posts should be shown
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function roi_show_related_posts() {
|
||||
return roi_is_option_enabled('enable_related_posts');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of related posts to show
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function roi_get_related_posts_count() {
|
||||
return (int) roi_get_option('related_posts_count', 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get related posts taxonomy
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_related_posts_taxonomy() {
|
||||
return roi_get_option('related_posts_taxonomy', 'category');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get related posts title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_related_posts_title() {
|
||||
return roi_get_option('related_posts_title', __('Related Posts', 'roi-theme'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if specific performance optimization is enabled
|
||||
*
|
||||
* @param string $optimization The optimization name
|
||||
* @return bool
|
||||
*/
|
||||
function roi_is_performance_enabled($optimization) {
|
||||
return roi_is_option_enabled('performance_' . $optimization);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get copyright text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_copyright_text() {
|
||||
$default = sprintf(
|
||||
__('© %s %s. All rights reserved.', 'roi-theme'),
|
||||
date('Y'),
|
||||
get_bloginfo('name')
|
||||
);
|
||||
return roi_get_option('copyright_text', $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get social media links
|
||||
*
|
||||
* @return array Array of social media links
|
||||
*/
|
||||
function roi_get_social_links() {
|
||||
return array(
|
||||
'facebook' => roi_get_option('social_facebook', ''),
|
||||
'twitter' => roi_get_option('social_twitter', ''),
|
||||
'instagram' => roi_get_option('social_instagram', ''),
|
||||
'linkedin' => roi_get_option('social_linkedin', ''),
|
||||
'youtube' => roi_get_option('social_youtube', ''),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if comments are enabled for posts
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function roi_comments_enabled_for_posts() {
|
||||
return roi_is_option_enabled('enable_comments_posts');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if comments are enabled for pages
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function roi_comments_enabled_for_pages() {
|
||||
return roi_is_option_enabled('enable_comments_pages');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default post layout
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_default_post_layout() {
|
||||
return roi_get_option('default_post_layout', 'right-sidebar');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default page layout
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_default_page_layout() {
|
||||
return roi_get_option('default_page_layout', 'right-sidebar');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get posts per page for archive
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function roi_get_archive_posts_per_page() {
|
||||
$custom = (int) roi_get_option('archive_posts_per_page', 0);
|
||||
return $custom > 0 ? $custom : get_option('posts_per_page', 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if featured image should be shown on single posts
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function roi_show_featured_image_single() {
|
||||
return roi_is_option_enabled('show_featured_image_single');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if author box should be shown on single posts
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function roi_show_author_box() {
|
||||
return roi_is_option_enabled('show_author_box');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get date format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_date_format() {
|
||||
return roi_get_option('date_format', 'd/m/Y');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get time format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_time_format() {
|
||||
return roi_get_option('time_format', 'H:i');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get logo URL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_logo_url() {
|
||||
$logo_id = roi_get_option('site_logo', 0);
|
||||
if ($logo_id) {
|
||||
$logo = wp_get_attachment_image_url($logo_id, 'full');
|
||||
if ($logo) {
|
||||
return $logo;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get favicon URL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_favicon_url() {
|
||||
$favicon_id = roi_get_option('site_favicon', 0);
|
||||
if ($favicon_id) {
|
||||
$favicon = wp_get_attachment_image_url($favicon_id, 'full');
|
||||
if ($favicon) {
|
||||
return $favicon;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom CSS
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_custom_css() {
|
||||
return roi_get_option('custom_css', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom JS (header)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_custom_js_header() {
|
||||
return roi_get_option('custom_js_header', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom JS (footer)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_custom_js_footer() {
|
||||
return roi_get_option('custom_js_footer', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if lazy loading is enabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function roi_is_lazy_loading_enabled() {
|
||||
return roi_is_option_enabled('enable_lazy_loading');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all theme options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function roi_get_all_options() {
|
||||
return get_option('roi_theme_options', array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset theme options to defaults
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function roi_reset_options() {
|
||||
return delete_option('roi_theme_options');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Table of Contents is enabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function roi_is_toc_enabled() {
|
||||
return roi_get_option('enable_toc', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get minimum headings required to display TOC
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function roi_get_toc_min_headings() {
|
||||
return (int) roi_get_option('toc_min_headings', 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get TOC title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_toc_title() {
|
||||
return roi_get_option('toc_title', __('Table of Contents', 'roi-theme'));
|
||||
}
|
||||
@@ -1,418 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Theme Settings Helper Functions
|
||||
*
|
||||
* Funciones helper para leer configuraciones del tema desde la tabla personalizada
|
||||
*
|
||||
* @package ROI_Theme
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get theme setting value from custom table
|
||||
*
|
||||
* @param string $setting_name The setting name
|
||||
* @param mixed $default Default value if setting doesn't exist
|
||||
* @return mixed The setting value
|
||||
*/
|
||||
function roi_get_setting($setting_name, $default = '') {
|
||||
// Cache estático para optimizar performance
|
||||
static $db_manager = null;
|
||||
static $settings_cache = null;
|
||||
|
||||
// Inicializar DB Manager una sola vez
|
||||
if ($db_manager === null) {
|
||||
$db_manager = new ROI_DB_Manager();
|
||||
}
|
||||
|
||||
// Cargar todas las configuraciones una sola vez por request
|
||||
if ($settings_cache === null) {
|
||||
$settings_cache = $db_manager->get_config('theme');
|
||||
|
||||
// Si no hay configuraciones en la tabla, intentar desde wp_options
|
||||
// (backward compatibility durante migración)
|
||||
if (empty($settings_cache)) {
|
||||
$settings_cache = get_option('roi_theme_options', array());
|
||||
}
|
||||
}
|
||||
|
||||
// Retornar valor específico
|
||||
if (isset($settings_cache[$setting_name])) {
|
||||
return $settings_cache[$setting_name];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get theme option value (ALIAS for backward compatibility)
|
||||
*
|
||||
* @deprecated 2.0.0 Use roi_get_setting() instead
|
||||
* @param string $option_name The option name
|
||||
* @param mixed $default Default value if option doesn't exist
|
||||
* @return mixed The option value
|
||||
*/
|
||||
function roi_get_option($option_name, $default = '') {
|
||||
return roi_get_setting($option_name, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if setting is enabled (checkbox/switch)
|
||||
*
|
||||
* @param string $setting_name The setting name
|
||||
* @return bool True if enabled, false otherwise
|
||||
*/
|
||||
function roi_is_setting_enabled($setting_name) {
|
||||
return (bool) roi_get_setting($setting_name, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if option is enabled (ALIAS for backward compatibility)
|
||||
*
|
||||
* @deprecated 2.0.0 Use roi_is_setting_enabled() instead
|
||||
* @param string $option_name The option name
|
||||
* @return bool True if enabled, false otherwise
|
||||
*/
|
||||
function roi_is_option_enabled($option_name) {
|
||||
return roi_is_setting_enabled($option_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get breadcrumbs separator
|
||||
*
|
||||
* @return string The separator
|
||||
*/
|
||||
function roi_get_breadcrumb_separator() {
|
||||
return roi_get_setting('breadcrumb_separator', '>');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if breadcrumbs should be shown
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function roi_show_breadcrumbs() {
|
||||
return roi_is_setting_enabled('enable_breadcrumbs');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get excerpt length
|
||||
*
|
||||
* @return int The excerpt length
|
||||
*/
|
||||
function roi_get_excerpt_length() {
|
||||
return (int) roi_get_setting('excerpt_length', 55);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get excerpt more text
|
||||
*
|
||||
* @return string The excerpt more text
|
||||
*/
|
||||
function roi_get_excerpt_more() {
|
||||
return roi_get_setting('excerpt_more', '...');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if related posts should be shown
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function roi_show_related_posts() {
|
||||
return roi_is_setting_enabled('enable_related_posts');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of related posts to show
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function roi_get_related_posts_count() {
|
||||
return (int) roi_get_setting('related_posts_count', 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get related posts taxonomy
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_related_posts_taxonomy() {
|
||||
return roi_get_setting('related_posts_taxonomy', 'category');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get related posts title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_related_posts_title() {
|
||||
return roi_get_setting('related_posts_title', __('Related Posts', 'roi-theme'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if specific performance optimization is enabled
|
||||
*
|
||||
* @param string $optimization The optimization name
|
||||
* @return bool
|
||||
*/
|
||||
function roi_is_performance_enabled($optimization) {
|
||||
return roi_is_setting_enabled('performance_' . $optimization);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get copyright text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_copyright_text() {
|
||||
$default = sprintf(
|
||||
__('© %s %s. All rights reserved.', 'roi-theme'),
|
||||
date('Y'),
|
||||
get_bloginfo('name')
|
||||
);
|
||||
return roi_get_setting('copyright_text', $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get social media links
|
||||
*
|
||||
* @return array Array of social media links
|
||||
*/
|
||||
function roi_get_social_links() {
|
||||
return array(
|
||||
'facebook' => roi_get_setting('social_facebook', ''),
|
||||
'twitter' => roi_get_setting('social_twitter', ''),
|
||||
'instagram' => roi_get_setting('social_instagram', ''),
|
||||
'linkedin' => roi_get_setting('social_linkedin', ''),
|
||||
'youtube' => roi_get_setting('social_youtube', ''),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if comments are enabled for posts
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function roi_comments_enabled_for_posts() {
|
||||
return roi_is_setting_enabled('enable_comments_posts');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if comments are enabled for pages
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function roi_comments_enabled_for_pages() {
|
||||
return roi_is_setting_enabled('enable_comments_pages');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default post layout
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_default_post_layout() {
|
||||
return roi_get_setting('default_post_layout', 'right-sidebar');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default page layout
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_default_page_layout() {
|
||||
return roi_get_setting('default_page_layout', 'right-sidebar');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get posts per page for archive
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function roi_get_archive_posts_per_page() {
|
||||
$custom = (int) roi_get_setting('archive_posts_per_page', 0);
|
||||
return $custom > 0 ? $custom : get_option('posts_per_page', 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if featured image should be shown on single posts
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function roi_show_featured_image_single() {
|
||||
return roi_is_setting_enabled('show_featured_image_single');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if author box should be shown on single posts
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function roi_show_author_box() {
|
||||
return roi_is_setting_enabled('show_author_box');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get date format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_date_format() {
|
||||
return roi_get_setting('date_format', 'd/m/Y');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get time format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_time_format() {
|
||||
return roi_get_setting('time_format', 'H:i');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get logo URL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_logo_url() {
|
||||
$logo_id = roi_get_setting('site_logo', 0);
|
||||
if ($logo_id) {
|
||||
$logo = wp_get_attachment_image_url($logo_id, 'full');
|
||||
if ($logo) {
|
||||
return $logo;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get favicon URL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_favicon_url() {
|
||||
$favicon_id = roi_get_setting('site_favicon', 0);
|
||||
if ($favicon_id) {
|
||||
$favicon = wp_get_attachment_image_url($favicon_id, 'full');
|
||||
if ($favicon) {
|
||||
return $favicon;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom CSS
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_custom_css() {
|
||||
return roi_get_setting('custom_css', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom JS (header)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_custom_js_header() {
|
||||
return roi_get_setting('custom_js_header', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom JS (footer)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_custom_js_footer() {
|
||||
return roi_get_setting('custom_js_footer', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if lazy loading is enabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function roi_is_lazy_loading_enabled() {
|
||||
return roi_is_setting_enabled('enable_lazy_loading');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all theme settings
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function roi_get_all_settings() {
|
||||
$db_manager = new ROI_DB_Manager();
|
||||
$settings = $db_manager->get_config('theme');
|
||||
|
||||
// Backward compatibility: si no hay settings en tabla, leer de wp_options
|
||||
if (empty($settings)) {
|
||||
$settings = get_option('roi_theme_options', array());
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all theme options (ALIAS for backward compatibility)
|
||||
*
|
||||
* @deprecated 2.0.0 Use roi_get_all_settings() instead
|
||||
* @return array
|
||||
*/
|
||||
function roi_get_all_options() {
|
||||
return roi_get_all_settings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset theme settings to defaults
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function roi_reset_settings() {
|
||||
$db_manager = new ROI_DB_Manager();
|
||||
return $db_manager->delete_config('theme');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset theme options to defaults (ALIAS for backward compatibility)
|
||||
*
|
||||
* @deprecated 2.0.0 Use roi_reset_settings() instead
|
||||
* @return bool
|
||||
*/
|
||||
function roi_reset_options() {
|
||||
return roi_reset_settings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Table of Contents is enabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function roi_is_toc_enabled() {
|
||||
return roi_get_setting('enable_toc', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get minimum headings required to display TOC
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function roi_get_toc_min_headings() {
|
||||
return (int) roi_get_setting('toc_min_headings', 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get TOC title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function roi_get_toc_title() {
|
||||
return roi_get_setting('toc_title', __('Table of Contents', 'roi-theme'));
|
||||
}
|
||||
202
inc/toc.php
202
inc/toc.php
@@ -1,202 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Table of Contents (TOC) Functions
|
||||
*
|
||||
* This file contains functions to automatically generate a table of contents
|
||||
* from post content headings (H2 and H3).
|
||||
*
|
||||
* @package ROI_Theme
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract headings from post content
|
||||
*
|
||||
* Parses the content and extracts all H2 and H3 headings with their text.
|
||||
*
|
||||
* @param string $content Post content
|
||||
* @return array Array of headings with level, text, and ID
|
||||
*/
|
||||
function roi_extract_headings($content) {
|
||||
if (empty($content)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$headings = array();
|
||||
|
||||
// Match H2 and H3 tags with their content
|
||||
preg_match_all('/<h([23])(?:[^>]*)>(.*?)<\/h\1>/i', $content, $matches, PREG_SET_ORDER);
|
||||
|
||||
foreach ($matches as $index => $match) {
|
||||
$level = (int) $match[1]; // 2 or 3
|
||||
$text = strip_tags($match[2]); // Remove any HTML tags inside heading
|
||||
|
||||
// Generate a clean ID from the heading text
|
||||
$id = roi_generate_heading_id($text, $index);
|
||||
|
||||
$headings[] = array(
|
||||
'level' => $level,
|
||||
'text' => $text,
|
||||
'id' => $id,
|
||||
);
|
||||
}
|
||||
|
||||
return $headings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a clean ID for a heading
|
||||
*
|
||||
* Creates a URL-friendly ID from heading text.
|
||||
*
|
||||
* @param string $text Heading text
|
||||
* @param int $index Index of the heading (for uniqueness)
|
||||
* @return string Clean ID
|
||||
*/
|
||||
function roi_generate_heading_id($text, $index) {
|
||||
// Remove special characters and convert to lowercase
|
||||
$id = sanitize_title($text);
|
||||
|
||||
// If ID is empty, use a fallback
|
||||
if (empty($id)) {
|
||||
$id = 'heading-' . $index;
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate HTML for Table of Contents
|
||||
*
|
||||
* Creates a nested list structure from the headings array.
|
||||
*
|
||||
* @param array $headings Array of headings from roi_extract_headings()
|
||||
* @return string HTML for the table of contents
|
||||
*/
|
||||
function roi_generate_toc($headings) {
|
||||
// Get minimum headings required from theme options
|
||||
$min_headings = (int) roi_get_option('toc_min_headings', 2);
|
||||
|
||||
if (empty($headings) || count($headings) < $min_headings) {
|
||||
return ''; // Don't show TOC if there are fewer headings than required
|
||||
}
|
||||
|
||||
// Get custom TOC title from theme options
|
||||
$toc_title = roi_get_toc_title();
|
||||
|
||||
$toc_html = '<nav class="roi-toc" aria-label="' . esc_attr($toc_title) . '">';
|
||||
$toc_html .= '<div class="roi-toc-header">';
|
||||
$toc_html .= '<h2 class="roi-toc-title">' . esc_html($toc_title) . '</h2>';
|
||||
$toc_html .= '<button class="roi-toc-toggle" aria-expanded="true" aria-controls="roi-toc-list">';
|
||||
$toc_html .= '<span class="toggle-icon" aria-hidden="true"></span>';
|
||||
$toc_html .= '<span class="screen-reader-text">' . esc_html__('Toggle Table of Contents', 'roi-theme') . '</span>';
|
||||
$toc_html .= '</button>';
|
||||
$toc_html .= '</div>';
|
||||
|
||||
$toc_html .= '<ol class="roi-toc-list" id="roi-toc-list">';
|
||||
|
||||
$current_level = 2;
|
||||
$open_sublists = 0;
|
||||
|
||||
foreach ($headings as $index => $heading) {
|
||||
$level = $heading['level'];
|
||||
$text = esc_html($heading['text']);
|
||||
$id = esc_attr($heading['id']);
|
||||
|
||||
// Handle level changes
|
||||
if ($level > $current_level) {
|
||||
// Open nested list for H3
|
||||
$toc_html .= '<ol class="roi-toc-sublist">';
|
||||
$open_sublists++;
|
||||
} elseif ($level < $current_level && $open_sublists > 0) {
|
||||
// Close nested list when going back to H2
|
||||
$toc_html .= '</li></ol></li>';
|
||||
$open_sublists--;
|
||||
} elseif ($index > 0) {
|
||||
// Close previous item
|
||||
$toc_html .= '</li>';
|
||||
}
|
||||
|
||||
$toc_html .= '<li class="roi-toc-item roi-toc-level-' . $level . '">';
|
||||
$toc_html .= '<a href="#' . $id . '" class="roi-toc-link">' . $text . '</a>';
|
||||
|
||||
$current_level = $level;
|
||||
}
|
||||
|
||||
// Close any open lists
|
||||
$toc_html .= '</li>';
|
||||
while ($open_sublists > 0) {
|
||||
$toc_html .= '</ol></li>';
|
||||
$open_sublists--;
|
||||
}
|
||||
|
||||
$toc_html .= '</ol>';
|
||||
$toc_html .= '</nav>';
|
||||
|
||||
return $toc_html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add IDs to headings in content
|
||||
*
|
||||
* Modifies the post content to add ID attributes to H2 and H3 headings.
|
||||
*
|
||||
* @param string $content Post content
|
||||
* @return string Modified content with IDs added to headings
|
||||
*/
|
||||
function roi_add_heading_ids($content) {
|
||||
if (empty($content)) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Extract headings first to get consistent IDs
|
||||
$headings = roi_extract_headings($content);
|
||||
|
||||
if (empty($headings)) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Replace headings with versions that include IDs
|
||||
$heading_index = 0;
|
||||
$content = preg_replace_callback(
|
||||
'/<h([23])(?:[^>]*)>(.*?)<\/h\1>/i',
|
||||
function($matches) use ($headings, &$heading_index) {
|
||||
if (!isset($headings[$heading_index])) {
|
||||
return $matches[0];
|
||||
}
|
||||
|
||||
$level = $matches[1];
|
||||
$text = $matches[2];
|
||||
$id = $headings[$heading_index]['id'];
|
||||
$heading_index++;
|
||||
|
||||
return '<h' . $level . ' id="' . esc_attr($id) . '">' . $text . '</h' . $level . '>';
|
||||
},
|
||||
$content
|
||||
);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify post content to add heading IDs
|
||||
*
|
||||
* Filters the_content to add IDs to headings for TOC linking.
|
||||
*
|
||||
* @param string $content Post content
|
||||
* @return string Modified content
|
||||
*/
|
||||
function roi_filter_content_add_heading_ids($content) {
|
||||
// Only apply to single posts
|
||||
if (!is_single()) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
return roi_add_heading_ids($content);
|
||||
}
|
||||
add_filter('the_content', 'roi_filter_content_add_heading_ids', 10);
|
||||
Reference in New Issue
Block a user