Guest User

Untitled

a guest
May 21st, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. /**
  2. * This function will alter the upload url, path and subdir parameters
  3. *
  4. * @param $param array : upload parameters, ( path, url, ... )
  5. * @param $uploaded array : media details being uploaded, ( context_id, title, ... )
  6. *
  7. * @return array
  8. */
  9. function rtmedia_change_upload_path( $param, $uploaded ) {
  10.  
  11. // Return as it is if $param is not array
  12. if ( ! is_array( $param ) || ! is_array( $uploaded ) ) {
  13. return $param;
  14. }
  15.  
  16. // Change parameters only if the URL is from rtMedia and `get_the_ID()` returns valid post ID.
  17. if ( stripos( $param['url'], 'rtmedia' ) !== false ) {
  18. $param['url'] .= '/' . $uploaded['context_id'] . '-' . $uploaded['context'];
  19. $param['path'] .= '/' . $uploaded['context_id'] . '-' . $uploaded['context'];
  20. $param['subdir'] .= '/' . $uploaded['context_id'] . '-' . $uploaded['context'];
  21. }
  22.  
  23. return $param;
  24. }
  25. add_filter( 'rtmedia_filter_upload_dir', 'rtmedia_change_upload_path', 10, 2 );
Add Comment
Please, Sign In to add comment