';
echo '
Add Prefix on File Upload
';
echo 'Visit our website to see our plugins
';
echo '';
echo '';
}
/**
* Registers the settings used by the plugin.
*/
function add_prefix_file_upload_register_settings() {
register_setting(
'add-prefix-file-upload-settings-group', // Option Group
'new_file_name_prefix', // Option Name
'sanitize_text_field' // Sanitize user input
);
}
add_action('admin_init', 'add_prefix_file_upload_register_settings');
/**
* Renames the uploaded file using the custom prefix.
*/
function add_prefix_file_upload_rename_uploaded_file($file) {
$prefix = get_option('new_file_name_prefix');
$prefix = sanitize_text_field(get_option('new_file_name_prefix'));
$file['name'] = $prefix . '-' . $file['name'];
return $file;
}
add_filter('wp_handle_upload_prefilter', 'add_prefix_file_upload_rename_uploaded_file');
?>