Skip to content

Commit d3dea22

Browse files
authored
Related Posts: Prevent PHP warnings when settings are malformed (#45538)
1 parent f377106 commit d3dea22

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: other
3+
4+
Related Posts: Prevent PHP errors when settings are malformed.

projects/plugins/jetpack/modules/related-posts/jetpack-related-posts.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function action_frontend_init() {
198198
public function get_headline() {
199199
$options = $this->get_options();
200200

201-
if ( $options['show_headline'] ) {
201+
if ( ! empty( $options['show_headline'] ) ) {
202202
$headline = sprintf(
203203
/** This filter is already documented in modules/sharedaddy/sharing-service.php */
204204
apply_filters( 'jetpack_sharing_headline_html', '<h3 class="jp-relatedposts-headline"><em>%s</em></h3>', esc_html( $options['headline'] ), 'related-posts' ),
@@ -931,7 +931,7 @@ public function get_for_post_id( $post_id, array $args ) {
931931
}
932932

933933
if (
934-
! $options['enabled']
934+
empty( $options['enabled'] )
935935
|| 0 === (int) $post_id
936936
|| empty( $options['size'] )
937937
) {
@@ -1305,15 +1305,15 @@ protected function action_frontend_init_ajax( array $excludes ) {
13051305

13061306
$response = array(
13071307
'version' => self::VERSION,
1308-
'show_thumbnails' => (bool) $options['show_thumbnails'],
1309-
'show_date' => (bool) $options['show_date'],
1310-
'show_context' => (bool) $options['show_context'],
1311-
'layout' => (string) $options['layout'],
1312-
'headline' => (string) $options['headline'],
1308+
'show_thumbnails' => (bool) ( $options['show_thumbnails'] ?? false ),
1309+
'show_date' => (bool) ( $options['show_date'] ?? true ),
1310+
'show_context' => (bool) ( $options['show_context'] ?? true ),
1311+
'layout' => (string) ( $options['layout'] ?? 'grid' ),
1312+
'headline' => (string) ( $options['headline'] ?? '' ),
13131313
'items' => array(),
13141314
);
13151315

1316-
if ( count( $related_posts ) === $options['size'] ) {
1316+
if ( ! empty( $options['size'] ) && count( $related_posts ) === $options['size'] ) {
13171317
$response['items'] = $related_posts;
13181318
}
13191319

0 commit comments

Comments
 (0)