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>
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
* Funciones para usar en templates:
|
||||
* - roi_render_ad_slot('post-top')
|
||||
* - roi_render_rail_ads() - Para los margenes laterales del viewport
|
||||
* - roi_should_disable_auto_ads()
|
||||
*/
|
||||
|
||||
if (!defined('ABSPATH')) {
|
||||
@@ -131,35 +130,8 @@ add_action('wp_footer', function() {
|
||||
echo roi_render_rail_ads();
|
||||
}, 50);
|
||||
|
||||
/**
|
||||
* Verifica si se debe deshabilitar Auto Ads
|
||||
*/
|
||||
function roi_should_disable_auto_ads(): bool
|
||||
{
|
||||
global $container;
|
||||
|
||||
if ($container === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$repository = $container->getComponentSettingsRepository();
|
||||
$settings = $repository->getComponentSettings('adsense-placement');
|
||||
|
||||
$isEnabled = ($settings['visibility']['is_enabled'] ?? false) === true;
|
||||
$disableAutoAds = ($settings['visibility']['disable_auto_ads'] ?? true) === true;
|
||||
|
||||
return $isEnabled && $disableAutoAds;
|
||||
} catch (\Throwable $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Carga el script principal de AdSense
|
||||
*
|
||||
* IMPORTANTE: Si disable_auto_ads está activo, se añade código para
|
||||
* deshabilitar Auto Ads (page-level ads) de Google.
|
||||
*/
|
||||
function roi_enqueue_adsense_script(): void
|
||||
{
|
||||
@@ -183,25 +155,13 @@ function roi_enqueue_adsense_script(): void
|
||||
}
|
||||
|
||||
$delayEnabled = ($settings['forms']['delay_enabled'] ?? true) === true;
|
||||
$disableAutoAds = ($settings['visibility']['disable_auto_ads'] ?? true) === true;
|
||||
|
||||
// Script principal de AdSense
|
||||
if ($delayEnabled) {
|
||||
echo '<script type="text/plain" data-adsense-script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=' . esc_attr($publisherId) . '" crossorigin="anonymous"></script>' . "\n";
|
||||
} else {
|
||||
echo '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=' . esc_attr($publisherId) . '" crossorigin="anonymous"></script>' . "\n";
|
||||
}
|
||||
|
||||
// Deshabilitar Auto Ads (page-level ads) si está configurado
|
||||
if ($disableAutoAds) {
|
||||
echo '<script>
|
||||
(adsbygoogle = window.adsbygoogle || []).push({
|
||||
google_ad_client: "' . esc_js($publisherId) . '",
|
||||
enable_page_level_ads: false
|
||||
});
|
||||
</script>' . "\n";
|
||||
}
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
if (defined('WP_DEBUG') && WP_DEBUG) {
|
||||
error_log('ROI AdSense: ' . $e->getMessage());
|
||||
|
||||
Reference in New Issue
Block a user