save_mod_rewrite_rules

Updates the htaccess file with the current rules if it is writable.

Description

save_mod_rewrite_rules(); 

Always writes to the file if it exists and is writable to ensure that we blank out old rules.


Usage

  1. if ( !function_exists( 'save_mod_rewrite_rules' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/misc.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = save_mod_rewrite_rules(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/misc.php  
  1. function save_mod_rewrite_rules() { 
  2. if ( is_multisite() ) 
  3. return; 
  4.  
  5. global $wp_rewrite; 
  6.  
  7. $home_path = get_home_path(); 
  8. $htaccess_file = $home_path.'.htaccess'; 
  9.  
  10. /** 
  11. * If the file doesn't already exist check for write access to the directory 
  12. * and whether we have some rules. Else check for write access to the file. 
  13. */ 
  14. if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) { 
  15. if ( got_mod_rewrite() ) { 
  16. $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() ); 
  17. return insert_with_markers( $htaccess_file, 'WordPress', $rules ); 
  18.  
  19. return false;