From a76bb224f2d10f3d099138fd4546fb1dad6661a2 Mon Sep 17 00:00:00 2001 From: DustyReagan Date: Wed, 15 Nov 2023 22:43:35 +0100 Subject: [PATCH 1/6] Update existence checks --- src/blocks/homepage-articles/view.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/blocks/homepage-articles/view.php b/src/blocks/homepage-articles/view.php index 502bca5a9..688252cd7 100644 --- a/src/blocks/homepage-articles/view.php +++ b/src/blocks/homepage-articles/view.php @@ -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 ) ) { + $category_link = get_category_link( $category->term_id ); + $category_formatted = esc_html( $category->name ); - if ( ! empty( $category_link ) ) { - $category_formatted = '' . esc_html( $category->name ) . ''; - } + if ( ! empty( $category_link ) ) { + $category_formatted = '' . $category_formatted . ''; + } - if ( $category ) { return apply_filters( 'newspack_blocks_categories', $category_formatted ); } + + return ''; } + From 9bd63c467d3fb3b436314b358c84d8a0a77ecee3 Mon Sep 17 00:00:00 2001 From: DustyReagan Date: Wed, 15 Nov 2023 23:05:18 +0100 Subject: [PATCH 2/6] Simplify existence check --- src/blocks/homepage-articles/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blocks/homepage-articles/view.php b/src/blocks/homepage-articles/view.php index 688252cd7..2fa729604 100644 --- a/src/blocks/homepage-articles/view.php +++ b/src/blocks/homepage-articles/view.php @@ -524,7 +524,7 @@ function newspack_blocks_format_categories( $post_id ) { } // 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 ) ) { + if ( is_a( $category, 'WP_Term' ) ) { $category_link = get_category_link( $category->term_id ); $category_formatted = esc_html( $category->name ); From 3c8d6145bfffd827ba5fa76bf2802eb3266006e0 Mon Sep 17 00:00:00 2001 From: DustyReagan Date: Wed, 15 Nov 2023 23:08:01 +0100 Subject: [PATCH 3/6] Return early if not WP_Term --- src/blocks/homepage-articles/view.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/blocks/homepage-articles/view.php b/src/blocks/homepage-articles/view.php index 2fa729604..d495b9d68 100644 --- a/src/blocks/homepage-articles/view.php +++ b/src/blocks/homepage-articles/view.php @@ -523,18 +523,17 @@ function newspack_blocks_format_categories( $post_id ) { } } - // Check if $category is a valid object and has the required properties. - if ( is_a( $category, 'WP_Term' ) ) { - $category_link = get_category_link( $category->term_id ); - $category_formatted = esc_html( $category->name ); + if( ! is_a( $category, 'WP_Term' ) ){ + return ''; + } - if ( ! empty( $category_link ) ) { - $category_formatted = '' . $category_formatted . ''; - } + $category_link = get_category_link( $category->term_id ); + $category_formatted = esc_html( $category->name ); - return apply_filters( 'newspack_blocks_categories', $category_formatted ); + if ( ! empty( $category_link ) ) { + $category_formatted = '' . $category_formatted . ''; } - return ''; + return apply_filters( 'newspack_blocks_categories', $category_formatted ); } From 501437920bbfd2858b1dcc27adc999a21bc70224 Mon Sep 17 00:00:00 2001 From: DustyReagan Date: Wed, 15 Nov 2023 23:09:20 +0100 Subject: [PATCH 4/6] Remove extra newline at EOF --- src/blocks/homepage-articles/view.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/blocks/homepage-articles/view.php b/src/blocks/homepage-articles/view.php index d495b9d68..0ee539d93 100644 --- a/src/blocks/homepage-articles/view.php +++ b/src/blocks/homepage-articles/view.php @@ -536,4 +536,3 @@ function newspack_blocks_format_categories( $post_id ) { return apply_filters( 'newspack_blocks_categories', $category_formatted ); } - From c153ab51022efeb0c2e283b310072ca5aa7a6138 Mon Sep 17 00:00:00 2001 From: DustyReagan Date: Wed, 15 Nov 2023 23:12:02 +0100 Subject: [PATCH 5/6] Fix lint isssue --- src/blocks/homepage-articles/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blocks/homepage-articles/view.php b/src/blocks/homepage-articles/view.php index 0ee539d93..863c98fc0 100644 --- a/src/blocks/homepage-articles/view.php +++ b/src/blocks/homepage-articles/view.php @@ -523,7 +523,7 @@ function newspack_blocks_format_categories( $post_id ) { } } - if( ! is_a( $category, 'WP_Term' ) ){ + if( ! is_a( $category, 'WP_Term' ) ) { return ''; } From e23b9dc40de95013e633f8181ff320086073dbd3 Mon Sep 17 00:00:00 2001 From: DustyReagan Date: Wed, 15 Nov 2023 23:13:57 +0100 Subject: [PATCH 6/6] Maybe fix lint isssue --- src/blocks/homepage-articles/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blocks/homepage-articles/view.php b/src/blocks/homepage-articles/view.php index 863c98fc0..1e559fa67 100644 --- a/src/blocks/homepage-articles/view.php +++ b/src/blocks/homepage-articles/view.php @@ -523,7 +523,7 @@ function newspack_blocks_format_categories( $post_id ) { } } - if( ! is_a( $category, 'WP_Term' ) ) { + if ( ! is_a( $category, 'WP_Term' ) ) { return ''; }