Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update existence checks in newspack_blocks_format_categories #1596

Merged
merged 6 commits into from
Nov 16, 2023
Merged
Changes from 1 commit
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
16 changes: 10 additions & 6 deletions src/blocks/homepage-articles/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,14 +523,18 @@ function newspack_blocks_format_categories( $post_id ) {
}
}

$category_link = get_category_link( $category->term_id );
$category_formatted = esc_html( $category->name );
// Check if $category is a valid object and has the required properties.
if ( is_a( $category, 'WP_Term' ) && isset( $category->term_id ) && isset( $category->name ) ) {
DustyReagan marked this conversation as resolved.
Show resolved Hide resolved
$category_link = get_category_link( $category->term_id );
$category_formatted = esc_html( $category->name );

if ( ! empty( $category_link ) ) {
$category_formatted = '<a href="' . esc_attr( $category_link ) . '">' . esc_html( $category->name ) . '</a>';
}
if ( ! empty( $category_link ) ) {
$category_formatted = '<a href="' . esc_url( $category_link ) . '">' . $category_formatted . '</a>';
}

if ( $category ) {
return apply_filters( 'newspack_blocks_categories', $category_formatted );
}

return '';
}