PHP WordPress - Flush Rewrite Rules on File Change or Every X Hours

</php // do not use on live/production servers add_action( 'init','maybe_rewrite_rules' ); function maybe_rewrite_rules() { $ver = filemtime( __FILE__ ); // Get the file time for this file as the version number $defaults = array( 'version' => 0, 'time' => time() ); $r = wp_parse_args( get_option( __CLASS__ . '_flush', array() ), $defaults ); // Flush if ver changes or if 48hrs has passed. if ( $r['version'] != $ver || $r['time'] + 172800 < time() ) { flush_rewrite_rules(); $args = array( 'version' => $ver, 'time' => time() ); if ( ! update_option( __CLASS__ . '_flush', $args ) ) { add_option( __CLASS__ . '_flush', $args ); } } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.