Created
July 24, 2014 04:26
-
-
Save spivurno/94d2188fcdefa2f91705 to your computer and use it in GitHub Desktop.
Gravity Wiz // Gravity Forms // User-specific Upload Paths
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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 <[email protected]> | |
| * @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 | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment