• Resolved ipwob

    (@ipwob)


    Hi there

    Can someone explain me, why the following test code already generates an error (…previously declared…)?

    if ( ! function_exists( 'mod_footer_admin' ) ) {
      function mod_footer_admin() {
        echo 'My static footer text goes here';
      }
    }
    add_filter('admin_footer_text', 'mod_footer_admin');

    I am new to plugin development and in order to avoid issues with other plugins I created a simple test, which already throws that error at me that I tried to test/avoid:

      1. In my themes function.php I am calling that function to modify the footer
      2. In my plugin I created exactly that function again to see if the function from the plugin will be ignored (as expected as themes function.php seems to have the higher priority)

    Unfortunately I am receiving the error:
    Fatal error: Cannot redeclare remove_footer_admin() (previously declared in .../mypluginname_plugin.php:26) in /srv/www/.../functions.php on line 26

    I expected that if ( ! function_exists... will add a function unless its already defined and though if it is defined it won`t break the page = ignored?

Viewing 1 replies (of 1 total)
  • Thread Starter ipwob

    (@ipwob)

    grmpf… after switching on my brain again I realized its the function from within the functions.php throwing the error. As perfectly stated in the related error message.

Viewing 1 replies (of 1 total)
  • The topic ‘Plugin Error (already declared)’ is closed to new replies.