Debug: Add file-based logging to bypass WP_DEBUG

This commit is contained in:
FrankZamora
2025-11-27 13:36:41 -06:00
parent 4ac03bd3e2
commit 83b594a750

View File

@@ -32,16 +32,17 @@ final class YoutubeFacadeContentFilter
*/
public function filter(string $content): string
{
// DEBUG: Log that filter is being called
error_log('YoutubeFacade: filter() called, content length: ' . strlen($content));
// DEBUG: File-based logging (bypass WP_DEBUG)
$logFile = '/tmp/youtube-facade-debug.log';
file_put_contents($logFile, date('Y-m-d H:i:s') . " - filter() called, content length: " . strlen($content) . "\n", FILE_APPEND);
// Check if content has YouTube embeds at all (quick check)
if (strpos($content, 'youtube.com/embed/') === false && strpos($content, 'youtube-nocookie.com/embed/') === false) {
error_log('YoutubeFacade: No YouTube embeds found in quick check');
file_put_contents($logFile, date('Y-m-d H:i:s') . " - No YouTube embeds found in quick check\n", FILE_APPEND);
return $content;
}
error_log('YoutubeFacade: YouTube embed detected, applying regex');
file_put_contents($logFile, date('Y-m-d H:i:s') . " - YouTube embed detected, applying regex\n", FILE_APPEND);
// Pattern to match YouTube iframes
// Handles: youtube.com/embed/ and youtube-nocookie.com/embed/
@@ -49,18 +50,18 @@ final class YoutubeFacadeContentFilter
$pattern = '/<iframe\s+[^>]*src=["\']https?:\/\/(?:www\.)?(?:youtube\.com|youtube-nocookie\.com)\/embed\/([a-zA-Z0-9_-]+)[^"\']*["\'][^>]*>\s*<\/iframe>/is';
$matchCount = 0;
$result = preg_replace_callback($pattern, function ($matches) use (&$matchCount) {
$result = preg_replace_callback($pattern, function ($matches) use (&$matchCount, $logFile) {
$matchCount++;
$videoId = $matches[1];
error_log('YoutubeFacade: Matched video ID: ' . $videoId);
file_put_contents($logFile, date('Y-m-d H:i:s') . " - Matched video ID: " . $videoId . "\n", FILE_APPEND);
return $this->renderer->render($videoId);
}, $content);
error_log('YoutubeFacade: Regex replaced ' . $matchCount . ' iframes');
file_put_contents($logFile, date('Y-m-d H:i:s') . " - Regex replaced " . $matchCount . " iframes\n", FILE_APPEND);
// Return original content if regex failed
if ($result === null) {
error_log('YoutubeFacade: preg_replace_callback returned null (regex error)');
file_put_contents($logFile, date('Y-m-d H:i:s') . " - preg_replace_callback returned null (regex error)\n", FILE_APPEND);
return $content;
}