wfu_logo_hooks

WordPress File Upload plugin supports a number of filters and actions to better tailor it to your needs. The full list of filters and actions supported can be found in this article.

Since version 3.6.0 administrators can define custom code to implement these filters right from the plugin’s area in Dashboard, without the need to add 3rd party plugins, as happened before.

Suppose that we want to implement custom javascript actions to run right after a file has been uploaded. We need to implement wfu_after_file_upload filter.

To do that we first need to go to the plugin’s area in Dashboard, in Hooks tab and create a new hook like this:

screenshot45

A new screen appears requesting to add a title for the hook, a description, the code, status (activated or not) and where it is supposed to run (in the dashboard or in the front-end). We add some custom title and description.

The plugin provides code templates, shown right above the code box, in order to assist the user implement the filters easily and quickly. We select the option “After File Upload Filter” and we press “Add Code“. The code box is filled with php code of the filter function and comments with instructions that describe how to use the filter, as shown below:

screenshot46

 

We edit the code so that a success message popups to the user if the file was uploaded successfully. The code finally looks like this:

screenshot47

We set its Status to Active and we Save it.

If everything is Ok, then we will see the new hook in the Hook List in Dashboard as follows, otherwise a message will appear on top with error information and the plugin will not be activated:

screenshot48

We can also activate, deactivate, delete the hook or perform bulk actions on many hooks from this screen.

Now that the filter is set up correctly we attempt to upload a file from a page. When the file is successfully uploaded, the following message is shown on screen:

screenshot49

For more information or questions about the Hooks feature, you can contact us.

The Iptanus Team

How to Create Custom Filters and Actions for WordPress File Upload Plugin

7 thoughts on “How to Create Custom Filters and Actions for WordPress File Upload Plugin

  • Hello,
    [Sorry for my english, I’m French]
    I’d like add one custom field with a default value but not display it in the upload page.
    I could use Css to hide these field, but I’d prefer do it without indication of these field in the code page.
    Is it possible with the hook system to add code in order to add one “userdata_field” before call the function “wfu_log_action” and like that have one record in the wfu_userdata table with the custom field I’d like to record ?
    I hope I’m clear.
    Thanks

  • Hello, I am trying to add a hook to wfu_after_file_upload and I have 2 questions:

    1) I need go into WP database and add some info to a table in WP database, so I need to execute an action on server side. Is it possible to create a hook similar to “wfu_after_file_upload” but on server side in functions.php?

    2) Is there shortcode or a variable I can access from server side in PHP to fetch the name of the file the user just uploaded? I looked in the WP database but could not find any uploaded files in wp_posts or any other tables that would give me that information.

    I am a mediocre programmer who greatly appreciate any suggestions. Thanks!

  • To clarify, I am rewording my first question to what should be the parameter xxxxx in “add_action(xxxxx, my-custom-function)” if I want to hook on the after file upload event in my in functions.php file, and how can I fetch the filename in my-custom-function?

    1. It should be “wfu_after_upload”. This is the filter you should use. You can find instructions how to use this filter here.

      Please note that it is not a good practice to add actions inside functions.php, unless it belongs to a child theme of your own. If you use a normal theme and you update it then everything you have inside functions.php will be lost.

      The plugin’s Pro version has a special page in Dashboard to add hooks, which remain even if you update it. You can also use other free plugins, like Code Snippets.

      Regards

      Nickolas

Leave a Reply

Your email address will not be published.

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