Skip to content

Commit

Permalink
Adds defensive coding to make sure warnings don't happen.
Browse files Browse the repository at this point in the history
  • Loading branch information
thijsoo committed Oct 17, 2023
1 parent 449bd2b commit e946725
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/helpers/current-page-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
10 changes: 7 additions & 3 deletions src/presentations/indexable-term-archive-presentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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';
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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'] ) ) {
Expand Down

0 comments on commit e946725

Please sign in to comment.