/** Force wp_upload_dir() to use time-based paths. */
add_filter( \'pre_option_uploads_use_yearmonth_folders\', \'__return_true\' );
/**
* Use the date format MMYY instead of YYYY/MM in the uploads path.
*
* @param array $dir
* @return array
*/
function wpse_104005_upload_dir( $dir ) {
if ( preg_match( \'!/([0-9]{4})/([0-9]{2})!\', $dir[\'subdir\'] ) ) { // Check we do indeed have a date-based subdir
$dir[\'subdir\'] = \'/\' . substr( $dir[\'subdir\'], 6, 2 ) . substr( $dir[\'subdir\'], 3, 2 );
$dir[\'path\'] = $dir[\'basedir\'] . $dir[\'subdir\'];
$dir[\'url\'] = $dir[\'baseurl\'] . $dir[\'subdir\'];
}
return $dir;
}
add_filter( \'upload_dir\', \'wpse_104005_upload_dir\', 100 );
过滤器
upload_dir
不会通过
$time
变量,因此在子目录上使用regex。
Update: 关于你的问题,加载wp-admin/options.php
在浏览器中,确保以下值为:
upload_path: news
upload_url_path: http://domain.com/news
如果仍然失败,请尝试使用中的完整路径
upload_path
(通常类似于
/user/public_html/news
, 使用
phpinfo()
如果不确定)。