• Resolved travhow

    (@travhow)


    Hi,
    How can I prepend a filename on upload? For example, I would like the file to be something like:
    ppg.%username%.filename.ext

    Thanks for your help!

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author nickboss

    (@nickboss)

    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

    Thread Starter travhow

    (@travhow)

    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?

    Plugin Author nickboss

    (@nickboss)

    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

    Thread Starter travhow

    (@travhow)

    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!

    Plugin Author nickboss

    (@nickboss)

    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

    Thread Starter travhow

    (@travhow)

    Thanks for all of your assistance Nickolas!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Prepend Filename’ is closed to new replies.