How to fix PHP8 fatal error for WordPress Plugins or Functions.php

2 minute read, 1 if you're quick

If you are like me and after upgrading your PHP to version 8 you started receiving the following error, then you are in the right place to fix it.
You might as well have received a code 500 in your browser from this error also.

PHP message: PHP Fatal error:  Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, non-static method class::function() cannot be called statically

This error signifies that there is most likely a hook in a plugin, theme or even your functions.php that looks like this:

add_action( 'hook', 'class::function_name' );
add_filter( 'hook', 'class::function_name' );

There may be some additional parameters to the command but this is the main part.
The add_action or add_filter command will probably have a function that looks a little like this:

public function function_name() {

From PHP version 8 onwards you must ensure that the function is a static one to match the add_Action or add_filter.
There are two ways you can fix this error:

Fix Static function error by changing the action/filter

If you change the command to the following it should fix the problem, however, you need to be using OOP programming.

add_filter( 'hook', [$this, 'function'] );

Fix Static function error by changing the function

The second option is changing the function into a static function, like this:

public static function function_name() {

Either way should fix the problem, happy coding!