Notice: register_rest_route was called incorrectly - wordpress

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.

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.

Related

Getting "An active PHP session was detected" critical warning in wordpress

A PHP session was created by a session_start() function call. This interferes with REST API and loopback requests. The session should be closed by session_write_close() before making any HTTP requests.
In most cases, the real reason of the above errors is the incorrect mechanism for using PHP sessions within plugins or themes when they are using the session_start() function.
Now you need to identify what plugin cause this issue by deactive your plugin one by one.
Then in that plugin, you need to find a piece of code similar to this:
if ( !session_id() ) {
session_start();
}
then change it to:
if ( !session_id() ) {
session_start( [
'read_and_close' => true,
] );
}
Then you are done. In most cases, this will fix the issue. Good luck!
Had the same issue due to WP Hotel Booking plugin use. I fixed it! Took me a while to find a plugin it caused and editing the plugin .php didn’t help. But I fixed it adding a snippet of code to functions.php of the CHILD theme:
function mymodule_curl_before_request($curlhandle){
session_write_close();
}
add_action( ‘requests-curl.before_request’,’mymodule_curl_before_request’, 9999 );
There's a background to this solution at: Make WordPress Core, Loopback request fails if headers set in curl
(Original link in German doesn't exist anymore and was referring to this other related discussion.)
Often this critical issue is caused by conflict in SESSION when using the PHP session_start() function.
For example I have used a Calculation plugin in Wordpress and after Wordpress version update this error occured.
So I detected the plugin which causes this issue as activated/deactivated plugins one by one.
SOLVING these errors: In File manager of my site I got the .php files of the plugin and searched for session_start() function. Where it was used after it I used this function in a row session_write_close();
Source of the function
Regards!
To chime in with my own experience here, this very issue was resolved by turning off the “cross sell pop up” module of Shopengine Pro. Indeed there’s a session start in the php. I have notified them about this today. Maybe it’ll help someone else meantime!
I found out that you get these critical health warnings when you install a plugin or a plugin Adon and fail to complete its setup to the end. So the simplest solution is to deactivate the plugin or complete the plugin set-up. My errors were caused by a Woocommerce Adon which I deactivated and when I refreshed the health status the two issues were gone. I hope this helps.
#David M., If the issue is specifically happening with the Cross-Sell Popup Module of the ShopEngine PRO plugin, then it can be fixed by adding a small piece of code on the cross-sell-popup.php file that will read and close the session of the Cross Sale Popup module immediately.
Big Thanks to #thống nguyễn for the solution.
On the line 18th, from where the session starts, replace the session_start() with the following code:
session_start([
'read_and_close' => true
]);
Hope it will help.
If you tried the above and it's not working try to change the php version from your hosting's CPanel
I had the same error ande i changed the php version from 7.4 to 7.3 and it all went well

Wordpress plugin is not working after migration to a new server

I have moved my wordpress site to a new server, and login.php is working right.
But in there many plugins is not working well, for example the login page is not linked to any other page after I submitted my username and password.
Here is the login page link:
https://cpalocate.ca/login/
I have entered the invalid username and password, it will also show the blank page, but not error page.
When I add this code in wp-config.php
define('WP_DEBUG', true);
it showed this text. " Notice: Constant WYZ_THEME_DIR already defined in /home/.....".
And I have fixed that, but the same problem.
Now there is no any error debug, but the login page is also not working.
I changed the php version of my site in cpanel, but the same.
Anyone has your idea to solve this issue?
It is possible (I'd even say likely) that on your old server it was using PHP 5.6 (or at least a different version of PHP than your new server) and now you're on 7.0, 7.2 or even 7.3. It would seem that if that's the case, some of your plugins are incompatible.
You should edit your wp-config.php and add
define('WP_DEBUG', true);
so that you can see the errors on your screen, at least until you figure out which plugins are causing the problems.
If it is a matter of PHP version, check with your host to see if they can roll you back, or you'll have to either contact the plugin author and have them update the plugins, or you need to fix the code yourself, based on whatever the error messages you see are.
Edit: if this doesn't solve your problem, first try a default WordPress theme like twenty-nineteen or whatever. If that doesn't solve it, then disable each plugin one at a time until you find the culprit.
I have turned off all my plugins and turn back it one by one.
I have found one of my plugins is caused this problem, it is PM Pro Settings.
So I deactivated it and there is no any problem now.
I am using other plugins on behalf of that one.

Algolia WordPress Plugin Wont Process Index Cueue

In reference to the following existing question. Wordpress Plugin : Can't process Indexing Queue I was unable to participate in the comments due to having a new account and less than 50 reputation.
I am having a problem getting the Algolia WordPress plugin to process the index. Running the latest version of WP and just downwloaded the WP Plugin from Algolia today. When I run WP_DEBUG and WP_DEBUG_LOG in my wp-config file I get the following output on any WP back end page.
has_cap was called with an argument that is deprecated since version 2.0.0! Usage of user levels by plugins and themes is deprecated. Use roles and capabilities instead. in /var/www/html/dealer/wp-includes/functions.php on line 3890
Line 3890 in wp-includes/functions.php just references the code that generated the error.
trigger_error( sprintf( __('%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s'), $function, $version, $message ) );
This appears to be an unrelated issue.
I should point out that this is a dev test server running locally on our internal network. I'm starting to wonder if that's causing the issue. I installed the same plugin on our live version of the site and everything works as expected.
We have never noticed any logs related to user capabilities. Your best bet to remove those notices is to:
Be sure all your plugins are updated,
Disable/Test/Enable plugins one by one to locate the plugin raising those.
Please ensure that all the requirements are met: https://community.algolia.com/wordpress/installation.html
Do you have any errors logged on the "Logs" page of the Algolia plugin?
Might be useful to also give us the list of plugins you are using.

Wordpress Plugin to identify what php code a page use

I'm looking a plugin that allow me to know/identify when I am in a page the php classes used in that page.
For example, a page can be part of a plugin or a part of a template,
so if I have to change it how can I know where I need to change the code among the many php classes?
Thanks so much
You can set on your wp-config.php file:
define( 'WP_DEBUG', true );
It will enable the “debug” mode throughout WordPress.
When set to "true", you’ll start seeing PHP notices, WordPress-generated debug messages, deprecated function usage, etc.
If this is not enough for you, you can try this plugin:
https://wordpress.org/plugins/debug-my-plugin/

Wordpress Theme Compatibility Issue

I'm developing a WP theme for a client and have run into some trouble.
When my theme is activated:
I edit post or page (or several other areas), click UPDATE, PUBLISH, etc - and I get a blank white page.
When I go back, the post has been updated - so the system is working, it just isn't redirecting me back to the edit page.
Everything works fine when the default template is activated.
Thanks!!!
To trace the error set the WP_DEBUG as true
Refer : http://www.wprecipes.com/how-to-easily-enabledisable-debug-mode-in-wordpress
Change WP_DEBUG to true in wp-config.php file located in the WordPress root folder, and then you will be able to see the errors that are coming up. Fixing those errors will resolve your problem.

Resources