iis7_rewrite_rule_exists

Check if rewrite rule for WordPress already exists in the IIS 7+ configuration file.

Description

iis7_rewrite_rule_exists( (string) $filename ); 

Parameters (1)

0. $filename (string)
The file path to the configuration file

Usage

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

Defined (1)

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

/wp-admin/includes/misc.php  
  1. function iis7_rewrite_rule_exists($filename) { 
  2. if ( ! file_exists($filename) ) 
  3. return false; 
  4. if ( ! class_exists( 'DOMDocument', false ) ) { 
  5. return false; 
  6.  
  7. $doc = new DOMDocument(); 
  8. if ( $doc->load($filename) === false ) 
  9. return false; 
  10. $xpath = new DOMXPath($doc); 
  11. $rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[starts-with(@name, \'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name, \'WordPress\')]'); 
  12. if ( $rules->length == 0 ) 
  13. return false; 
  14. else 
  15. return true;