[wp-trac] [WordPress Trac] #44171: Flushing the rewrite rules is "wrong" on the front-end
WordPress Trac
noreply at wordpress.org
Mon May 21 13:41:49 UTC 2018
#44171: Flushing the rewrite rules is "wrong" on the front-end
-------------------------+---------------------
Reporter: azaozz | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 5.0
Component: General | Version:
Severity: normal | Resolution:
Keywords: dev-note | Focuses:
-------------------------+---------------------
Comment (by kraftbj):
Sample first run:
**Rewrite rules should only be flushed within wp-admin**
In 5.0 via #44171, rewrite rules can only be flushed within an
administrative context (wp-admin).
Processing rewrite rules, generally, is an expensive operation, which is
why WordPress stores a compiled set of rewrite rules in the database. When
plugins or themes flush the rewrite rules on the front-end, this requires
the site to perform the work of compiling the rewrite rules, performing
two writes to the database, and, by default, updating the .htaccess or
web.config to continue loading the site.
At best, this increases the site load time for visitors, but at worst, can
overload the database and bring the site down depending on the number of
concurrent visitors.
Starting in 5.0, a `_doing_it_wrong` notice will occur and the
`flush_rewrite_rules()` will return early without action if `is_admin` is
false. Ideally, flushing the rewrite rules should only occur when there
has been a preceding action impacting rewrite rules, such as plugin or
theme activation/deactivation. If actively developing a site, plugin, or
theme, `add_action( 'admin_init', 'flush_rewrite_rules' );` is acceptable.
This is often best done via a dedicated development plugin to avoid
accidentally shipping it in production code.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44171#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list