[wp-trac] [WordPress Trac] #47526: Flagging system needed to help flush rewrite rules on post type registration from a plugin
WordPress Trac
noreply at wordpress.org
Tue Jun 11 16:31:51 UTC 2019
#47526: Flagging system needed to help flush rewrite rules on post type
registration from a plugin
-----------------------------+------------------------------------
Reporter: kevindees | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Permalinks | Version: 5.2.1
Severity: normal | Keywords: dev-feedback has-patch
Focuses: |
-----------------------------+------------------------------------
When activating or deactivating a plugin with post types or taxonomies the
timing of flushing rewrite rules is very cumbersome. There are also
inconsistencies on how flushing rewrite rules "should" be handled when
activating vs deactivating.
Further, some plugins remove the rewrite rules added for a post type by
other plugins.
I think it is worth considering the implementation of a unified API for
flushing rewrite rules to help plugin developers flush permalinks
registering with post types and taxonomies.
I believe a good starting point would be to add a flagging system to the
database. The flagging system would allow authors to check for the flag
and execute code when the flag is available. This seems to be a common
practice already.
Example implementation:
{{{#!php
<?php
// Plugin Name: My Plugin
add_action( 'init', function() {
register_post_type('book', ['public' => true]);
});
function my_plugin_activate() {
update_site_state_changed( 'flush_rewrite_rules' );
}
function my_plugin_deactivate() {
update_site_state_changed( 'flush_rewrite_rules' );
}
register_activation_hook(__FILE__, 'my_plugin_activate');
register_deactivation_hook(__FILE__, 'my_plugin_deactivate');
}}}
The applied patch is for proof of concept. Not intended to be final.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/47526>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list