워드프레스 디버깅

Published Aug 29, 2022 | Updated Sep 23, 2022 | 0 comments

워드프레스는 기본적으로 최초 발행일을 표시하게 되어있다.

하지만 난 최초 발행일 뿐만 아니라 최종 수정시점을 표시하기 위해 아래 포스팅에서 작성한 것처럼 마지막 수정일 포함해서 반환하게 수정했었다

그 이후 며칠 아무 이상 없이 사이트가 잘 작동하는 줄 알았다

하지만 언제 부턴가 관리자 Dashboard 페이지가 일부만 표시되고 나머지 위젯들이 표시가 되지 않았다

정상적인 상황에서는 Site Health Status 가 정상적으로 표시되고 다른 항목들도 모두 잘 표시가 된 상태이다.


하지만 어떤 문제로 인해 Site Health Status 를 보면 체크가 완료되지 않은 상태이며 다른 항목들도 제대로 로딩이 되지 않은 상태이다


https://wordpress.org/support/article/debugging-in-wordpress/#wp_debug

그래서 확인도 할 겸 위 링크를 참조해서 로그를 남겨보니 다음과 같은 로그가 남는다.

dashboard.php 파일의 1001 번째 코드를 보면 999 번째 라인에서 get_the_time(‘U’) 으로 할당된 $time 변수 때문에 오류가 발생하면서 Dashboard 페이지만 문제가 되었던 것 가다.

[29-Aug-2022 12:00:10 UTC] PHP Fatal error:  Uncaught TypeError: gmdate(): Argument #2 ($timestamp) must be of type ?int, string given in wp-admin/includes/dashboard.php:1001
Stack trace:
#0 wp-admin/includes/dashboard.php(1001): gmdate('Y-m-d', 'Last updated Au...')
#1 wp-admin/includes/dashboard.php(930): wp_dashboard_recent_posts(Array)
#2 wp-admin/includes/template.php(1401): wp_dashboard_site_activity('', Array)
#3 wp-admin/includes/dashboard.php(265): do_meta_boxes(Object(WP_Screen), 'normal', '')
#4 wp-admin/index.php(203): wp_dashboard()
#5 {main}
  thrown in wp-admin/includes/dashboard.php on line 1001

아래에 표시된 소스코드는 에러가 발생하는 부분의 소스코드이다.

		$today    = current_time( 'Y-m-d' );
		$tomorrow = current_datetime()->modify( '+1 day' )->format( 'Y-m-d' );
		$year     = current_time( 'Y' );

		while ( $posts->have_posts() ) {
			$posts->the_post();

			$time = get_the_time( 'U' );

			if ( gmdate( 'Y-m-d', $time ) === $today ) {
				$relative = __( 'Today' );
			} elseif ( gmdate( 'Y-m-d', $time ) === $tomorrow ) {
				$relative = __( 'Tomorrow' );
			} elseif ( gmdate( 'Y', $time ) !== $year ) {
				/* translators: Date and time format for recent posts on the dashboard, from a different calendar year, see https://www.php.net/manual/datetime.format.php */
				$relative = date_i18n( __( 'M jS Y' ), $time );
			} else {
				/* translators: Date and time format for recent posts on the dashboard, see https://www.php.net/manual/datetime.format.php */
				$relative = date_i18n( __( 'M jS' ), $time );
			}

get_the_time 을 날짜 형식이 아니라 일반 텍스트 조합으로 반환되게 수정해서 문제가 되었다 ㅡㅡ;;

그래서 관리자 페이지 인 경우 제외하는 조건을 추가해서 해결했다.

관리자 페이지에서는 기존처럼 날짜 형식으로 반환을 하고 그 이외에만 내가 원하는 방식으로 반환되게 수정한다.

수정된 소스 코드는 다음과 같다.

// BEGIN LastUpdatedDate
function last_modified_date_blog( $the_date ) {
    if ( !is_admin() ) {
        $published = get_post_time('M j, Y');
        $lastupdated = get_post_modified_time('M j, Y');
        if($published !== $lastupdated) {
            return sprintf( __( 'Last updated %s | Published %s ', 'Divi' ), esc_html( get_post_modified_time( 'M j, Y' ) ), esc_html( get_post_time( 'M j, Y' ) ) );
        }
    }
    return $the_date;
}
add_filter( 'get_the_date', 'last_modified_date_blog' );
add_filter( 'get_the_time', 'last_modified_date_blog' );
// END LastUpdatedDate

TAG INFORMATION

Learn more on this topic

Related Blog Posts

워드프레스 Github 플러그인

워드프레스 Github 플러그인

워드프레스에서 Github 저장소를 포함하기 위해 사용 중이던 Embed Block for GitHub 플러그인의 버그 발생과 더 이상 유지 보수가 안되는 상황에서 새로운 플러그인(Github Embed)을 소개하고 해당 플러그인으로 대체 하게 된 상황에 대해 설명합니다.

read more

Join in the conversation

Leave a Comment

0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

무료 온라인 전광판

전광판

텍스트를 입력하고 텍스트 효과 및 배경효과 를 변경해서 전체화면으로 표시할 수 있는 전광판 용도로 사용하실 수 있습니다. 각종 스포츠 및 공연 관람시 응원 용도로 사용이 가능합니다.

Carousel

여러개의 슬라이드를 추가하여 프레젠테이션 및 이미지 슬라이드 용도로 사용하실 수 있습니다. 브라우저가 포함된 IT 기기로 큰 모니터에 연결하여 매장 내 공지사항 및 메뉴소개를 이미지로 표시할 수 있습니다.

Pin It on Pinterest

Shares
Share This

Share This

Share this post with your friends!

Shares