Conflict with “wp” hook | WordPress.org

[ad_1]

What is the rest of the error message?

FYI: Site Reviews does not use the wp hook. Also, you should add a is_admin() check to your code if it is only meant to run on the frontend.

[16-Feb-2024 10:33:24 UTC] PHP Fatal error: Cannot redeclare redirect_author_page_to_home() (previously declared in /home/domain.pl/public_html/wp-content/plugins/wpcodebox2/src/Runner/QueryRunner.php(126) : eval()'d code:10) in /home/domain.pl/public_html/wp-content/plugins/wpcodebox2/src/Runner/QueryRunner.php(126) : eval()'d code on line 9

I spoke to the developer of WPCodeBox and he is unable to do anything about this fact. I can only anonymize the function or change the hooks.

Exaple:

add_action( 'template_redirect', 'my_redirect_author_page_to_home' );

function redirect_author_page_to_home() {

to:

add_action( 'template_redirect', function() {

And then it works properly.

  • This reply was modified 25 minutes ago by BDR Bros..

Firstly: I doubt this is being caused by Site Reviews. Does the error include a stack trace that shows files from Site Reviews are involved?

Secondly: add a function_exists check to your snippet:

if (!function_exists('redirect_author_page_to_home')) {
    function redirect_author_page_to_home() {
        // ...
    }
}
add_action('template_redirect', 'redirect_author_page_to_home');

Thirdly: redirect_author_page_to_home is a custom function but the error shows that it is being defined more than once. That means you are triggering the snippet that is creating the function more than once. Adding a function_exists check is more of a bandaid fix. For a proper solution, you need to figure out why your snippet is being triggered more than once. That might involve using a different hook, or adding an is_admin check before creating the function (if the snippet should only run on the admin side/frontend).

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer