Hi, you can do it with a plugin hook. If you have the free version, you need to put the following code at the end of functions.php file of your theme:
if (!function_exists('wfu_before_file_check_handler')) {
function wfu_before_file_check_handler($changable_data, $additional_data) {
$user = get_userdata($additional_data["user_id"]);
if ( $user != false ) {
$username = $user->user_login;
$filename = wfu_basename($changable_data["file_path"]);
$filepath = wfu_basedir($changable_data["file_path"]);
$changable_data["file_path"] = $filepath."ppg.".$username.".".$filename;
}
return $changable_data;
}
add_filter('wfu_before_file_check', 'wfu_before_file_check_handler', 10, 2);
}
Regards
Nickolas
Thanks Nickolas! This is close, but I am still getting a little weird output. My filename ended up as ppg-trav_-horntest-gmail-com_-test_.png, so it seems that there are some extra ‘_’ and the dots are becoming ‘-‘. Any idea how to fix this?
Add also the following lines:
if ( isset($GLOBALS[“WFU_GLOBALS”][“WFU_WILDCARD_ASTERISK_MODE”]) ) $GLOBALS[“WFU_GLOBALS”][“WFU_WILDCARD_ASTERISK_MODE”][3] = “loose”;
if ( isset($GLOBALS[“WFU_GLOBALS”][“WFU_SANITIZE_FILENAME_DOTS”]) ) $GLOBALS[“WFU_GLOBALS”][“WFU_SANITIZE_FILENAME_DOTS”][3] = “false”;
Nickolas
Where exactly should I add those lines? I have tried before the initial if statement, inside the function, and inside the if ($user != false) statement, and they all returned the same results as before.
Thanks!
They should be put before the if statement.
If they do not work, try something else. Open the visual editor of the shortcode and enable attribute “Do not change filename”.
Nickolas
Thanks for all of your assistance Nickolas!