Gravity Wiz // Gravity Forms // User-specific Upload Paths
<?php
/**
* Gravity Wiz // Gravity Forms // User-specific Upload Paths
*
* Modifies the default Gravity Forms file upload path to user-specific (based on the user login) upload paths.
* If the user's login were "john315", the upload path would be ".../wp-content/uploads/john315/".
* If the user is not logged in, the default GF upload path will be used.
*
* @version 1.0
* @author David Smith <david@gravitywiz.com>
* @license GPL-2.0+
* @link http://gravitywiz.com/...
*/
add_filter( 'gform_upload_path', 'gw_user_specific_upload_path' );
function gw_user_specific_upload_path( $upload_path ) {
if( ! is_user_logged_in() ) {
return $upload_path;
}
$user = wp_get_current_user();
$username = $user->get( 'user_login' );
$upload_dir = wp_upload_dir();
$user_dir = $upload_dir['basedir'] . "/{$username}/";
$user_url = $upload_dir['baseurl'] . "/{$username}/";
return array(
'path' => $user_dir,
'url' => $user_url
);
}