Guest User

Untitled

a guest
Jan 21st, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. function fcsp_type_upload_dir( $args ) {
  2.  
  3. // Get the current post_id
  4. $id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : '' );
  5.  
  6. if( $id ) {
  7. // Set the new path depends on current post_type
  8. $newdir = '/' . get_post_type( $id );
  9.  
  10. $args['path'] = str_replace( $args['subdir'], '', $args['path'] ); //remove default subdir
  11. $args['url'] = str_replace( $args['subdir'], '', $args['url'] );
  12. $args['subdir'] = $newdir;
  13. $args['path'] .= $newdir;
  14. $args['url'] .= $newdir;
  15. }
  16. return $args;
  17. }
  18. add_filter( 'upload_dir', 'fcsp_type_upload_dir' );
  19.  
  20. define( 'UPLOADS', trailingslashit( WP_CONTENT_DIR ) . '$newdir' );
Add Comment
Please, Sign In to add comment