From e94672533999351acdbdb770b76154ba6088268e Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Tue, 17 Oct 2023 10:01:33 +0200 Subject: [PATCH 1/2] Adds defensive coding to make sure warnings don't happen. --- src/helpers/current-page-helper.php | 8 +++++--- .../indexable-term-archive-presentation.php | 10 +++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/helpers/current-page-helper.php b/src/helpers/current-page-helper.php index 6109a77b932..28f6289925b 100644 --- a/src/helpers/current-page-helper.php +++ b/src/helpers/current-page-helper.php @@ -482,10 +482,12 @@ protected function get_non_cached_date_archive_permalink() { * @return int The amoumt of queried terms. */ protected function count_queried_terms() { - $wp_query = $this->wp_query_wrapper->get_main_query(); - $term = $wp_query->get_queried_object(); + $wp_query = $this->wp_query_wrapper->get_main_query(); + $term = $wp_query->get_queried_object(); + + $queried_terms = $wp_query->tax_query->queried_terms; - if ( empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { + if ( is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } diff --git a/src/presentations/indexable-term-archive-presentation.php b/src/presentations/indexable-term-archive-presentation.php index cd60880192f..295f84a5bb2 100644 --- a/src/presentations/indexable-term-archive-presentation.php +++ b/src/presentations/indexable-term-archive-presentation.php @@ -92,7 +92,7 @@ public function generate_meta_description() { * @return array The source. */ public function generate_source() { - if ( ! empty( $this->model->object_id ) ) { + if ( ! empty( $this->model->object_id ) || is_null( \get_queried_object() ) ) { return \get_term( $this->model->object_id, $this->model->object_sub_type ); } @@ -152,7 +152,7 @@ public function generate_robots() { * First we get the no index option for this taxonomy, because it can be overwritten the indexable value for * this specific term. */ - if ( ! $this->taxonomy->is_indexable( $this->source->taxonomy ) ) { + if ( is_wp_error( $this->source ) || ! $this->taxonomy->is_indexable( $this->source->taxonomy ) ) { $robots['index'] = 'noindex'; } @@ -172,7 +172,7 @@ public function generate_robots() { * @return string The title. */ public function generate_title() { - if ( $this->model->title ) { + if ( is_wp_error( $this->source ) || $this->model->title ) { return $this->model->title; } @@ -209,6 +209,10 @@ protected function is_multiple_terms_query() { return false; } + if ( is_wp_error( $this->source ) ) { + return false; + } + $queried_terms = $query->tax_query->queried_terms; if ( empty( $queried_terms[ $this->source->taxonomy ]['terms'] ) ) { From 94f4eacf42a581f612bea89189f0078d020c9ed6 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Tue, 17 Oct 2023 12:45:07 +0200 Subject: [PATCH 2/2] Change flow to not always generate a source object. --- src/presentations/indexable-term-archive-presentation.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/presentations/indexable-term-archive-presentation.php b/src/presentations/indexable-term-archive-presentation.php index 295f84a5bb2..460f83693d6 100644 --- a/src/presentations/indexable-term-archive-presentation.php +++ b/src/presentations/indexable-term-archive-presentation.php @@ -172,7 +172,11 @@ public function generate_robots() { * @return string The title. */ public function generate_title() { - if ( is_wp_error( $this->source ) || $this->model->title ) { + if ( $this->model->title ) { + return $this->model->title; + } + + if ( is_wp_error( $this->source ) ) { return $this->model->title; }