Skip to content

Commit 555f4cd

Browse files
authored
Merge pull request #566 from pfefferle/fix/php8-null-array-handling
Fix PHP 8 TypeError in parse_post_json when JSON is invalid
2 parents 462295f + 263e566 commit 555f4cd

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

includes/handler/class-wp.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,18 @@ public function parse_post_json( Response $response, $timezone = null ) {
150150

151151
$page_json = json_decode( $response->get_body(), true );
152152

153+
if ( ! is_array( $page_json ) ) {
154+
return array();
155+
}
156+
153157
return array_filter(
154158
array(
155159
'name' => ifset( $page_json['title']['rendered'] ),
156160
'summary' => ifset( $page_json['excerpt']['rendered'] ),
157161
'content' => ifset( $page_json['content']['rendered'] ),
158162
'url' => ifset( $page_json['link'] ),
159-
'published' => new DateTimeImmutable( $page_json['date'], $timezone ),
160-
'updated' => new DateTimeImmutable( $page_json['modified'], $timezone ),
163+
'published' => isset( $page_json['date'] ) ? new DateTimeImmutable( $page_json['date'], $timezone ) : null,
164+
'updated' => isset( $page_json['modified'] ) ? new DateTimeImmutable( $page_json['modified'], $timezone ) : null,
161165
'author' => ifset( $page_json['_links']['author'][0]['href'] ),
162166
'_pagedata' => $page_json,
163167
)

0 commit comments

Comments
 (0)