尝试更改上传目录时为空白页

nis*_*isr 5 php directory wordpress attachment path

使用wordpress 4.2.2时,当我在子主题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' );
Run Code Online (Sandbox Code Playgroud)

我得到一张空白页!在function.php中没有空行,仅在添加此代码后问题才出现。我真的需要它来组织我的上载文件夹,但是没有空白页。有什么解决办法吗?

小智 0

如上所述,您需要查看错误报告。添加到 wp-config.php 的顶部: php error_reporting(E_ALL); ini_set('display_errors', 1);

如果这不起作用,请找到define('WP_DEBUG', false);该值并将其设置为true

这也可能有帮助,添加到 wp-config 的顶部以将错误通过管道传输到文档根目录下的 err.log : @ini_set( 'log_errors', 'On' ); @ini_set( 'display_errors', 'Off' ); @ini_set( 'error_log', $_SERVER['DOCUMENT_ROOT'] . '/err.log' );