How to find out if an wp-admin action edited a file?

I want to create a small plugin to automatically purge the APC opcode cache after specific actions in the WordPress admin interface. This is necessary if e.g. apc.stat is set to 0, as a change to a file then doesn’t reset its cache value in the opcode cache and so calls will use the old, cached, out-of-date file. Total debug nightmare if you forget to clear the cache manually.

Is there an easy way to find out if an action edited/changed a file?

I could manually check if is_admin and POST and file is e.g. theme-editor.php, but this seems like a not very nice hack that is bound to miss some things.

Solutions Collecting From Web of "How to find out if an wp-admin action edited a file?"

The system redirects after an update with updated=true. You could check for that GET parameter on the load-theme-editor.php hook, something like:

  function() {
    if (isset($_GET['updated']) && true == $_GET['updated']) {
      // clear the cache

I looked for more specific hooks and couldn’t find any, by the way.

You should set APC to not check file updates only on deployment environment. If you give access to change the code then it is not a deployment environment.

In general what you are trying to do violate a basic monitoring rule – a software/device should not monitor itself, as it might get into a condition in which the monitoring can not be done. In your case you will find it hard to fix your monitoring code if there is a bug in it.

A better solution is to have an external program which monitors file changes under the wordpress root directory and clears the cache when it is detected. It will be much smaller , more reliable and easier to maintain then what you are trying to do here. (since you have APC I assume you have your own VPS and can hook to the file change notification service which all OSs has now)