워드프레스 Twenty Twenty-Two, Twenty Twenty-Three 테마에서 특정 게시물 접속 안되는 문제 수정하기

워드프레스 에러 화면

웹서버 에러 로그 보니 특정 페이지에서 에러가 나는걸 확인했습니다.

2022/12/11 09:28:19 [error] 79223#79223: *30768 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught ArgumentCountError: 25 arguments are required, 1 given in /www/wordpress/wp-includes/blocks/comment-template.php:70
Stack trace:
#0 /wordpress/wp-includes/blocks/comment-template.php(70): sprintf()
#1 /wordpress/wp-includes/blocks/comment-template.php(62): block_core_comment_template_render_comments()
#2 /wordpress/wp-includes/blocks/comment-template.php(55): block_core_comment_template_render_comments()
#3 /wordpress/wp-includes/blocks/comment-template.php(123): block_core_comment_template_render_comments()
#4 /wordpress/wp-includes/class-wp-block.php(256): render_block_core_comment_template()
#5 /wordpress/wp-includes/class-wp-block.php(242): WP_Block->render()
#6 /wordpress/wp-includes/blocks/comments.php(45): WP_Block->render()
#7 /wordpress/wp-includes/c" while reading response header from upstream, client: 192.168.0.1, server: linsoo.pe.kr, request: "GET /%ed%8b%b0%ec%8a%a4%ed%86%a0%eb%a6%ac-%ed%83%88%ed%87%b4-%ec%99%84%eb%a3%8c/ HTTP/2.0", upstream: "fastcgi://unix:/var/run/php/php-fpm.sock:", host: "linsoo.pe.kr", referrer: ""

에러는 위와 같고 대충 보면 그냥 워드프레스 자체 버그인줄 알았는데… 어제까지는 분명 멀쩡했단 말이죠. 워드프레스가 업데이트 한것도 아니고요.

뭐가 바뀌었나 고민하다가 보니 제가 어제부터 주소체계를 /archives/%post_id% 에서 %post_name%으로 바꾼게 생각났습니다. 그래서 원상 복구 하고 다시 테스트 하니 멀쩡하게 돌아갑니다 -_-;

그래서 에러코드랑 해당 소스를 확인해 봤는데

if ( ! empty( $children ) && ! empty( $thread_comments ) ) {
    if ( $comment_depth < $thread_comments_depth ) {
        $comment_depth += 1;
        $inner_content  = block_core_comment_template_render_comments(
            $children,
            $block
        );
        $block_content .= sprintf( '<ol>%1$s</ol>', $inner_content );
        $comment_depth -= 1;
    } else {
        $inner_content  = block_core_comment_template_render_comments(
            $children,
            $block
        );
        $block_content .= sprintf( $inner_content );
    }
}

15번째줄인 $block_content .= sprintf( $inner_content ); 에서 에러가 나는것이였습니다.

저 $inner_content 값에 뭐가 들어가는지 봤는데 댓글 페이지 만드는 html 코드 였습니다. 그 중에 아래 부분이 문제였습니다.

<a href="https://linsoo.pe.kr/%ed%8b%b0%ec%8a%a4%ed%86%a0%7%b4-%ec%99%84%eb%a3%8c/#comment-3380">2017년 1월 4일</a>

URL이 한글이라 UTF8로 인코딩 됬는데 % 항목이 들어가니 php sprintf 가 저걸 인자로 받기 때문에 생기는 버그였죠.

$inner_content = preg_replace('/%/mi', "%%",$inner_content);				
$block_content .= sprintf( $inner_content );

기존 코드 위에 정규식으로 대체 하는 한줄만 넣어주면 해결 됩니다만… 나중에 워드프레스 업데이트 되면 날라갈테니 원상복구 되겠죠. (양키 애덜이라 이런 문제는 겪어보지 못할테니 아마 패치 안될 가능성도 높아보입니다.)

댓글 URL 표시

저 URL이 들어가는 부분은 바로 댓글의 저 댓글 링크 부분이었습니다.

댓글 링크 설정

사이트 테마 편집에서 댓글 날짜 링크를 꺼버리면 역시 간편하게 해결 됩니다. 후자의 방법이 아마 나중에 워드프레스 업데이트 되도 영향을 받지 않으니 괜찮을거 같습니다.

워드프레스 permalink 설정화면

아니면 워드프레스 permalink 설정을 한글이 들어갈 가능성이 없는 걸로 선택하는것도 한 방법이 되겠습니다. (저는 구글 SEO가 permalink엔 글 제목을 추천한다고 해서 글 이름으로 했습니다)

아참 위 문제는 블럭에디트 방식 테마에서 발생하는것으로 글 제목처럼 Twenty Twenty-Two, Twenty Twenty-Three 이 두 테마에서 동일하게 발생했습니다. 아마 다른 블럭에티트 방식 테마에서도 발생할거라 예상됩니다.


Comments

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다