Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/fix-related-posts-warnings
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Related Posts: Prevent PHP errors when settings are malformed.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function action_frontend_init() {
public function get_headline() {
$options = $this->get_options();

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

if (
! $options['enabled']
empty( $options['enabled'] )
|| 0 === (int) $post_id
|| empty( $options['size'] )
) {
Expand Down Expand Up @@ -1305,15 +1305,15 @@ protected function action_frontend_init_ajax( array $excludes ) {

$response = array(
'version' => self::VERSION,
'show_thumbnails' => (bool) $options['show_thumbnails'],
'show_date' => (bool) $options['show_date'],
'show_context' => (bool) $options['show_context'],
'layout' => (string) $options['layout'],
'headline' => (string) $options['headline'],
'show_thumbnails' => (bool) ( $options['show_thumbnails'] ?? false ),
'show_date' => (bool) ( $options['show_date'] ?? true ),
'show_context' => (bool) ( $options['show_context'] ?? true ),
'layout' => (string) ( $options['layout'] ?? 'grid' ),
'headline' => (string) ( $options['headline'] ?? '' ),
'items' => array(),
);

if ( count( $related_posts ) === $options['size'] ) {
if ( ! empty( $options['size'] ) && count( $related_posts ) === $options['size'] ) {
$response['items'] = $related_posts;
}

Expand Down
Loading