Skip to content

Instantly share code, notes, and snippets.

@mikeschinkel
Created January 18, 2012 00:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeschinkel/1629997 to your computer and use it in GitHub Desktop.
Save mikeschinkel/1629997 to your computer and use it in GitHub Desktop.
File Changed function from Sunrise.
<?php
/**
* Used where you might want to use an activation function but where it's not convenient or possible (like in a theme.)
* Accepts __FILE__ for the a unique key to identify the file.
*
* @param string $file
* @return bool
*
* Author: Mike Schinkel
* Author URI: http://about.me/mikeschinkel/
*
*/
function sr_file_changed( $file ) {
$file_changed = false;
$files_changed = get_option( '_sr_files_last_changed' );
if ( ! is_array( $files_changed ) )
$files_changed = array();
if ( isset($files_changed[$file]) ) {
$this_time = filemtime( $file );
$file_changed = ($this_time > $files_changed[$file]);
$last_changed = $this_time;
} else {
$last_changed = filemtime( $file );
$file_changed = true;
}
if ( $file_changed ) {
$files_changed[$file] = $last_changed;
update_option( '_sr_files_last_changed', $files_changed );
}
return $file_changed;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment