WordPress.org

Make WordPress Core

Opened 7 weeks ago

Closed 7 weeks ago

#51247 closed defect (bug) (worksforme)

Uncaught Error rest-api.php:2209

Reported by: rpayne7264 Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.5
Component: REST API Keywords: reporter-feedback
Focuses: rest-api Cc:

Description

PHP Fatal error: Uncaught Error: Call to undefined method stdClass::get_rest_controller() in .../wp-includes/rest-api.php:2209

A check needs to be added to make sure $taxonomy is an instance of WP_Taxonomy. The root cause, however, may be the class definition has not been loaded yet, so PHP creates it as a "stdClass" (standard class.)

Change History (5)

#1 @TimothyBlynJacobs
7 weeks ago

  • Keywords reporter-feedback added
  • Version changed from 5.5.1 to 5.5

Hi @rpayne7264,

Thanks for the ticket! Could you share the code being used to register the taxonomy?

#2 @rpayne7264
7 weeks ago

  • Focuses rest-api added

Here you go:

	$taxonomy = get_taxonomy( $term->taxonomy );
	if ( ! $taxonomy ) {
		return '';
	}

	$controller = $taxonomy->get_rest_controller();
	if ( ! $controller ) {
		return '';
	}

This is in function rest_get_route_for_term in .../wp-includes/rest-api.php

#3 @TimothyBlynJacobs
7 weeks ago

Sorry, to clarify, I mean the code being used to register the taxonomy that isn't working, not the WordPress Core part.

#4 @rpayne7264
7 weeks ago

I do not know where the code to register the taxonomy is located.

#5 @TimothyBlynJacobs
7 weeks ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Without that, this will unfortunately be difficult to figure out the root cause. When calling `register_taxonomy`, WordPress uses the WP_Taxonomy class and its method immediately.

The only way I could see this happening would be if someone is manipulating the $wp_taxonomies global directly and using an stdClass instead of a WP_Taxonomy. WP_Taxonomy was added to Core in WordPress 4.7. So I think if someone did have a use case for manipulating that global directly, I think it is safe at this point to consider it to be doing it wrong if they aren't using the proper class at this point.

As such, I'm going to close out this ticket as worksforme to indicate that I can't reproduce this error when using the proper register_taxonomy API. If you find a way to replicate this issue when using the correct APIs, feel free to reopen the ticket.

Note: See TracTickets for help on using tickets.