Skip to content

Commit

Permalink
Contact Form: avoid errors when saved feedback is not a WP_Post (#34129)
Browse files Browse the repository at this point in the history
Fixes #34125

Saved feedback forms can be `WP_Post`, `array`, or `null`.
Let's not assume we'll always get a `WP_Post`, and be more defensive.
  • Loading branch information
jeherve authored Nov 17, 2023
1 parent 5181de4 commit 5e943c1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Avoid errors when a saved feedback form does not have the expected WP_Post format.
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ public static function get_compiled_form( $feedback_id, $form ) {
}
} else {
// The feedback content is stored as the first "half" of post_content
$value = $feedback->post_content;
$value = is_a( $feedback, '\WP_Post' ) ? $feedback->post_content : '';
list( $value ) = explode( '<!--more-->', $value );
$value = trim( $value );
}
Expand Down Expand Up @@ -619,7 +619,7 @@ public static function get_compiled_form_for_email( $feedback_id, $form ) {
}
} else {
// The feedback content is stored as the first "half" of post_content
$value = $feedback->post_content;
$value = is_a( $feedback, '\WP_Post' ) ? $feedback->post_content : '';
list( $value ) = explode( '<!--more-->', $value );
$value = trim( $value );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

Contact Form: avoid errors when a saved submitted contact form is requested but does not exist anymore.
Original file line number Diff line number Diff line change
Expand Up @@ -3089,7 +3089,7 @@ public static function get_compiled_form( $feedback_id, $form ) {
}
} else {
// The feedback content is stored as the first "half" of post_content
$value = $feedback->post_content;
$value = is_a( $feedback, '\WP_Post' ) ? $feedback->post_content : '';
list( $value ) = explode( '<!--more-->', $value );
$value = trim( $value );
}
Expand Down Expand Up @@ -3182,7 +3182,7 @@ public static function get_compiled_form_for_email( $feedback_id, $form ) {
}
} else {
// The feedback content is stored as the first "half" of post_content
$value = $feedback->post_content;
$value = is_a( $feedback, '\WP_Post' ) ? $feedback->post_content : '';
list( $value ) = explode( '<!--more-->', $value );
$value = trim( $value );
}
Expand Down

0 comments on commit 5e943c1

Please sign in to comment.