워드프레스는 기본적으로 최초 발행일을 표시하게 되어있다.
하지만 난 최초 발행일 뿐만 아니라 최종 수정시점을 표시하기 위해 아래 포스팅에서 작성한 것처럼 마지막 수정일 포함해서 반환하게 수정했었다
그 이후 며칠 아무 이상 없이 사이트가 잘 작동하는 줄 알았다
하지만 언제 부턴가 관리자 Dashboard 페이지가 일부만 표시되고 나머지 위젯들이 표시가 되지 않았다

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

하지만 어떤 문제로 인해 Site Health Status 를 보면 체크가 완료되지 않은 상태이며 다른 항목들도 제대로 로딩이 되지 않은 상태이다
그래서 확인도 할 겸 위 링크를 참조해서 로그를 남겨보니 다음과 같은 로그가 남는다.
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
0 Comments