DevinVinson / WordPress-Plugin-Boilerplate

[WordPress] A foundation for WordPress Plugin Development that aims to provide a clear and consistent guide for building your plugins.
http://wppb.io
7.67k stars 2.25k forks source link

register_uninstall_hook was called incorrectly #22

Closed montrealist closed 11 years ago

montrealist commented 11 years ago

Just decided to give it a try for a new plugin I'm working on. I get the following notice twice:

PHP Notice: register_uninstall_hook was called incorrectly. Only a static class method or function can be used in an uninstall hook.

It occurs on these two lines:

register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
register_uninstall_hook( __FILE__, array( $this, 'uninstall' ) );

I have an existing WordPress 3.5.1 with a custom theme and a bunch of plugins. Could it be on my side?

montrealist commented 11 years ago

Found this tentative solution. Would it modify anything in the way the plugin is functioning? Alas, I'm not a PHP wizard.

tommcfarlin commented 11 years ago

Thanks for the heads up on this - I'll make a note and have it patched in a future version. Nice catch!

Japh commented 11 years ago

I'm wrestling with this too, though I don't believe the fix suggested on that SO answer is legit. They've stopped the error appearing by calling a global function that doesn't exist.

I tried this, register_uninstall_hook( __FILE__, 'cowabunga');, and it also appears to "fix" the problem (i.e. the error disappears).

Need a better solution...

Japh commented 11 years ago

Note, the Codex page recommends the uninstall.php approach: http://codex.wordpress.org/Function_Reference/register_uninstall_hook

montrealist commented 11 years ago

Sweet, thank you for looking into it! Haven't tried it yet, but sure looks like a legit solution for this one.

Guess another possible option would be to move the uninstall function outside of the class.

tommcfarlin commented 11 years ago

Nice work - definitely a fan of the uninstall.php approach. Will be planning to merge this and have it tagged for the next release of the Boilerplate.

Thanks guys.