The cause of your error is that the filter receives and is expected to return a WP_Error
object, null
is not an error object.
We can confirm this via the docs, and enforce it via type hinting:
function my_logout_message( \WP_Error $error ) : \WP_Error {
Additionally, if your code had worked, all errors would be eliminated, not just the logout message. There would be no way to tell a user their password was incorrect, that a password reset email or a confirmation email was on its way, etc
With this in mind, the WP_Error
say there is a remove
method, so we can remove the loggedout error if it’s present:
$error->remove( 'loggedout' );
I do not recommend this though