fix(adsense): registrar filtro the_content y corregir ancho de contenedor
- Registra filtro the_content para inyectar anuncios (post-top, post-bottom, content) - Corrige CSS del contenedor .roi-ad-slot con width:100% para evitar availableWidth=0 - Usa ContentAdInjector para insertar ads dentro del contenido 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -3,11 +3,11 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace ROITheme\Admin\AdsensePlacement\Infrastructure\FieldMapping;
|
namespace ROITheme\Admin\AdsensePlacement\Infrastructure\FieldMapping;
|
||||||
|
|
||||||
use ROITheme\Admin\Shared\Infrastructure\FieldMapping\FieldMapperInterface;
|
use ROITheme\Admin\Shared\Domain\Contracts\FieldMapperInterface;
|
||||||
|
|
||||||
final class AdsensePlacementFieldMapper implements FieldMapperInterface
|
final class AdsensePlacementFieldMapper implements FieldMapperInterface
|
||||||
{
|
{
|
||||||
public function getComponentId(): string
|
public function getComponentName(): string
|
||||||
{
|
{
|
||||||
return 'adsense-placement';
|
return 'adsense-placement';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -194,3 +194,65 @@ function roi_enqueue_adsense_script(): void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
add_action('wp_head', 'roi_enqueue_adsense_script', 5);
|
add_action('wp_head', 'roi_enqueue_adsense_script', 5);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registra el filtro the_content para inyectar anuncios
|
||||||
|
*/
|
||||||
|
add_filter('the_content', 'roi_inject_content_ads', 100);
|
||||||
|
|
||||||
|
function roi_inject_content_ads(string $content): string
|
||||||
|
{
|
||||||
|
global $container;
|
||||||
|
|
||||||
|
// Solo en posts individuales
|
||||||
|
if (!is_single() || !in_the_loop() || !is_main_query()) {
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($container === null) {
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$repository = $container->getComponentSettingsRepository();
|
||||||
|
$settings = $repository->getComponentSettings('adsense-placement');
|
||||||
|
|
||||||
|
if (empty($settings) || !($settings['visibility']['is_enabled'] ?? false)) {
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verificar exclusiones
|
||||||
|
if (roi_is_ad_excluded($settings)) {
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
$renderer = $container->getAdsensePlacementRenderer();
|
||||||
|
|
||||||
|
// Inyectar anuncio al inicio (post-top)
|
||||||
|
$postTopHtml = '';
|
||||||
|
if ($settings['behavior']['post_top_enabled'] ?? false) {
|
||||||
|
$postTopHtml = $renderer->renderSlot($settings, 'post-top');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inyectar anuncio al final (post-bottom)
|
||||||
|
$postBottomHtml = '';
|
||||||
|
if ($settings['behavior']['post_bottom_enabled'] ?? false) {
|
||||||
|
$postBottomHtml = $renderer->renderSlot($settings, 'post-bottom');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inyectar anuncios dentro del contenido
|
||||||
|
$injector = new \ROITheme\Public\AdsensePlacement\Infrastructure\Services\ContentAdInjector(
|
||||||
|
$settings,
|
||||||
|
$renderer
|
||||||
|
);
|
||||||
|
$content = $injector->inject($content);
|
||||||
|
|
||||||
|
return $postTopHtml . $content . $postBottomHtml;
|
||||||
|
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
if (defined('WP_DEBUG') && WP_DEBUG) {
|
||||||
|
error_log('ROI AdSense Content: ' . $e->getMessage());
|
||||||
|
}
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -59,12 +59,14 @@ final class AdsensePlacementRenderer
|
|||||||
|
|
||||||
// 4. Generar CSS (usando CSSGeneratorService)
|
// 4. Generar CSS (usando CSSGeneratorService)
|
||||||
$css = $this->cssGenerator->generate(
|
$css = $this->cssGenerator->generate(
|
||||||
".roi-ad-{$location}",
|
".roi-ad-slot",
|
||||||
[
|
[
|
||||||
'display' => 'flex',
|
'display' => 'block',
|
||||||
'justify_content' => 'center',
|
'width' => '100%',
|
||||||
'margin_top' => '1rem',
|
'min_width' => '300px',
|
||||||
'margin_bottom' => '1rem',
|
'margin_top' => '1.5rem',
|
||||||
|
'margin_bottom' => '1.5rem',
|
||||||
|
'text_align' => 'center',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user