Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This function will alter the upload url, path and subdir parameters
- *
- * @param $param array : upload parameters, ( path, url, ... )
- * @param $uploaded array : media details being uploaded, ( context_id, title, ... )
- *
- * @return array
- */
- function rtmedia_change_upload_path( $param, $uploaded ) {
- // Return as it is if $param is not array
- if ( ! is_array( $param ) || ! is_array( $uploaded ) ) {
- return $param;
- }
- // Change parameters only if the URL is from rtMedia and `get_the_ID()` returns valid post ID.
- if ( stripos( $param['url'], 'rtmedia' ) !== false ) {
- $param['url'] .= '/' . $uploaded['context_id'] . '-' . $uploaded['context'];
- $param['path'] .= '/' . $uploaded['context_id'] . '-' . $uploaded['context'];
- $param['subdir'] .= '/' . $uploaded['context_id'] . '-' . $uploaded['context'];
- }
- return $param;
- }
- add_filter( 'rtmedia_filter_upload_dir', 'rtmedia_change_upload_path', 10, 2 );
Add Comment
Please, Sign In to add comment