feat(exclusions): Implement component exclusion system (Plan 99.11)

Adds ability to exclude components from specific:
- Categories (by slug or term_id)
- Post/Page IDs
- URL patterns (substring or regex)

Architecture:
- Domain: Value Objects (CategoryExclusion, PostIdExclusion,
  UrlPatternExclusion, ExclusionRuleSet) + Contracts
- Application: EvaluateExclusionsUseCase +
  EvaluateComponentVisibilityUseCase (orchestrator)
- Infrastructure: WordPressExclusionRepository,
  WordPressPageContextProvider, WordPressServerRequestProvider
- Admin: ExclusionFormPartial (reusable UI),
  ExclusionFieldProcessor, JS toggle

The PageVisibilityHelper now uses the orchestrator UseCase that
combines page-type visibility (Plan 99.10) with exclusion rules.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
FrankZamora
2025-12-03 10:51:00 -06:00
parent 8735962f52
commit 14138e7762
19 changed files with 1407 additions and 5 deletions

View File

@@ -0,0 +1,90 @@
<?php
declare(strict_types=1);
namespace ROITheme\Shared\Infrastructure\Services;
use ROITheme\Shared\Domain\Contracts\PageContextProviderInterface;
use ROITheme\Shared\Domain\Contracts\ServerRequestProviderInterface;
/**
* Implementacion WordPress del proveedor de contexto de pagina
*
* Obtiene informacion del post/pagina actual usando funciones de WordPress.
*
* v1.1: Renombrado de WordPressExclusionEvaluator
* Inyecta ServerRequestProviderInterface (no accede a $_SERVER directamente)
*
* @package ROITheme\Shared\Infrastructure\Services
*/
final class WordPressPageContextProvider implements PageContextProviderInterface
{
public function __construct(
private readonly ServerRequestProviderInterface $requestProvider
) {}
public function getCurrentContext(): array
{
$postId = $this->getCurrentPostId();
return [
'post_id' => $postId,
'categories' => $this->getPostCategories($postId),
'url' => $this->getCurrentUrl(),
'request_uri' => $this->requestProvider->getRequestUri(),
'post_type' => $this->getCurrentPostType($postId),
];
}
private function getCurrentPostId(): int
{
if (is_singular()) {
return get_the_ID() ?: 0;
}
return 0;
}
/**
* @return array<array{term_id: int, slug: string, name: string}>
*/
private function getPostCategories(int $postId): array
{
if ($postId === 0) {
return [];
}
$categories = get_the_category($postId);
if (empty($categories)) {
return [];
}
return array_map(function (\WP_Term $term): array {
return [
'term_id' => $term->term_id,
'slug' => $term->slug,
'name' => $term->name,
];
}, $categories);
}
private function getCurrentUrl(): string
{
global $wp;
if (isset($wp->request)) {
return home_url($wp->request);
}
return home_url(add_query_arg([], false));
}
private function getCurrentPostType(int $postId): string
{
if ($postId === 0) {
return '';
}
return get_post_type($postId) ?: '';
}
}