Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

register_uninstall_hook called twice on each page #56

tristanleboss opened this issue Jun 24, 2016 · 1 comment · Fixed by #57


Copy link

commented Jun 24, 2016


The wordpress function register_uninstall_hook is called twice on each page. Indeed, it is executed in:

  • add_hook function from class CPTP_Module_Option from file ./CPTP/Module/Option.php
  • add_hook function from class CPTP_Module_FlushRules from file ./CPTP/Module/FlushRules.php

This function should only be called once from the function you define as an activation hook using register_activation_hook. Have a look at the note at the bottom of this page:

Indeed, this WordPress function stores your uninstall function in an uninstall_plugins option stored in wp_options table. So no need to call it on each page. Calling it at plugin activation is enough.

Indeed, it actually executes 2 UPDATE queries on each page of my site. It's a problem if you use a caching plugin (like W3 Total Cache) because when an UPDATE query is done on a table, the caching plugin needs to discard the cached queries who use this table. So, on each page, my cache clears the cache for the wp_options table killing any caching effect.




This comment has been minimized.

Copy link
Contributor Author

commented Jun 25, 2016

Actually, I also discovered that calling this function twice doesn't do what I think you expect: uninstall hooks are not combined. Indeed, the last one replace the previous one.

Here are the 2 queries executed by the register_uninstall_hook function (which internally uses update_option). We can clearly see that it replaces the previously defined uninstall hook.

UPDATE wp_options
SET option_value = 'a:1:{s:59:"custom-post-type-permalinks/custom-post-type-permalinks.php";a:2:{i:0;s:18:"CPTP_Module_Option";i:1;s:14:"uninstall_hook";}}' WHERE option_name = 'uninstall_plugins'

UPDATE wp_options
SET option_value = 'a:1:{s:59:"custom-post-type-permalinks/custom-post-type-permalinks.php";a:2:{i:0;s:22:"CPTP_Module_FlushRules";i:1;s:14:"uninstall_hook";}}' WHERE option_name = 'uninstall_plugins'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.