iis7_delete_rewrite_rule

Delete WordPress rewrite rule from web.config file if it exists there.

Description

iis7_delete_rewrite_rule( (string) $filename ); 

Parameters (1)

0. $filename (string)
Name of the configuration file

Usage

  1. if ( !function_exists( 'iis7_delete_rewrite_rule' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/misc.php'; 
  3.  
  4. // Name of the configuration file 
  5. $filename = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = iis7_delete_rewrite_rule($filename); 
  9.  

Defined (1)

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

/wp-admin/includes/misc.php  
  1. function iis7_delete_rewrite_rule($filename) { 
  2. // If configuration file does not exist then rules also do not exist so there is nothing to delete 
  3. if ( ! file_exists($filename) ) 
  4. return true; 
  5.  
  6. if ( ! class_exists( 'DOMDocument', false ) ) { 
  7. return false; 
  8.  
  9. $doc = new DOMDocument(); 
  10. $doc->preserveWhiteSpace = false; 
  11.  
  12. if ( $doc -> load($filename) === false ) 
  13. return false; 
  14. $xpath = new DOMXPath($doc); 
  15. $rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[starts-with(@name, \'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name, \'WordPress\')]'); 
  16. if ( $rules->length > 0 ) { 
  17. $child = $rules->item(0); 
  18. $parent = $child->parentNode; 
  19. $parent->removeChild($child); 
  20. $doc->formatOutput = true; 
  21. saveDomDocument($doc, $filename); 
  22. return true;