Files
roi-theme/Public/YoutubeFacade/Infrastructure/Wordpress/YoutubeFacadeHooksRegistrar.php
FrankZamora d7915d372b refactor(adsense): remove dead code + PageSpeed CSS defer
- Remove unused roi_should_disable_auto_ads() function
- Remove enable_page_level_ads code (Auto Ads disabled in Google panel)
- Defer non-critical CSS with media=print pattern (Fase 4.2 PageSpeed)
- Fix roi-accessibility dependency: roi-theme-style -> roi-main-style

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 15:38:49 -06:00

74 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace ROITheme\Public\YoutubeFacade\Infrastructure\Wordpress;
use ROITheme\Public\YoutubeFacade\Infrastructure\Services\YoutubeFacadeContentFilter;
/**
* Registers WordPress hooks for YouTube Facade Pattern
*
* PageSpeed Optimization Phase 2.4:
* - Reduces TBT by ~2000ms by lazy-loading YouTube iframes
* - Shows thumbnail + play button instead of full iframe
* - Loads real iframe only on user click
*
* @package ROITheme\Public\YoutubeFacade
* @since 1.0.6
*/
final class YoutubeFacadeHooksRegistrar
{
private YoutubeFacadeContentFilter $contentFilter;
public function __construct(YoutubeFacadeContentFilter $contentFilter)
{
$this->contentFilter = $contentFilter;
}
/**
* Register all hooks
*/
public function register(): void
{
// Filter post content to replace YouTube iframes with facades
// Priority 101 = after rcp_filter_restricted_content (100)
add_filter('the_content', [$this->contentFilter, 'filter'], 101);
// Enqueue facade assets
add_action('wp_enqueue_scripts', [$this, 'enqueueAssets'], 15);
}
/**
* Enqueue CSS and JS for YouTube facades
*/
public function enqueueAssets(): void
{
// Load on all frontend pages (condition removed for debugging)
// TODO: Re-add is_singular() check after confirming assets load
if (is_admin()) {
return;
}
// DIFERIDO: Fase 4.2 PageSpeed - below the fold
wp_enqueue_style(
'roi-youtube-facade',
get_template_directory_uri() . '/Public/YoutubeFacade/Infrastructure/Ui/Assets/Css/youtube-facade.css',
[],
ROI_VERSION,
'print' // Diferido para no bloquear renderizado
);
wp_enqueue_script(
'roi-youtube-facade',
get_template_directory_uri() . '/Public/YoutubeFacade/Infrastructure/Ui/Assets/Js/youtube-facade.js',
[],
ROI_VERSION,
[
'in_footer' => true,
'strategy' => 'defer',
]
);
}
}