WP_Rewrite::flush_rules()
Removes rewrite rules and then recreate rewrite rules.
Calls WP_Rewrite::wp_rewrite_rules() after removing the rewrite_rules If the function named 'save_mod_rewrite_rules' exists, it will be called.
Method of the class: WP_Rewrite{}
Method of the class: WP_Rewrite{}
Used By: flush_rewrite_rules()
Hooks from the method
Return
null
. Nothing.
Usage
global $wp_rewrite; $wp_rewrite->flush_rules( $hard );
- $hard(true|false)
- Whether to update .htaccess (hard flush) or just update rewrite_rules option (soft flush).
Default: true (hard)
Examples
#1 Example of updating rewrite rules of URLs:
// make sure the $wp_rewrite variable is defined globally global $wp_rewrite; $wp_rewrite->flush_rules();
Or you could do it this way:
$GLOBALS['wp_rewrite']->flush_rules();
#2 Example of updating rewrite rules using the function flush_rewrite_rules()
, while the plugin is activated:
register_activation_hook( __FILE__, 'author_base_rewrite' ); function author_base_rewrite(){ flush_rewrite_rules( false ); }
flush_rewrite_rules( false ) - false indicates that the file .htaccess
should not be updated, if false is not specified, the file .htaccess
will be updated according to the rules.
Changelog
Since 2.0.1 | Introduced. |