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

    (@nickboss)

    Hi, when medialink or postlink attributes are set to “true”, then the plugin adds the uploaded files to the Media items of your website by executing wfu_process_media_insert function of the plugin.

    Here is what you can do:

    1. Set medialink and postlink attributes to “false”, so that wfu_process_media_insert is not executed.
    2. Implement wfu_after_upload filter. If you have the Pro version, you can do it using Code Hooks feature of the plugin. If you have the Free version, you can use another plugin (like Code Snippets) or add the implementation code inside wfu_functions.php. Read this article for instructions about this filter.
    3. Inside the filter handler run function wfu_process_media_insert. This function takes 3 parameters, the filepath, any additional userdata fields and the page id (in case you want to attach the uploaded file to the page). The function returns the attachment ID of the uploaded file.
    4. Here is the complete implementation code:

    if (!function_exists('wfu_after_upload_handler')) {
    	function wfu_after_upload_handler($changable_data, $additional_data) {
    		$files = $additional_data["files"];
    		foreach ( $files as $ind => $file ) {
    			$attachment_ID = wfu_process_media_insert($file["filepath"], $file["user_data"], 0);
    			// perform here any actions with $attachment_ID
    		}
    		return $changable_data;
    	}
    	add_filter('wfu_after_upload', 'wfu_after_upload_handler', 10, 2);
    }

    I haven’t tried the above code, I hope it works. Please note that the above code will only add the uploaded files to Media items. It will not attach the files into the page (page id is 0).

    Nickolas

    Thread Starter friendofdog

    (@friendofdog)

    Many thanks – it works! I used the below action to pass the attachment ID to the appropriate field…

    $changable_data['js_script'] = '$("#attachment").val("' . $attachment_ID . '");';

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get attachment ID immediately after uploading’ is closed to new replies.