diff --git a/Admin/AdsensePlacement/Infrastructure/FieldMapping/AdsensePlacementFieldMapper.php b/Admin/AdsensePlacement/Infrastructure/FieldMapping/AdsensePlacementFieldMapper.php
index c4abf4ec..270400a9 100644
--- a/Admin/AdsensePlacement/Infrastructure/FieldMapping/AdsensePlacementFieldMapper.php
+++ b/Admin/AdsensePlacement/Infrastructure/FieldMapping/AdsensePlacementFieldMapper.php
@@ -19,6 +19,7 @@ final class AdsensePlacementFieldMapper implements FieldMapperInterface
'adsense-placementEnabled' => ['group' => 'visibility', 'attribute' => 'is_enabled'],
'adsense-placementShowOnMobile' => ['group' => 'visibility', 'attribute' => 'show_on_mobile'],
'adsense-placementShowOnDesktop' => ['group' => 'visibility', 'attribute' => 'show_on_desktop'],
+ 'adsense-placementHideForLoggedIn' => ['group' => 'visibility', 'attribute' => 'hide_for_logged_in'],
// ANALYTICS (Google Analytics)
'adsense-placementAnalyticsEnabled' => ['group' => 'analytics', 'attribute' => 'analytics_enabled'],
diff --git a/Admin/AdsensePlacement/Infrastructure/Ui/AdsensePlacementFormBuilder.php b/Admin/AdsensePlacement/Infrastructure/Ui/AdsensePlacementFormBuilder.php
index 77164716..71ca7b81 100644
--- a/Admin/AdsensePlacement/Infrastructure/Ui/AdsensePlacementFormBuilder.php
+++ b/Admin/AdsensePlacement/Infrastructure/Ui/AdsensePlacementFormBuilder.php
@@ -86,6 +86,13 @@ final class AdsensePlacementFormBuilder
$html .= ' ';
$html .= '';
+ // Opcion para ocultar anuncios a usuarios logueados
+ $html .= '
';
+ $hideForLoggedIn = $this->renderer->getFieldValue($cid, 'visibility', 'hide_for_logged_in', false);
+ $html .= $this->buildSwitch($cid . 'HideForLoggedIn', 'Ocultar para usuarios logueados', $hideForLoggedIn, 'bi-person-lock');
+ $html .= 'No mostrar anuncios a usuarios con sesion iniciada en WordPress';
+ $html .= '
';
+
$html .= ' ';
$html .= '';
diff --git a/Inc/adsense-placement.php b/Inc/adsense-placement.php
index f9e29bac..4cdfe4b9 100644
--- a/Inc/adsense-placement.php
+++ b/Inc/adsense-placement.php
@@ -37,6 +37,11 @@ function roi_render_ad_slot(string $location): string
return '';
}
+ // Verificar si ocultar para usuarios logueados
+ if (roi_should_hide_for_logged_in($settings)) {
+ return '';
+ }
+
// Verificar exclusiones
if (roi_is_ad_excluded($settings)) {
return '';
@@ -55,6 +60,21 @@ function roi_render_ad_slot(string $location): string
}
}
+/**
+ * Verifica si se deben ocultar anuncios para usuarios logueados
+ */
+function roi_should_hide_for_logged_in(array $settings): bool
+{
+ // Si la opcion esta activada Y el usuario esta logueado, ocultar ads
+ $hideForLoggedIn = $settings['visibility']['hide_for_logged_in'] ?? false;
+
+ if ($hideForLoggedIn && is_user_logged_in()) {
+ return true;
+ }
+
+ return false;
+}
+
/**
* Verifica si el contenido actual esta excluido
*/
@@ -108,6 +128,11 @@ function roi_render_rail_ads(): string
return '';
}
+ // Verificar si ocultar para usuarios logueados
+ if (roi_should_hide_for_logged_in($settings)) {
+ return '';
+ }
+
// Verificar exclusiones
if (roi_is_ad_excluded($settings)) {
return '';
@@ -153,6 +178,11 @@ function roi_enqueue_adsense_script(): void
return;
}
+ // Verificar si ocultar para usuarios logueados
+ if (roi_should_hide_for_logged_in($settings)) {
+ return;
+ }
+
$publisherId = $settings['content']['publisher_id'] ?? '';
if (empty($publisherId)) {
return;
@@ -201,6 +231,11 @@ function roi_inject_content_ads(string $content): string
return $content;
}
+ // Verificar si ocultar para usuarios logueados
+ if (roi_should_hide_for_logged_in($settings)) {
+ return $content;
+ }
+
// Verificar exclusiones
if (roi_is_ad_excluded($settings)) {
return $content;
diff --git a/Schemas/adsense-placement.json b/Schemas/adsense-placement.json
index 4c4eb060..e9f563bf 100644
--- a/Schemas/adsense-placement.json
+++ b/Schemas/adsense-placement.json
@@ -28,6 +28,13 @@
"default": true,
"editable": true,
"description": "Muestra anuncios en pantallas moviles (<992px)"
+ },
+ "hide_for_logged_in": {
+ "type": "boolean",
+ "label": "Ocultar para usuarios logueados",
+ "default": false,
+ "editable": true,
+ "description": "No mostrar anuncios a usuarios con sesion iniciada en WordPress"
}
}
},