chore(php): add toc debug logging for guest visibility issue
Temporary debug logging to diagnose why TOC shows for logged users but not for guests. Logs visibility checks at each layer. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -43,20 +43,30 @@ final class TableOfContentsRenderer implements RendererInterface
|
|||||||
{
|
{
|
||||||
$data = $component->getData();
|
$data = $component->getData();
|
||||||
|
|
||||||
|
// DEBUG TOC: Log all visibility checks
|
||||||
|
$isLoggedIn = is_user_logged_in();
|
||||||
|
$debugPrefix = "TOC DEBUG [" . ($isLoggedIn ? "LOGGED" : "GUEST") . "]";
|
||||||
|
|
||||||
if (!$this->isEnabled($data)) {
|
if (!$this->isEnabled($data)) {
|
||||||
|
error_log("{$debugPrefix}: SKIP - isEnabled=false");
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PageVisibilityHelper::shouldShow(self::COMPONENT_NAME)) {
|
$shouldShow = PageVisibilityHelper::shouldShow(self::COMPONENT_NAME);
|
||||||
|
if (!$shouldShow) {
|
||||||
|
error_log("{$debugPrefix}: SKIP - PageVisibilityHelper::shouldShow=false");
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$tocItems = $this->generateTocItems($data);
|
$tocItems = $this->generateTocItems($data);
|
||||||
|
|
||||||
if (empty($tocItems)) {
|
if (empty($tocItems)) {
|
||||||
|
error_log("{$debugPrefix}: SKIP - tocItems empty");
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_log("{$debugPrefix}: RENDER - passed all checks, items=" . count($tocItems));
|
||||||
|
|
||||||
$css = $this->generateCSS($data);
|
$css = $this->generateCSS($data);
|
||||||
$html = $this->buildHTML($data, $tocItems);
|
$html = $this->buildHTML($data, $tocItems);
|
||||||
$script = $this->buildScript($data);
|
$script = $this->buildScript($data);
|
||||||
@@ -107,12 +117,21 @@ final class TableOfContentsRenderer implements RendererInterface
|
|||||||
{
|
{
|
||||||
global $post;
|
global $post;
|
||||||
|
|
||||||
|
// DEBUG: Track content processing
|
||||||
|
$isLoggedIn = is_user_logged_in();
|
||||||
|
$debugPrefix = "TOC generateTocFromContent [" . ($isLoggedIn ? "LOGGED" : "GUEST") . "]";
|
||||||
|
|
||||||
if (!$post || empty($post->post_content)) {
|
if (!$post || empty($post->post_content)) {
|
||||||
|
error_log("{$debugPrefix}: SKIP - no post or empty content");
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_log("{$debugPrefix}: post_id={$post->ID}, raw_content_length=" . strlen($post->post_content));
|
||||||
|
|
||||||
$content = apply_filters('the_content', $post->post_content);
|
$content = apply_filters('the_content', $post->post_content);
|
||||||
|
|
||||||
|
error_log("{$debugPrefix}: filtered_content_length=" . strlen($content));
|
||||||
|
|
||||||
$dom = new DOMDocument();
|
$dom = new DOMDocument();
|
||||||
libxml_use_internal_errors(true);
|
libxml_use_internal_errors(true);
|
||||||
$dom->loadHTML('<?xml encoding="utf-8" ?>' . $content);
|
$dom->loadHTML('<?xml encoding="utf-8" ?>' . $content);
|
||||||
@@ -127,6 +146,8 @@ final class TableOfContentsRenderer implements RendererInterface
|
|||||||
|
|
||||||
$headings = $xpath->query($xpathQuery);
|
$headings = $xpath->query($xpathQuery);
|
||||||
|
|
||||||
|
error_log("{$debugPrefix}: headings_found=" . $headings->length);
|
||||||
|
|
||||||
if ($headings->length === 0) {
|
if ($headings->length === 0) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,9 +36,16 @@ final class EvaluateComponentVisibilityUseCase
|
|||||||
*/
|
*/
|
||||||
public function execute(string $componentName): bool
|
public function execute(string $componentName): bool
|
||||||
{
|
{
|
||||||
|
// DEBUG: Log for TOC only
|
||||||
|
$debugToc = ($componentName === 'table-of-contents');
|
||||||
|
|
||||||
// Paso 1: Verificar visibilidad por tipo de pagina
|
// Paso 1: Verificar visibilidad por tipo de pagina
|
||||||
$visibleByPageType = $this->pageVisibilityUseCase->execute($componentName);
|
$visibleByPageType = $this->pageVisibilityUseCase->execute($componentName);
|
||||||
|
|
||||||
|
if ($debugToc) {
|
||||||
|
error_log("EvaluateComponentVisibility [{$componentName}]: visibleByPageType=" . ($visibleByPageType ? "true" : "false"));
|
||||||
|
}
|
||||||
|
|
||||||
if (!$visibleByPageType) {
|
if (!$visibleByPageType) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -46,6 +53,10 @@ final class EvaluateComponentVisibilityUseCase
|
|||||||
// Paso 2: Verificar exclusiones
|
// Paso 2: Verificar exclusiones
|
||||||
$isExcluded = $this->exclusionsUseCase->execute($componentName);
|
$isExcluded = $this->exclusionsUseCase->execute($componentName);
|
||||||
|
|
||||||
|
if ($debugToc) {
|
||||||
|
error_log("EvaluateComponentVisibility [{$componentName}]: isExcluded=" . ($isExcluded ? "true" : "false"));
|
||||||
|
}
|
||||||
|
|
||||||
// Mostrar si NO esta excluido
|
// Mostrar si NO esta excluido
|
||||||
return !$isExcluded;
|
return !$isExcluded;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,15 +28,27 @@ final class EvaluatePageVisibilityUseCase
|
|||||||
{
|
{
|
||||||
$config = $this->visibilityRepository->getVisibilityConfig($componentName);
|
$config = $this->visibilityRepository->getVisibilityConfig($componentName);
|
||||||
|
|
||||||
|
// DEBUG: Log for TOC only
|
||||||
|
$debugToc = ($componentName === 'table-of-contents');
|
||||||
|
$usingDefaults = false;
|
||||||
|
|
||||||
if (empty($config)) {
|
if (empty($config)) {
|
||||||
// Usar defaults especificos por componente si existen
|
// Usar defaults especificos por componente si existen
|
||||||
$config = VisibilityDefaults::getForComponent($componentName);
|
$config = VisibilityDefaults::getForComponent($componentName);
|
||||||
|
$usingDefaults = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$pageType = $this->pageTypeDetector->detect();
|
$pageType = $this->pageTypeDetector->detect();
|
||||||
$visibilityField = $pageType->toVisibilityField();
|
$visibilityField = $pageType->toVisibilityField();
|
||||||
|
$fieldValue = $config[$visibilityField] ?? true;
|
||||||
|
$result = $this->toBool($fieldValue);
|
||||||
|
|
||||||
return $this->toBool($config[$visibilityField] ?? true);
|
if ($debugToc) {
|
||||||
|
error_log("EvaluatePageVisibility [{$componentName}]: pageType=" . $pageType->value() . ", field={$visibilityField}, fieldValue=" . var_export($fieldValue, true) . ", result=" . ($result ? "true" : "false") . ", usingDefaults=" . ($usingDefaults ? "true" : "false"));
|
||||||
|
error_log("EvaluatePageVisibility [{$componentName}]: config=" . json_encode($config));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function toBool(mixed $value): bool
|
private function toBool(mixed $value): bool
|
||||||
|
|||||||
@@ -43,7 +43,15 @@ final class PageVisibilityHelper
|
|||||||
$container = DIContainer::getInstance();
|
$container = DIContainer::getInstance();
|
||||||
$useCase = $container->getEvaluateComponentVisibilityUseCase();
|
$useCase = $container->getEvaluateComponentVisibilityUseCase();
|
||||||
|
|
||||||
return $useCase->execute($componentName);
|
$result = $useCase->execute($componentName);
|
||||||
|
|
||||||
|
// DEBUG: Log visibility evaluation
|
||||||
|
if ($componentName === 'table-of-contents') {
|
||||||
|
$isLoggedIn = is_user_logged_in();
|
||||||
|
error_log("PageVisibilityHelper DEBUG [{$componentName}] [" . ($isLoggedIn ? "LOGGED" : "GUEST") . "]: result=" . ($result ? "true" : "false"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -15,6 +15,18 @@ final class WordPressPageTypeDetector implements PageTypeDetectorInterface
|
|||||||
{
|
{
|
||||||
public function detect(): PageType
|
public function detect(): PageType
|
||||||
{
|
{
|
||||||
|
// DEBUG: Log all checks for diagnosis
|
||||||
|
$isLoggedIn = is_user_logged_in();
|
||||||
|
$debugData = [
|
||||||
|
'is_front_page' => is_front_page(),
|
||||||
|
'is_home' => is_home(),
|
||||||
|
'is_single' => is_single(),
|
||||||
|
'is_page' => is_page(),
|
||||||
|
'is_search' => is_search(),
|
||||||
|
'is_archive' => is_archive(),
|
||||||
|
];
|
||||||
|
error_log("PageTypeDetector DEBUG [" . ($isLoggedIn ? "LOGGED" : "GUEST") . "]: " . json_encode($debugData));
|
||||||
|
|
||||||
if ($this->isHome()) {
|
if ($this->isHome()) {
|
||||||
return PageType::home();
|
return PageType::home();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user