You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Regards,
Tristan
The text was updated successfully, but these errors were encountered:
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'
Hello,
The wordpress function
register_uninstall_hook
is called twice on each page. Indeed, it is executed in:add_hook
function from classCPTP_Module_Option
from file./CPTP/Module/Option.php
add_hook
function from classCPTP_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: https://developer.wordpress.org/reference/functions/register_uninstall_hook/Indeed, this WordPress function stores your uninstall function in an
uninstall_plugins
option stored inwp_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.
Regards,
Tristan
The text was updated successfully, but these errors were encountered: