[wp-trac] [WordPress Trac] #42563: Flushing rewrite rules on plugin deactivation does nothing
WordPress Trac
noreply at wordpress.org
Wed Nov 15 22:46:50 UTC 2017
#42563: Flushing rewrite rules on plugin deactivation does nothing
---------------------------+------------------------------
Reporter: brainfork | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Rewrite Rules | Version: 4.8.3
Severity: normal | Resolution:
Keywords: | Focuses:
---------------------------+------------------------------
Comment (by mdgl):
I suspect you are seeing this behaviour because you also have an action
attached to 'init' that creates taxonomies or post types that result in
new rewrite rules.
The problem is that the 'init' action is run before the deactivation hook
when deactivating the (active) plugin, so your rewrite rules are still
updated before being flushed.
I find you need to add something like the following check in your 'init'
action before creating new taxonomies or post types:
{{{
function xxx_plugin_initialise() {
if ( is_admin() && strpos($_SERVER['REQUEST_URI'],
parse_url(admin_url('plugins.php'), PHP_URL_PATH) .
'?action=deactivate&plugin=' . urlencode(plugin_basename(__FILE__))) === 0
)
return;
xxx_plugin_setup_taxonomies();
xxx_plugin_setup_post_types();
}
add_action( 'init', 'xxx_plugin_initialise' );
function xxx_plugin_activate() {
xxx_plugin_initialise();
flush_rewrite_rules();
}
function xxx_plugin_deactivate() {
flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'xxx_plugin_activate' );
register_deactivation_hook( __FILE__, 'xxx_plugin_deactivate' );
}}}
It would be good is the codex and other advice searchable on the Internet
was updated with a description of this issue.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42563#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list