• Resolved Delia Carballo

    (@soydelia)


    I have read that it is possible to change filenames with a hook.

    I have a custom field called “Select file type” with 3 options and user must select one of them (option1, option2, option3).

    I would like that the name of uploaded file to be:
    – option1.* if user select “option1”
    – option2.* if user select “option2”
    – option3.* if user select “option3”

    I have pro version of the plugin.

    Thanks.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter Delia Carballo

    (@soydelia)

    I’m sorry, I’ve forgotten something in filename.

    I would like that the name of uploaded file to be:
    – username-option1.* if user select “option1”
    – username-option2.* if user select “option2”
    – username-option3.* if user select “option3”

    Thanks!

    Plugin Author nickboss

    (@nickboss)

    Hi, just one question: will the uploader be always a logged user?

    Regards

    Nickolas

    Thread Starter Delia Carballo

    (@soydelia)

    Yes, the uploader will always be a logged user.

    Plugin Author nickboss

    (@nickboss)

    Hi, ok here are instructions:

    1. Go to the Dashboard area of the plugin at Hooks tab and add a new hook.
    2. Give it any title you want.
    3. Put the following code in the Code box:

    
    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 ) {
    			$filepath = wfu_basedir($changable_data["file_path"]);
    			$username = $user->user_login;
    			$new_filename = $changable_data["user_data"][0]["value"];
    			$fileext = wfu_fileext($changable_data["file_path"], true);
    			$changable_data["file_path"] = $filepath.$username."-".$new_filename.$fileext;
    		}
    		return $changable_data;
    	}
    	add_filter('wfu_before_file_check', 'wfu_before_file_check_handler', 10, 2); 
    }
    

    4. Set Status to Active and Save.

    You are done. Test and and let me know if it works.

    Nickolas

    Thread Starter Delia Carballo

    (@soydelia)

    Hello,

    I get this error:

    ————–

    Warning: file_get_contents(https:// […] /wp-admin/admin-ajax.php): failed to open stream: HTTP request failed! HTTP/1.1 503 Service Unavailable in /homepages/ […] /wp-content/plugins/wordpress-file-upload-pro/lib/wfu_functions.php on line 2658

    Hook has been saved but cannot be activated because the code contains errors. Please check its syntax.

    ———

    Plugin Author nickboss

    (@nickboss)

    To my environment it does not generate any errors. Please go to Settings of the plugin and activate option ModSecurity Restrictions. Then try to set it again to active and save it.

    Nickolas

    Thread Starter Delia Carballo

    (@soydelia)

    Done. Now it works.

    Thanks a lot!!!

    Thread Starter Delia Carballo

    (@soydelia)

    I forgot to mark it as resolved.

    Thanks again ??

    Hi Nicholas,

    I am basically looking for the same solution, but can’t find the “hooks” tab in WordPress File Upload Control Panel. Does it have a different name now?

    Plugin Author nickboss

    (@nickboss)

    Hi, if you have the Free version, then there is not hook tab. This is a feature of the Pro version. You have 2 alternatives:

    1. Install Code Snippets plugin. This is the same as Hooks feature. You can put the hook code in a snippet.
    2. Just edit functions.php file of your theme and put the hook code there.

    Regards

    Nickolas

    Or just buy pro? ??

    Plugin Author nickboss

    (@nickboss)

    yep, this is also a good option ??

    If you are not satisfied, then I will refund you.

    Nickolas

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Change filename’ is closed to new replies.