Notice: register_rest_route was called incorrectly

In my Wordpress site, this issue appears when adding or editing posts.

Notice: register_rest_route was called incorrectly. REST API routes must be registered on the rest_api_init action. Please see Debugging in WordPress for more information. (This message was added in version 5.1.0.) in /project/wp/wp-includes/functions.php on line 5167

Note: I didn't make any WP update or any plugin update on the site.

Any idea to fix this issue? Thank you.

Solutions

In WordPress 5.5, a change was made to how REST routes are registered and now required a permission_callback.

The reason you may see it the notice on one site and not all is that notices only appear when WordPress is run in DEBUG mode, confirm by checking the value of wp-config.php for

define( 'WP_DEBUG', true );

If the site showing the notices should not be in debug mode , simply change the value of WP_DEBUG to false .

A plugin or your theme are creating a REST-Api route in a wrong hook. This is correctly done by using add_action('rest_api_init', 'function_to_create_end_endpoint');

function_to_create_endpoint contains the function register_rest_route().

In your case it's something else ('init' or 'plugins_loaded' instead of 'rest_api_init')

Some solutions:

  • Update all Plugins/your Theme to a current Version
  • If this doesn't help you can: Deactivate Plugins one by one, to see which one causes the issue, than maybe replace it or check if is abandoned
  • Search for "register_rest_route" in your wp-content folder and find the plugin that calls it in a hook something other than "rest_api_init".
  • Lastly Notices only show up when you turn on full debugging in your wp-config, this isn't meant for sites running in production. You could turn it off.

Similar questions

string(2) "id" Notice: id was called incorrectly. Product properties should not be accessed directly. Backtrace:
string(2) "id" Notice: id was called incorrectly. Product properties should not be accessed directly. Backtrace: require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/plugins/woocommerce/templates/single-product.php'), wc_get_template_part, load_template, require('/plugins/woocommerce/templates/content-...
Getting notice is wordpress "WP_Scripts::localize was called incorrectly"
Complete message: Notice: WP_Scripts::localize was called incorrectly. The $l10n parameter must be an array. To pass arbitrary data to scripts, use the wp_add_inline_script() function instead. Please see Debugging in WordPress for more information. (This message was added in version 5.7.0.) in /home3/dduconne/public_html/wp-includes/functions.php o...
In a Wordpress plugin, why doesn't `register_rest_route()` work when called in the activation hook?
I have this (example) plugin: When I activate this plugin, the /wp-json/great-plugin/v1/hello route does not exist. However, if I move the add_action call to the top level, like so: then the /wp-json/great-plugin/v1/hello route exists and responds to GET requests with "Hello, world!". Why doesn't the endpoint get registered when the registration ha...
Fatal error: Call to undefined function register_rest_route()
I get the error Fatal error: Call to undefined function register_rest_route() when I try to go to example.com/wp-json. What is wrong? This is how my code looks like:
register_rest_route regex option for base64 or alternate
What I tested Wordpress Version: 4.9.5 PHP Version: 7.1.7/7.1.4/7.2.0/7.0.3/5.6.20/5.5.38/5.4.45 Web Server: Nginx 1.10.1/Apache 2.4.10 Environment/Host: Flywheel local https://local.getflywheel.com/ PCRE Library Version: 8.38 2015-11-23 I have been trying to work with register_rest_route but running into regex issues. It seems that there is some f...
How to use current_user_can() in register_rest_route()?
I'm trying to assert current_user_can() in the permission_callback method of a register_rest_route function. However, it always returns false. Upon further debugging, I see that wp_get_current_user() function returns ID zero, which probably means the $current_user global isn't available at the moment of execution. That means this example from the d...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy .