Created
December 7, 2013 17:37
-
-
Save mustafauysal/7845879 to your computer and use it in GitHub Desktop.
Change WordPress upload_dir per post type.
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 | |
/** | |
* Change upload dir for video post type | |
* Media files that comes from video post type will be stored under | |
* wp-content/uploads/video/year/month/file-name.blah | |
* use "upload_dir" filter | |
* @param $args | |
* @return mixed | |
*/ | |
public function video_upload_directory( $args ) { | |
$id = $_REQUEST['post_id']; | |
$parent = get_post( $id )->post_parent; | |
$video_dir = "/videos"; | |
// Check the post-type | |
if ( "video" == get_post_type( $id ) || "video" == get_post_type( $parent ) ) { | |
$args['subdir'] = $video_dir . $args['subdir']; | |
$args['path'] = $args['basedir'] . $args['subdir']; | |
$args['url'] = $args['baseurl'] . $args['subdir']; | |
} | |
return $args; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment