fix(php): toc fallback to raw content when filtered has no headings
When plugins like Thrive Visual Editor transform content for non-logged users, headings may be removed from the filtered content. This fix uses raw post_content as fallback when filtered content has no headings but raw content does. Also removes temporary debug logging added for diagnosis. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -36,16 +36,9 @@ final class EvaluateComponentVisibilityUseCase
|
||||
*/
|
||||
public function execute(string $componentName): bool
|
||||
{
|
||||
// DEBUG: Log for TOC only
|
||||
$debugToc = ($componentName === 'table-of-contents');
|
||||
|
||||
// Paso 1: Verificar visibilidad por tipo de pagina
|
||||
$visibleByPageType = $this->pageVisibilityUseCase->execute($componentName);
|
||||
|
||||
if ($debugToc) {
|
||||
error_log("EvaluateComponentVisibility [{$componentName}]: visibleByPageType=" . ($visibleByPageType ? "true" : "false"));
|
||||
}
|
||||
|
||||
if (!$visibleByPageType) {
|
||||
return false;
|
||||
}
|
||||
@@ -53,10 +46,6 @@ final class EvaluateComponentVisibilityUseCase
|
||||
// Paso 2: Verificar exclusiones
|
||||
$isExcluded = $this->exclusionsUseCase->execute($componentName);
|
||||
|
||||
if ($debugToc) {
|
||||
error_log("EvaluateComponentVisibility [{$componentName}]: isExcluded=" . ($isExcluded ? "true" : "false"));
|
||||
}
|
||||
|
||||
// Mostrar si NO esta excluido
|
||||
return !$isExcluded;
|
||||
}
|
||||
|
||||
@@ -28,27 +28,15 @@ final class EvaluatePageVisibilityUseCase
|
||||
{
|
||||
$config = $this->visibilityRepository->getVisibilityConfig($componentName);
|
||||
|
||||
// DEBUG: Log for TOC only
|
||||
$debugToc = ($componentName === 'table-of-contents');
|
||||
$usingDefaults = false;
|
||||
|
||||
if (empty($config)) {
|
||||
// Usar defaults especificos por componente si existen
|
||||
$config = VisibilityDefaults::getForComponent($componentName);
|
||||
$usingDefaults = true;
|
||||
}
|
||||
|
||||
$pageType = $this->pageTypeDetector->detect();
|
||||
$visibilityField = $pageType->toVisibilityField();
|
||||
$fieldValue = $config[$visibilityField] ?? true;
|
||||
$result = $this->toBool($fieldValue);
|
||||
|
||||
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;
|
||||
return $this->toBool($config[$visibilityField] ?? true);
|
||||
}
|
||||
|
||||
private function toBool(mixed $value): bool
|
||||
|
||||
@@ -43,15 +43,7 @@ final class PageVisibilityHelper
|
||||
$container = DIContainer::getInstance();
|
||||
$useCase = $container->getEvaluateComponentVisibilityUseCase();
|
||||
|
||||
$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;
|
||||
return $useCase->execute($componentName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,18 +15,6 @@ final class WordPressPageTypeDetector implements PageTypeDetectorInterface
|
||||
{
|
||||
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()) {
|
||||
return PageType::home();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user