WordPress.org

Make WordPress Core

Ticket #4018: 4018.diff

File 4018.diff, 1.5 KB (added by westi, 8 years ago)

New version of save_mod_rewrite_rules

  • wp-admin/includes/misc.php

     
    8989        } 
    9090} 
    9191 
     92/** 
     93 * Updates the htaccess file with the current rules if it is writable. 
     94 * 
     95 * Always writes to the file if it exists and is writable to ensure that we blank out old rules. 
     96 */ 
     97 
    9298function save_mod_rewrite_rules() { 
    93         global $is_apache, $wp_rewrite; 
     99        global $wp_rewrite; 
     100         
    94101        $home_path = get_home_path(); 
     102        $htaccess_file = $home_path.'.htaccess'; 
    95103 
    96         if (!$wp_rewrite->using_mod_rewrite_permalinks() ) 
    97                 return false; 
    98  
    99         if (!((!file_exists( $home_path.'.htaccess' ) && is_writable( $home_path ) ) || is_writable( $home_path.'.htaccess' ) ) ) 
    100                 return false; 
    101  
    102         if (! got_mod_rewrite() ) 
    103                 return false; 
    104  
    105         $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() ); 
    106         return insert_with_markers( $home_path.'.htaccess', 'WordPress', $rules ); 
     104        // If the file doesn't already exists check for write access to the directory and whether of not we have some rules. 
     105        // else check for write access to the file. 
     106        if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) { 
     107                if ( got_mod_rewrite() ) { 
     108                        $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() ); 
     109                        return insert_with_markers( $htaccess_file, 'WordPress', $rules ); 
     110                } 
     111        } 
     112         
     113        return false; 
    107114} 
    108115 
    109116function update_recently_edited( $file ) {