WordPress / pattern-directory

The WordPress Block Pattern Directory
https://wordpress.org/patterns/
GNU General Public License v2.0
125 stars 35 forks source link

Avoid warning with invalid tax queries #681

Closed dd32 closed 6 months ago

dd32 commented 6 months ago
E_WARNING: ltrim() expects parameter 1 to be string, object given in wp-includes/formatting.php:4494

Source: GET https://example.org/?pattern-categories=1&s=the

get_term_link() can return a WP_Error when the input is invalid, this is then passed to esc_url().

This is a slightly hacky workaround by checking that get_queried_object() returns something before venturing into the taxonomy branch. Technically, it would probably be better to validate that get_term_link() return s a term, and that get_queried_object() return a WP_Term though.. so perhaps this could be && ( get_queried_object() instanceof \WP_Term )?