diff --git a/functions.php b/functions.php index cd91bb94..4de7db4a 100644 --- a/functions.php +++ b/functions.php @@ -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'); diff --git a/inc/customizer-fonts.php b/inc/customizer-fonts.php deleted file mode 100644 index ff42d599..00000000 --- a/inc/customizer-fonts.php +++ /dev/null @@ -1,145 +0,0 @@ -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 - /* - ?> - - - - - '); -} - -/** - * 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')); -} diff --git a/inc/theme-settings.php b/inc/theme-settings.php deleted file mode 100644 index 6d246439..00000000 --- a/inc/theme-settings.php +++ /dev/null @@ -1,418 +0,0 @@ -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')); -} diff --git a/inc/toc.php b/inc/toc.php deleted file mode 100644 index 11b4d000..00000000 --- a/inc/toc.php +++ /dev/null @@ -1,202 +0,0 @@ -]*)>(.*?)<\/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 = ''; - - 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\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 '' . $text . ''; - }, - $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);