admin管理员组

文章数量:1322850

I have a site using a customized version of this plugin: /

After installing Wordpress 5.5, any of the taxonomy display pages generate this fatal error:

PHP Fatal error:  Uncaught Error: Call to undefined method stdClass::get_rest_controller() in /home/abc/domains/mydomain/public_html/wp-includes/rest-api.php:2209
Stack trace:
#0 /home/abc/domains/mydomain/public_html/wp-includes/rest-api.php(2245): rest_get_route_for_term(Object(WP_Term))
#1 /home/abc/domains/mydomain/public_html/wp-includes/rest-api.php(943): rest_get_queried_resource_route()
#2 /home/abc/domains/mydomain/public_html/wp-includes/class-wp-hook.php(285): rest_output_link_header()
#3 /home/abc/domains/mydomain/public_html/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array)
#4 /home/abc/domains/mydomain/public_html/wp-includes/plugin.php(478): WP_Hook->do_action(Array)
#5 /home/abc/domains/mydomain/public_html/wp-includes/template-loader.php(13): do_action('template_redire...')
#6 /home/abc/domains/mydomain/public_html/wp-blog-header.php(19): require_once('/home/abc/domai...')
#7 /home/abc/domains/mydomain in /home/abc/domains/mydomain/public_html/wp-includes/rest-api.php on line 2209

Rolling back WP to 5.4.2 restores functionality.

I tried installing the same plugin on a clean version of 5.5 with an unmodified version of the plugin, and I get the same error.

The plugin appears abandoned, but it's a pretty small codebase. I haven't been able to identify the what's triggering the fatal error, and haven't been able to find any other questions noting similar errors. If anyone has any thoughts, it would be greatly appreciated!

I have a site using a customized version of this plugin: https://wordpress/plugins/user-tags/

After installing Wordpress 5.5, any of the taxonomy display pages generate this fatal error:

PHP Fatal error:  Uncaught Error: Call to undefined method stdClass::get_rest_controller() in /home/abc/domains/mydomain/public_html/wp-includes/rest-api.php:2209
Stack trace:
#0 /home/abc/domains/mydomain/public_html/wp-includes/rest-api.php(2245): rest_get_route_for_term(Object(WP_Term))
#1 /home/abc/domains/mydomain/public_html/wp-includes/rest-api.php(943): rest_get_queried_resource_route()
#2 /home/abc/domains/mydomain/public_html/wp-includes/class-wp-hook.php(285): rest_output_link_header()
#3 /home/abc/domains/mydomain/public_html/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array)
#4 /home/abc/domains/mydomain/public_html/wp-includes/plugin.php(478): WP_Hook->do_action(Array)
#5 /home/abc/domains/mydomain/public_html/wp-includes/template-loader.php(13): do_action('template_redire...')
#6 /home/abc/domains/mydomain/public_html/wp-blog-header.php(19): require_once('/home/abc/domai...')
#7 /home/abc/domains/mydomain in /home/abc/domains/mydomain/public_html/wp-includes/rest-api.php on line 2209

Rolling back WP to 5.4.2 restores functionality.

I tried installing the same plugin on a clean version of 5.5 with an unmodified version of the plugin, and I get the same error.

The plugin appears abandoned, but it's a pretty small codebase. I haven't been able to identify the what's triggering the fatal error, and haven't been able to find any other questions noting similar errors. If anyone has any thoughts, it would be greatly appreciated!

Share Improve this question asked Sep 17, 2020 at 19:37 Hugh MongooseHugh Mongoose 111 bronze badge 0
Add a comment  | 

1 Answer 1

Reset to default 3

Since 5.5 WP_Taxonomy objects now have a new method, get_rest_controller(), to allow for per-taxonomy controller overrides. The problem is that your plugin overwrites the taxonomy saved in the global $wp_taxonomies cache with a version that isn't a real WP_Taxonomy object, just a stdObject property bag, and so does not have get_rest_controller() to call.

This is the relevant bit: ut_registered_taxonomy() in UserTags.php lines 83-101, which is a registered_taxonomy action handler.

public function ut_registered_taxonomy( $taxonomy, $object, $args ) {
    global $wp_taxonomies;

    // Only modify user taxonomies, everything else can stay as is
    if ( $object != 'user' ) {
        return;
    }

    // Array => Object
    $args = (object) $args;

    // Register any hooks/filters that rely on knowing the taxonomy now
    add_filter( "manage_edit-{$taxonomy}_columns", array( $this, 'set_user_column' ) );
    add_filter( "manage_{$taxonomy}_custom_column",
                 array( $this, 'set_user_column_values' ), 10, 3 );

    // Save changes
    $wp_taxonomies[ $taxonomy ]    = $args;  // <--- this line is the problem
    self::$taxonomies[ $taxonomy ] = $args;
}

Note the line I've marked just below the "Save changes" comment: this overwrites the existing value of $wp_taxonomies[ $taxonomy ] with a bad value, and isn't needed anyway because there haven't been any changes made to the taxonomy properties. So I'd suggest just deleting this line as the simplest fix.

(In fairness to this code it was written before the WP_Taxonomy class was added in 4.7. And back then the (object) cast was the correct way to make a taxonomy object from $args if you had changed the contents of $args and needed to update $wp_taxonomies.)

We could now also now ensure we have a real WP_Taxonomy object in self::$taxonomies too, e.g. rather than $args = (object) $args) fetch the real object from $wp_taxonomies $args = $wp_taxonomies[ $taxonomy ] where it was placed shortly before this call. But I don't think that's actually necessary here.

本文标签: WP 55 Fatal Errorgetrestcontroller() in restapiphp