• oce

    (@josepo)


    I’m writing a plugin and running into some issues.

    I have an activation function, which sets up a table I’m using; I also have an admin page, under the management category. After activating, which works fine, when I go to the admin page I get:

    Fatal error: Cannot redeclare dumb_setup() (previously declared in /path/.../wp-content/plugins/dumb_plugin_test.php:10) in /path/.../wp-content/plugins/dumb_plugin_test.php on line 8

    Minimal code that repeats this error is at https://pastie.caboo.se/123913

    Thanks….

Viewing 5 replies - 1 through 5 (of 5 total)
  • Adam Brown

    (@adamrbrown)

    Hmm. That’s weird. I don’t know what exactly in your code would cause that. But a side point. Shouldn’t this:

    register_activation_hook(basename(__FILE__), 'dumb_setup()');

    say this:

    register_activation_hook(basename(__FILE__), 'dumb_setup');

    ?

    fitztrev

    (@fitztrev)

    josepo: That is indeed weird. I’m not sure of the reason myself. I rewrote it quickly with a simple class structure and it seems to be working just fine now. https://pastebin.ca/803336

    P.S. adamrbrown is correct. No parentheses needed to specify the dumb_setup function.

    Adam Brown

    (@adamrbrown)

    I haven’t tested, but I think this is your problem now that I think about it again:

    add_management_page("dumb", "dumb", 0, __FILE__);

    It’s trying to include your code a second time when you go to your admin page. Change __FILE__ to something else (so your plugin has 2 files) and see what happens.

    Thread Starter oce

    (@josepo)

    Thanks, that works, though I don’t really get the file-inclusion thing, as it gets parsed but stuff defined in there doesn’t seem to fall under the scope of other things…whatever.

    Nevermind.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘plugin development — cannot redeclare function’ is closed to new replies.