debug: Add logging to diagnose AdSense ads not injecting
Added error_log statements to roi_inject_content_ads() to trace: - Function entry point - Conditions failing (is_single, in_the_loop, is_main_query) - Container null check - Settings loaded status - Post exclusion check - Rendered slot lengths - Any exceptions with full trace This will help identify why ads are not appearing on production despite all database settings being correctly configured. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -183,12 +183,17 @@ function roi_inject_content_ads(string $content): string
|
||||
{
|
||||
global $container;
|
||||
|
||||
// DEBUG: Log para diagnosticar problema de ads no inyectados
|
||||
error_log('ROI AdSense Debug: roi_inject_content_ads called');
|
||||
|
||||
// Solo en posts individuales
|
||||
if (!is_single() || !in_the_loop() || !is_main_query()) {
|
||||
error_log('ROI AdSense Debug: Skip - not single/loop/main_query. is_single=' . (is_single() ? '1' : '0') . ', in_the_loop=' . (in_the_loop() ? '1' : '0') . ', is_main_query=' . (is_main_query() ? '1' : '0'));
|
||||
return $content;
|
||||
}
|
||||
|
||||
if ($container === null) {
|
||||
error_log('ROI AdSense Debug: Skip - container is null');
|
||||
return $content;
|
||||
}
|
||||
|
||||
@@ -196,12 +201,16 @@ function roi_inject_content_ads(string $content): string
|
||||
$repository = $container->getComponentSettingsRepository();
|
||||
$settings = $repository->getComponentSettings('adsense-placement');
|
||||
|
||||
error_log('ROI AdSense Debug: Settings loaded. is_enabled=' . ($settings['visibility']['is_enabled'] ?? 'NOT SET'));
|
||||
|
||||
if (empty($settings) || !($settings['visibility']['is_enabled'] ?? false)) {
|
||||
error_log('ROI AdSense Debug: Skip - settings empty or not enabled');
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Verificar exclusiones
|
||||
if (roi_is_ad_excluded($settings)) {
|
||||
error_log('ROI AdSense Debug: Skip - post excluded');
|
||||
return $content;
|
||||
}
|
||||
|
||||
@@ -211,12 +220,14 @@ function roi_inject_content_ads(string $content): string
|
||||
$postTopHtml = '';
|
||||
if ($settings['behavior']['post_top_enabled'] ?? false) {
|
||||
$postTopHtml = $renderer->renderSlot($settings, 'post-top');
|
||||
error_log('ROI AdSense Debug: post-top rendered, length=' . strlen($postTopHtml));
|
||||
}
|
||||
|
||||
// Inyectar anuncio al final (post-bottom)
|
||||
$postBottomHtml = '';
|
||||
if ($settings['behavior']['post_bottom_enabled'] ?? false) {
|
||||
$postBottomHtml = $renderer->renderSlot($settings, 'post-bottom');
|
||||
error_log('ROI AdSense Debug: post-bottom rendered, length=' . strlen($postBottomHtml));
|
||||
}
|
||||
|
||||
// Inyectar anuncios dentro del contenido
|
||||
@@ -226,12 +237,12 @@ function roi_inject_content_ads(string $content): string
|
||||
);
|
||||
$content = $injector->inject($content);
|
||||
|
||||
error_log('ROI AdSense Debug: Final injection done. postTop=' . strlen($postTopHtml) . ', postBottom=' . strlen($postBottomHtml));
|
||||
|
||||
return $postTopHtml . $content . $postBottomHtml;
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
if (defined('WP_DEBUG') && WP_DEBUG) {
|
||||
error_log('ROI AdSense Content: ' . $e->getMessage());
|
||||
}
|
||||
error_log('ROI AdSense Content ERROR: ' . $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine());
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user