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:
FrankZamora
2025-12-06 23:03:42 -06:00
parent 5333531be4
commit 0c1908e7d1
5 changed files with 67 additions and 3 deletions

View File

@@ -43,20 +43,30 @@ final class TableOfContentsRenderer implements RendererInterface
{
$data = $component->getData();
// DEBUG TOC: Log all visibility checks
$isLoggedIn = is_user_logged_in();
$debugPrefix = "TOC DEBUG [" . ($isLoggedIn ? "LOGGED" : "GUEST") . "]";
if (!$this->isEnabled($data)) {
error_log("{$debugPrefix}: SKIP - isEnabled=false");
return '';
}
if (!PageVisibilityHelper::shouldShow(self::COMPONENT_NAME)) {
$shouldShow = PageVisibilityHelper::shouldShow(self::COMPONENT_NAME);
if (!$shouldShow) {
error_log("{$debugPrefix}: SKIP - PageVisibilityHelper::shouldShow=false");
return '';
}
$tocItems = $this->generateTocItems($data);
if (empty($tocItems)) {
error_log("{$debugPrefix}: SKIP - tocItems empty");
return '';
}
error_log("{$debugPrefix}: RENDER - passed all checks, items=" . count($tocItems));
$css = $this->generateCSS($data);
$html = $this->buildHTML($data, $tocItems);
$script = $this->buildScript($data);
@@ -107,12 +117,21 @@ final class TableOfContentsRenderer implements RendererInterface
{
global $post;
// DEBUG: Track content processing
$isLoggedIn = is_user_logged_in();
$debugPrefix = "TOC generateTocFromContent [" . ($isLoggedIn ? "LOGGED" : "GUEST") . "]";
if (!$post || empty($post->post_content)) {
error_log("{$debugPrefix}: SKIP - no post or empty content");
return [];
}
error_log("{$debugPrefix}: post_id={$post->ID}, raw_content_length=" . strlen($post->post_content));
$content = apply_filters('the_content', $post->post_content);
error_log("{$debugPrefix}: filtered_content_length=" . strlen($content));
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML('<?xml encoding="utf-8" ?>' . $content);
@@ -127,6 +146,8 @@ final class TableOfContentsRenderer implements RendererInterface
$headings = $xpath->query($xpathQuery);
error_log("{$debugPrefix}: headings_found=" . $headings->length);
if ($headings->length === 0) {
return [];
}