Filters
Not only can you change the look by creating a custom template, but you can also change some of the simpler elements through filters. Each filter can be modified by placing the appropriate code in the functions.php
file in the theme folder, examples of which are shown below:
Show the number of files
In the default template, a number with the number of files in it appears after the folder name. This is set or modified by the download_from_files_counter
filter.
If you don’t want this number to appear, simply clear the filter:
remove_all_filters('download_from_files_counter');
If you want to change it, e.g. Here’s how:
remove_all_filters('download_from_files_counter'); function download_from_files_my_counter($number) { // $number (int) -> The number itself $html = ''; if (!empty($data)) { $html = ' <small>('.$number.')</small>'; } return $html; } add_filter( 'download_from_files_counter', 'download_from_files_my_counter', 10, 1 );
Show date
The extended template will also display the date the file was created. This is set or modified by the download_from_files_date
filter.
If you don’t want to see the date, simply clear the filter:
remove_all_filters('download_from_files_date');
If you want to change it, e.g. Here’s how:
remove_all_filters('download_from_files_date'); function download_from_files_my_date($datetime, $date_format, $time_format) { // $datetime (int) -> timestamp // $date_format (text) -> WordPress default date format // $time_format (text) -> WordPress default time format $date = date_i18n($date_format, strtotime($datetime)); $time = date_i18n($time_format, strtotime($datetime)); return $date . ' ' . $time.', '; } add_filter( 'download_from_files_date', 'download_from_files_my_date', 10, 3 );
Show uploader
The extended template will also display the name of the uploader of the file – if available. This is set or modified by the download_from_files_uploader
filter.
If you don’t want to display the uploader, simply clear the filter:
remove_all_filters('download_from_files_uploader');
If you want to change it, e.g. Here’s how:
remove_all_filters('download_from_files_uploader'); function download_from_files_my_uploader($uploader) { // $uploader (text) -> The name of the uploader $html = ''; if (!empty($uploader)) { $html = $uploader . ', '; } return $html; } add_filter( 'download_from_files_uploader', 'download_from_files_my_uploader', 10, 1 );
Change icons
Each of the templates uses an icon for the file types. These are loaded by default from the plugin’s directory, the assets/images/
folder. You can only delete it completely by creating a custom template, but if you change where the icons load, you can do so through the download_from_files_icon
filter:
remove_all_filters('download_from_files_icon'); function download_from_files_my_icon($icon) { // $icon (text) -> Icon corresponding to the type, eg. doc.png $src = ''; if (!empty($icon)) { $src = esc_url( home_url('/') ) . 'wp-content/themes/my_theme/icons/' . $icon; } return $src; } add_filter( 'download_from_files_icon', 'download_from_files_my_icon', 10, 1 );