johnbillion / query-monitor

The developer tools panel for WordPress
https://querymonitor.com
GNU General Public License v2.0
1.58k stars 207 forks source link

Fix Fatal error: Object of class WP_Term could not be converted to string #839

Closed rubas closed 6 months ago

rubas commented 9 months ago

Error

Fatal error: Uncaught Error: Object of class WP_Term could not be converted to string in /query-monitor/collectors/theme.php on line 119

Reproduce

  1. Define a taxonomy called sidebar
  2. wp/wp-includes/taxonomy.php:1015 executes $_term = apply_filters( "get_{$taxonomy}", $_term, $taxonomy );
  3. web/app/plugins/query-monitor/collectors/theme.php catches the action ( 'get_sidebar', array( $this, 'action_get_position' ));
  4. and the function action_get_position will explode
johnbillion commented 9 months ago

Yikes. I'm happy to put in a workaround, but I would strongly recommend using a different name for your taxonomy to avoid the problem altogether.

johnbillion commented 6 months ago

I've decided to close this off. There are really too many potential problems using a taxonomy with a name that matches an entity in WordPress, and no doubt other plugins that rightfully expect the parameter that's passed to this hook to be a string. I know it's frustrating, it's a shame that there are so many actions and filters in WordPress that have overly generic names.

Cheers!