Php 尝试更改上载目录时出现空白页

Php 尝试更改上载目录时出现空白页,php,wordpress,path,directory,attachment,Php,Wordpress,Path,Directory,Attachment,使用wordpress 4.2.2,当我在child theme function.php中使用此代码根据每个帖子类型更改附件上载目录时: function wpse_16722_type_upload_dir( $args ) { // Get the current post_id $id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : '' ); if( $id ) { // Set the new pat

使用wordpress 4.2.2,当我在child theme function.php中使用此代码根据每个帖子类型更改附件上载目录时:

function wpse_16722_type_upload_dir( $args ) {
// Get the current post_id
$id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : '' );
if( $id ) {    
   // Set the new path depends on current post_type
   $newdir = '/' . get_post_type( $id );
   $args['path']    = str_replace( $args['subdir'], '', $args['path'] ); //remove default subdir
   $args['url']     = str_replace( $args['subdir'], '', $args['url'] );      
   $args['subdir']  = $newdir;
   $args['path']   .= $newdir; 
   $args['url']    .= $newdir; 
   return $args;
   }
}
add_filter( 'upload_dir', 'wpse_16722_type_upload_dir' );
我得到一张空白页!! function.php中没有空行,只有在添加此代码后才会出现问题。我真的需要它来组织我的上传文件夹,但没有一个空白页。
有什么解决方案吗?

如上所述,您需要查看错误报告。添加到wp-config.php的顶部:
php错误报告(E_ALL);ini设置(“显示错误”,1)

如果不起作用,则查找
define('WP_DEBUG',false)
并将值设置为
true

这也可能会有所帮助,请将以下内容添加到wp config的顶部,以将错误传递到文档根目录下的err.log:

@ini_集('log_errors','On');
@ini_集('display_errors','Off');

@ini_集('error_log',$_SERVER['DOCUMENT_ROOT']./err.log')

空白页表示语法错误。在打开PHP标记后立即将错误报告添加到文件顶部,例如
未发生任何事情,未显示任何内容,空白页