WP Support Help

Rewrites

A rewrite manager that allows for checking if rewrite rules valid for a particular instance, or if they need to be flushed and rewritten.

$rewrites = new Rewrites( $rules ); if (!$rewrites->has_latest()) { $rewrites->flush(); }

or more simply:

$rewrites = new Rewrites( $rules ); $rewrites->sync():

Flushing the rewrite rules

$rewrites->flush();

Checking if the current instance has the latest rules

$rewrites->has_latest();

Checking if a specific rewrite exists

$rewrites->exists( '^wp/plugin/?$' );

Checking if a specific rule and query exists

$rewrites->exists( '^wp/plugin/?$', 'index.php?wp-plugin=/' );

Adding a rewrite rule

$rewrites->add( '^wp/plugin/?$', 'index.php?wp-plugin=/' );

Apply all loaded rules

$rewrites = new Rewrites( $rules ); $rewrites->apply();

Sync the rules

if the instances rewrite rules aren't current, refresh them.

$rewrites->sync();

Flush and reapply the rules

$rewrites->flush();
Last modified: 09 September 2024