Skip to content

Instantly share code, notes, and snippets.

@derpixler
Last active May 16, 2016 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derpixler/ecf96b914c1191113984848babd1e9ac to your computer and use it in GitHub Desktop.
Save derpixler/ecf96b914c1191113984848babd1e9ac to your computer and use it in GitHub Desktop.
Flush WordPress Rewrite Rule if you have changes on a document
<?php
/**
* validate the last modification of this file
* on modification flush rewrite rules
*
* @return void
*/
function _flush_rules() {
$o = __CLASS__;
$v = filemtime( __FILE__ );
$d = array( 'version' => 0, 'time' => time() );
$r = wp_parse_args( get_option( $o, array() ), $d );
if ( $r[ 'version' ] != $v ) {
flush_rewrite_rules();
$a = array( 'version' => $v, 'time' => time() );
if ( ! update_option( $o, $a ) ) {
add_option( $o, $a );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment