我在Wordpress uploads文件夹中创建了许多子文件夹,并希望根据仪表板中显示的当前页面以编程方式指定文件应上传到哪个文件夹。
这是我到目前为止的代码:
function field_name_upload_prefilter($errors) {
// in this filter we add a WP filter that alters the upload path
add_filter('upload_dir', 'field_name_upload_dir');
return $errors;
}
// Second filter
function field_name_upload_dir($uploads) {
// here is where we later the path
if($pagenow == 'archive'){
$uploads['path'] = $uploads['basedir'].'/archive';
$uploads['url'] = $uploads['baseurl'].'/archive';
$uploads['subdir'] = '';
}
if ($pagenow = 'assets') {
$uploads['path'] = $uploads['basedir'].'/assets';
$uploads['url'] = $uploads['baseurl'].'/assets';
$uploads['subdir'] = '';
}
return $uploads;
}