-
-
Save fritids/9041141 to your computer and use it in GitHub Desktop.
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 | |
add_filter('upload_dir', 'cgg_upload_dir'); | |
function cgg_upload_dir($dir) | |
{ | |
// xxx Lots of $_REQUEST usage in here, not a great idea. | |
// Are we where we want to be? | |
if (!isset($_REQUEST['action']) || 'upload-attachment' !== $_REQUEST['action']) { | |
return $dir; | |
} | |
// post types match up? | |
if (!isset($_REQUEST['post_id']) || 'ml_resource' !== get_post_type($_REQUEST['post_id'])) { | |
return $dir; | |
} | |
$exts = apply_filters('ml_resource_whitelist_ext', array('jpe?g', 'png', 'gif', 'bmp')); | |
// let images to do their own thing | |
if (!isset($_REQUEST['name']) || preg_match('/(' . implode('|', $exts) .')$/ui', $_REQUEST['name'])) { | |
return $dir; | |
} | |
// modify the path and url for other files. | |
$resources = apply_filters('ml_resource_directory', 'resources'); | |
$dir['path'] = path_join($dir['basedir'], $resources); | |
$dir['url'] = path_join($dir['baseurl'], $resources); | |
return $dir; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment