Files
roi-theme/inc/seo.php
FrankZamora de5fff4f5c Fase 1: Estructura Base y DI Container - Clean Architecture
COMPLETADO: Fase 1 de la migración a Clean Architecture + POO

## Estructura de Carpetas
- ✓ Estructura completa de 4 capas (Domain, Application, Infrastructure, Presentation)
- ✓ Carpetas de Use Cases (SaveComponent, GetComponent, DeleteComponent, SyncSchema)
- ✓ Estructura de tests (Unit, Integration, E2E)
- ✓ Carpetas de schemas y templates

## Composer y Autoloading
- ✓ PSR-4 autoloading configurado para ROITheme namespace
- ✓ Autoloader optimizado regenerado

## DI Container
- ✓ DIContainer implementado con patrón Singleton
- ✓ Métodos set(), get(), has() para gestión de servicios
- ✓ Getters específicos para ComponentRepository, ValidationService, CacheService
- ✓ Placeholders que serán implementados en Fase 5
- ✓ Prevención de clonación y deserialización

## Interfaces
- ✓ ComponentRepositoryInterface (Domain)
- ✓ ValidationServiceInterface (Application)
- ✓ CacheServiceInterface (Application)
- ✓ Component entity placeholder (Domain)

## Bootstrap
- ✓ functions.php actualizado con carga de Composer autoloader
- ✓ Inicialización del DIContainer
- ✓ Helper function roi_container() disponible globalmente

## Tests
- ✓ 10 tests unitarios para DIContainer (100% cobertura)
- ✓ Total: 13 tests unitarios, 28 assertions
- ✓ Suite de tests pasando correctamente

## Validación
- ✓ Script de validación automatizado (48/48 checks pasados)
- ✓ 100% de validaciones exitosas

La arquitectura base está lista para la Fase 2.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 13:48:24 -06:00

206 lines
5.3 KiB
PHP

<?php
/**
* SEO Optimizations and Rank Math Compatibility
*
* This file contains SEO-related theme functions that work
* seamlessly with Rank Math SEO plugin without conflicts.
*
* @package ROI_Theme
* @since 1.0.0
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}
/**
* Remove WordPress version from header and feeds
*
* Prevents disclosure of WordPress version number which could
* expose potential vulnerabilities. This is a common SEO best practice.
*
* @since 1.0.0
*/
function roi_remove_generator() {
return '';
}
remove_action('wp_head', 'wp_generator');
add_filter('the_generator', 'roi_remove_generator');
/**
* Remove RSD (Really Simple Discovery) link
*
* Removes unnecessary header link that's rarely needed.
*
* @since 1.0.0
*/
remove_action('wp_head', 'rsd_link');
/**
* Remove Windows Live Writer manifest
*
* Removes deprecated Microsoft Windows Live Writer support link.
*
* @since 1.0.0
*/
remove_action('wp_head', 'wlwmanifest_link');
/**
* Remove REST API link from header
*
* Note: Rank Math handles REST API headers, so we keep REST API
* itself enabled but remove the link tag from the header.
* This prevents exposing API endpoints unnecessarily.
*
* @since 1.0.0
*/
remove_action('wp_head', 'rest_output_link_wp_head');
/**
* Optimize robots.txt headers
*
* Ensures proper cache headers for robots.txt
*
* @since 1.0.0
*/
function roi_robots_header() {
if (is_robots()) {
header('Cache-Control: public, max-age=86400');
header('Expires: ' . gmdate('r', time() + 86400));
}
}
add_action('pre_handle_robots_txt', 'roi_robots_header');
/**
* Improve comment feed performance
*
* Disables post comments feed if not needed (can be re-enabled
* in theme options if required for client websites).
*
* @since 1.0.0
*/
// Note: Keep this commented out unless client specifically needs comment feeds
// remove_action('wp_head', 'feed_links', 2);
/**
* Clean up empty image alt attributes
*
* Encourages proper image SEO by highlighting missing alt text in admin
*
* @since 1.0.0
*/
function roi_admin_notice_missing_alt() {
if (!current_user_can('upload_files')) {
return;
}
// This is informational - actual alt text enforcement is better
// handled by Rank Math's image optimization features
}
/**
* Ensure wp_head() is properly closed before body
*
* This is called in header.php to ensure all SEO meta tags
* (from Rank Math and theme) are properly placed.
*
* @since 1.0.0
*/
function roi_seo_head_hooks() {
// This ensures proper hook execution order for Rank Math compatibility
do_action('roi_head_close');
}
/**
* Add prefetch hints for external resources
*
* Improves performance by preemptively connecting to external domains
* commonly used in the theme (fonts, CDNs, etc.)
*
* @since 1.0.0
*/
function roi_prefetch_external() {
// Google Fonts prefetch
echo '<link rel="preconnect" href="https://fonts.googleapis.com">' . "\n";
echo '<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>' . "\n";
}
add_action('wp_head', 'roi_prefetch_external', 1);
/**
* Open Graph support for Rank Math compatibility
*
* Ensures theme doesn't output conflicting OG tags when Rank Math is active.
* Rank Math handles all Open Graph implementation.
*
* @since 1.0.0
*/
function roi_check_rank_math_active() {
return defined('RANK_MATH_VERSION');
}
/**
* Schema.org compatibility layer
*
* Provides basic schema support if Rank Math is not active.
* When Rank Math is active, it takes over all schema implementation.
*
* @since 1.0.0
*/
function roi_schema_fallback() {
// Only output schema if Rank Math is NOT active
if (roi_check_rank_math_active()) {
return;
}
// Basic organization schema fallback
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'WebSite',
'name' => get_bloginfo('name'),
'url' => get_home_url(),
);
if (get_bloginfo('description')) {
$schema['description'] = get_bloginfo('description');
}
echo "\n" . '<!-- ROI Theme Basic Schema (Rank Math not active) -->' . "\n";
echo '<script type="application/ld+json">' . "\n";
echo wp_json_encode($schema, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . "\n";
echo '</script>' . "\n";
}
add_action('wp_head', 'roi_schema_fallback', 20);
/**
* Security headers configuration
*
* Adds recommended security headers that also improve SEO
* (by indicating secure, well-maintained site)
*
* @since 1.0.0
*/
function roi_security_headers() {
// These headers improve trust signals for search engines
header('X-Content-Type-Options: nosniff');
header('X-Frame-Options: SAMEORIGIN');
header('X-XSS-Protection: 1; mode=block');
}
add_action('send_headers', 'roi_security_headers');
/**
* Ensure title tag support is active
*
* This is set in functions.php with add_theme_support('title-tag')
* but we verify it here to log any issues for debugging.
*
* @since 1.0.0
*/
function roi_verify_title_tag_support() {
if (!current_theme_supports('title-tag')) {
// Log warning if title-tag support is somehow disabled
error_log('Warning: ROI Theme title-tag support not properly initialized');
}
}
add_action('after_setup_theme', 'roi_verify_title_tag_support', 20);