User Private Files is a powerful plugin that allows you to furthre extend it with actions and filters hooks. Below are the available filters and actions hooks that you can use to modify or extend the plugin.
Filters
- upf_new_btn_after: This filter is placed after the buttons list in the “New” button dropdown. By default, you have Upload Files, New Folder, and Upload Folder options in the New button dropdown. If you are using the Text Editor addon, you will also see the New File option which is a good example of using this filter. The “New File” option is placed by the Text Editor addon by using this filter.
Example:
// Adding new External Link option under the New button
add_filter(‘upf_new_btn_after’, ‘upf_extend_new_button’, 11, 1);function upf_extend_new_button($val){
return $val . ‘<a href=”javascript:void(0);” class=”new-btn-dropdown-item” id=”upfp_new_link_btn”><i class=”fas fa-file-text” aria-hidden=”true”></i> External Link</a>’;
}
- upf_users_list: This filter is used to modify the list of users returned inside the share popup. It is helpful if you have a large number of users and you want to allow very few users to share the files with.
Example:
// Display only the contributor role users in share popups.
add_filter(‘upf_users_list’, ‘upf_extend_users_list’, 11, 1);function upf_extend_users_list($all_users){
$all_users = get_users(array(‘fields’ => array(‘user_login’, ‘user_email’), ‘role__in’ => array( ‘contributor’ )));
return $all_users;
}
- upfp_register_html: It is used to modify the content of the registration page for logged-in users.
Example:
// Add custom message on registration page if user is logged-in
add_filter(‘upfp_register_html’, ‘upf_extend_register_html’, 11, 1);function upf_extend_register_html($msg){
return ‘<h3>You are already logged in.</h3>’ . $msg;
}
- upfp_login_html: Similar to the previous filter, this filter is used to modify the content of the plugin’s login shortcode page for logged-in users.
Example:
// Add custom message on login page if user is logged-in
add_filter(‘upfp_login_html’, ‘upf_extend_login_html’, 11, 1);function upf_extend_login_html($msg){
return ‘<h3>You are already logged in.</h3>’ . $msg;
}
- upfp_upload_allow_multiple: This filter makes it possible to disable the multiple file uploads. By default the uploader allows users to upload multiple files at a time but you can disable it with this filter.
Example:
// Disable multiple file uploads at once
add_filter(‘upfp_upload_allow_multiple’, ‘upf_extend_upload_multiple’, 11, 1);function upf_extend_upload_multiple($multiple){
return ”;
}
- upvf_my_files_hdng: This filter applies for the gallery shortcode. It allows you to modify the heading for My Files at the top.
Example:
// Change My Files heading for classic gallery
add_filter(‘upvf_my_files_hdng’, ‘upf_extend_classic_my_files_hdng’, 11, 1);function upf_extend_classic_my_files_hdng($my_files_hdng){
return ‘Your Files’;
}
- upfp_user_info_after: If you want to add custom content near the username in the right sidebar panel, you can make use of this filter. It will add your content next to the username.
Example:
// Add content near username in right sidebar panel
add_filter(‘upfp_user_info_after’, ‘upf_extend_user_info_after’);function upf_extend_user_info_after(){
return ‘Howdy!’;
}
- upf_right_sidebar_sections: This is used to insert content to the left sidebar.
Example:
// Append content to the left sidebar panel
add_filter(‘upf_right_sidebar_sections’, ‘upf_extend_right_sidebar_sections’, 11, 1);function upf_extend_right_sidebar_sections($content){
return $content . ‘<ul><li><a href=”#”>Need Help?</a></li></ul>’;
}
Action Hooks
- upf_file_inserted: Use this action hook to perform some actions after a file is uploaded via the plugin.
Example:
// Set custom meta to a file after the upload
add_action(‘upf_file_inserted’, ‘upf_extend_file_inserted’, 10, 3);function upf_extend_file_inserted($attach_id, $fldr_id = ”, $curr_user_id = ”){
// set custom meta data of the file
update_post_meta($attach_id, ‘is_private_doc’, true);
}
- upfadm_file_inserted: This filter is similar to the previous one but it is for the admin file manager. This will trigger when a file is uploaded in the backend file manager.
Example:
// For admin FM
add_action(‘upfadm_file_inserted’, ‘upf_extend_adm_file_inserted’, 10, 4);function upf_extend_adm_file_inserted($attach_id, $user_id, $role, $inside_file_manager = false ){
// set custom meta data of the file
update_post_meta($attach_id, ‘is_private_doc’, true);
update_post_meta($attach_id, ‘uploaded_by_admin’, true);
}
- upf_file_rename: This is triggered when a file is renamed.
Example:
// File renamed, perform some action
add_action(‘upf_file_rename’, ‘upf_extend_file_rename’, 10, 2);function upf_extend_file_rename($file_id, $new_name){
$curr_user_id = get_current_user_id();
update_post_meta($file_id, ‘last_renamed_by’, $curr_user_id);
}
- upf_file_delete: It is run when a file is deleted.
Example:
// File deleted, perform some action
add_action(‘upf_file_delete’, ‘upf_extend_file_delete’, 10, 1);function upf_extend_file_rename($file_id){
// Your code logic. e.g. You can send an email to admin when someone deletes a file.
}
- upf_file_move: When a file is moved to another folder.
Example:
// File moved
add_action(‘upf_file_move’, ‘upf_extend_file_move’, 10, 2);function upf_extend_file_move($file_id, $target_fldr){
// Your code logic
}
- upf_folder_create: This action is triggered when a new folder is created.
Example:
// Folder created
add_action(‘upf_folder_create’, ‘upf_extend_folder_create’, 10, 1);function upf_extend_folder_create($folder_id){
// Your code logic
}
- upf_folder_rename: When a folder is renamed, you can use this hook to perform some actions.
Example:
// Folder renamed
add_action(‘upf_folder_rename’, ‘upf_extend_folder_rename’, 10, 2);function upf_extend_folder_rename($folder_id, $name){
// Your code logic
}
- upf_folder_move: This is triggered when a folder is moved to another location.
Example:
// Folder moved
add_action(‘upf_folder_move’, ‘upf_extend_folder_move’, 10, 2);function upf_extend_folder_move($folder_id, $target_folder_id){
// Your code logic
}
- upf_folder_delete: Use this hook if you want to perform some actions when a folder is deleted.
Example:
// Folder moved
add_action(‘upf_folder_delete’, ‘upf_extend_folder_delete’, 10, 1);function upf_extend_folder_delete($folder_id){
// Your code logic
}
JS Actions Hooks
- UpfJSClassic_AfterUpload: This is triggered when files are done uploading in the [upf_upload] shortcode. You can use this trigger to display some message to the user that the file is uploaded. It provides one parameter fileCount that contains the number of the files that are uploaded.
Example:
jQuery(document).ready(function( $ ){
$(document).on(‘UpfJSClassic_AfterUpload’, function(event, data) {alert(data.fileCount + ‘ Files uploaded Successfully!’);
});
});