4 | | function maybe_flush_rules() { |

5 | | global $wp_rewrite; |

6 | | $rewrite_rules = get_option( 'rewrite_rules' ); |

7 | | foreach( $rewrite_rules as $rule => $rewrite ) { |

8 | | $rewrite_rules_array[$rule]['rewrite'] = $rewrite; |

9 | | } |

10 | | $maybe_missing = $wp_rewrite->rewrite_rules(); |

11 | | $missing_rules = false; |

12 | | $rewrite_rules_array = array_reverse( $rewrite_rules_array, true ); |

13 | | foreach( $maybe_missing as $rule => $rewrite ) { |

14 | | if ( ! array_key_exists( $rule, $rewrite_rules_array ) ) { |

15 | | $missing_rules = true; |

16 | | break; |

17 | | } |

18 | | } |

19 | | if ( true === $missing_rules ) { |

20 | | flush_rewrite_rules(); |

| 4 | #!php |

| 5 | <?php |

| 6 | function maybe_flush_rules() { |

| 7 | global $wp_rewrite; |

| 8 | $rewrite_rules = get_option( 'rewrite_rules' ); |

| 9 | |

| 10 | foreach( $rewrite_rules as $rule => $rewrite ) { |

| 11 | $rewrite_rules_array[$rule]['rewrite'] = $rewrite; |

| 12 | } |

| 13 | |

| 14 | $maybe_missing = $wp_rewrite->rewrite_rules(); |

| 15 | $missing_rules = false; |

| 16 | $rewrite_rules_array = array_reverse( $rewrite_rules_array, true ); |

| 17 | |

| 18 | foreach( $maybe_missing as $rule => $rewrite ) { |

| 19 | if ( ! array_key_exists( $rule, $rewrite_rules_array ) ) { |

| 20 | $missing_rules = true; |

| 21 | break; |