Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm writing a plugin, most of my code is wrapped in classes, except for an admin_notice fallback function that I call when I am not loading the main plugin class:

class MyClass {
    //Main plugin class
}

if ( $check = true ) {
    $myClass = new MyClass();
} else {
    add_action( 'admin_notices', 'admin_notice' );
} 

function admin_notice() {
    echo "plugin not loaded";
}

this worked before like it should, until suddenly I got an error when I deactivated and reactivated te plugin:

Plugin could not be activated because it triggered a fatal error.

Fatal error: Cannot redeclare admin_notice() (previously declared in myplugin.php:12) in myplugin.php on line 14

The line numbers (12&14) refer to the first and last lines of the function, the file is the same.

the strange thing is that when I wrap the function in a function exists conditional like this:

if ( ! function_exists('admin_notice') ) {
    function admin_notice() {
        echo "plugin not loaded";
    }
}

I get an error that the function doesn't exist!

I have tried deleting & reinstalling the plugin files, renaming the function, but that doesn't help... Any ideas what's going on?

share|improve this question

closed as too localized by s_ha_dum, brasofilo, toscho Apr 5 '13 at 22:50

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

Ok, solved my own issue... This might be very specific, but in case anyone ever finds a similar issue:

to catch unexpected output errors I had another function:

add_action('activated_plugin','save_error');
function save_error(){
    $file = "unexpected-output.txt";
    $fh = fopen($file, 'w') or die("can't open file");
    $error = ob_get_contents();
    fclose($fh);
}

there was a typo in the fopen(), which apparently messed up things badly (still not sure why it was trying to load everything more than once - I think it has to do with the fact that the function died).

share|improve this answer
    
+1 for answering your own question –  vancoder Apr 5 '13 at 16:29
    
+1 Same here, answering your own question is nearly always worth a vote. –  s_ha_dum Apr 5 '13 at 20:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.