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.