Skip to content

Commit 632c441

Browse files
authored
Comments: Fix fatal when comment form defaults are null (#53860)
1 parent 7514a97 commit 632c441

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Fix fatal errors when another plugin or theme returns an empty value from a comment form or comment content filter.

‎projects/packages/comments/src/editor/class-block-editor.php‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ private static function restore( array $blocks, &$images = 0 ) {
181181
/**
182182
* Let the tags these blocks save through kses, for a comment that holds them.
183183
*
184-
* @param array $tags Allowed tags.
185-
* @param string $context The kses context.
184+
* @param array|mixed $tags Allowed tags. Null when an earlier filter drops them.
185+
* @param string $context The kses context.
186186
* @return array
187187
*/
188188
public function allowed_html( $tags, $context ) {
@@ -191,7 +191,7 @@ public function allowed_html( $tags, $context ) {
191191
}
192192

193193
return array_merge(
194-
$tags,
194+
(array) $tags,
195195
array(
196196
'p' => array(),
197197
'br' => array(),
@@ -218,12 +218,12 @@ public function allowed_html( $tags, $context ) {
218218
/**
219219
* The comment's HTML without the block delimiters, and without any block the editor does not offer.
220220
*
221-
* @param string $content Comment content.
221+
* @param string|mixed $content Comment content.
222222
* @param \WP_Comment|null $comment The comment, where the caller has it.
223-
* @return string
223+
* @return string|mixed
224224
*/
225225
public static function render( $content, $comment = null ) {
226-
if ( ! has_blocks( $content ) ) {
226+
if ( ! is_string( $content ) || ! has_blocks( $content ) ) {
227227
return $content;
228228
}
229229

@@ -237,11 +237,15 @@ public static function render( $content, $comment = null ) {
237237
/**
238238
* Core's comment email, with the comment's block markup replaced by the text it draws.
239239
*
240-
* @param string $message The email body.
241-
* @param int $comment_id The comment the email is about.
242-
* @return string
240+
* @param string|mixed $message The email body.
241+
* @param int $comment_id The comment the email is about.
242+
* @return string|mixed
243243
*/
244244
public static function render_in_email( $message, $comment_id ) {
245+
if ( ! is_string( $message ) ) {
246+
return $message;
247+
}
248+
245249
$comment = get_comment( $comment_id );
246250

247251
if ( ! $comment instanceof \WP_Comment || ! has_blocks( $comment->comment_content ) ) {

‎projects/packages/comments/src/form/class-comment-form.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function comment_form_logged_in( $logged_in_as ) {
163163
/**
164164
* Set the form arguments the app reads back out.
165165
*
166-
* @param array $args Comment form arguments.
166+
* @param array|mixed $args Comment form arguments. Null when an earlier filter drops them.
167167
* @return array
168168
*/
169169
public function comment_form_defaults( $args ) {
@@ -183,7 +183,7 @@ public function comment_form_defaults( $args ) {
183183
$defaults['title_reply'] = $greeting;
184184
}
185185

186-
$this->defaults = array_merge( $args, $defaults );
186+
$this->defaults = array_merge( (array) $args, $defaults );
187187

188188
return $this->defaults;
189189
}

0 commit comments

Comments
 (0)