Skip to content

Instantly share code, notes, and snippets.

@tripflex
Last active December 13, 2019 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripflex/95925fc065ee40fead1c7d03204e9498 to your computer and use it in GitHub Desktop.
Save tripflex/95925fc065ee40fead1c7d03204e9498 to your computer and use it in GitHub Desktop.
Prepend username on any files uploaded with WP Job Manager
<?php
add_filter( 'job_manager_upload_file_pre_upload', 'smyles_add_user_login_to_file_uploads' );
function smyles_add_user_login_to_file_uploads( $file ) {
$user = wp_get_current_user();
if ( $user && $user->ID > 0 ) {
$file['name'] = sanitize_file_name( $user->user_login ) . '_' . $file['name'];
}
return $file;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment