Custom Hooks

Simple File List includes numerous hooks you can use in order to extend its functionality and integration with your theme or other plugins. In addition knowing when an action occurred, SFL custom hooks also return an array containing messages related to the action process.

File Uploads Hooks

These hooks will fire after a successful file upload job. There is one for the front-end and one for the back-end.

eeSFL_Hook_Uploaded
eeSFL_Admin_Hook_Uploaded

How to Use the Hooks

To make your theme do something special when SFL fires hooks, add something like this to your child theme’s functions.php file.

// add_action('The Hook Name', 'Your Function Name', Priority, Number of Arguments)
add_action('eeSFL_Hook_Uploaded', 'eeHookTestOutput', 10, 1);

Then write a function to do whatever you want when the action occurs and the hook is fired.

// When the hook is fired, add_action() calls this function
// Writes output to /wp-content/debug.log
function eeHookTestOutput($eeMessages) {
     
     error_log('Hook Fired'); 

     foreach($eeMessages as $eeMessage) {
          
           error_log($eeMessage);
     }
}

More Hooks

SFL is List is Loaded

This hook will fire each time the file list is loaded. The messages array will contain the URL of the list page and how many items were shown.

eeSFL_Hook_Loaded

SFL is Item is Listed

This hook will fire each time a file or folder(Pro) is listed. The messages array will contain the file array, which contains all of the details for the item.

eeSFL_Hook_Listed

New Item Added

This hook will fire each time a new item (one that was added from outside the plugin) is found during the re-scan process.

eeSFL_Hook_Added

Item Not Found

This hook will fire each time an item is no longer found in the list, and was removed from outside of the plugin.

eeSFL_Hook_Removed

Item was Edited

This hook will fire each time an item has been edited. The message array will give info about what happened.

eeSFL_Hook_Edited

Item was Deleted

This hook will fire each time an item has been deleted. The message array will give the name of the file deleted.

eeSFL_Hook_Deleted

Item was Moved

This hook will fire each time an item has been moved. The message array will give the before and after path.

eeSFL_Hook_Moved

List was Scanned

This hook will fire each time the disk was re-scanned. The message array will give info about what happened.

eeSFL_Hook_Scanned

Hooks are cool! If you need one for something in your project, please let me know!

3 thoughts on “Custom Hooks”

  1. I would like to track usage of the files that we’re sharing on our site. Any chance you could add a few more hooks, namely file opened, file downloaded, link copied. For each of these, the path to the file would be beneficial, similar to how it’s provided with the eeSFL_Hook_Moved hook. Also, can the full path to the deleted file be provided as an element in the messages array in the hook eeSFL_Hook_Deleted? It looks like it’s not including subfolders.

    Reply
    • This would only be possible for restricted lists using the File Access Manager extension. Normally these actions are simply direct links to the files, so there is nothing to fire the hook. Restricted lists go through a file firewall where hooks may be useful. I will put that on my to-do list.

      Reply
      • Good point. I ended up trapping the clicks and passing them via REST to log into a database. Unfortunately, the restricted list route wouldn’t help me as in this case we’re making the documents publicly available.

        Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.