我正在使用Smart Image Resizer来显示图片。这在单站点WP上工作正常。但它对WPMU不起作用。
是否有人使用子域名在WPMU中使用Smart Image Resizer?
答案 0 :(得分:0)
好的,所以我通过黑客攻击image.php文件来修复它。
问题是Smart Image Resizer使用DOCUMENT_ROOT
来定义基本上传文件夹。它不包括wordpress上传文件夹(适用于WP和WPMU)。所以我在image.php文件中添加/更改了一些代码来解决这个问题。
// Let's include Wordpress libraries
// We assume this file WILL be located in root folder
require_once($_SERVER['DOCUMENT_ROOT'].'/wp-blog-header.php');
// This must be included just after the above include. Otherwise we can get a 404 Not Found error in WPMU
header('HTTP/1.1 200 OK'); // ****** Wordpress hack ********
//Define upload dir for Wordpress
$upload_dir = wp_upload_dir();
define('WP_IMAGE_UPLOAD_DIR', str_replace("\\","/",$upload_dir['basedir']));
define('WP_IMAGE_UPLOAD_URL', str_replace("\\","/",$upload_dir['baseurl']));
// Replace the original code to remove base URL (and upload path)
$image = str_replace(WP_IMAGE_UPLOAD_URL,'',$_GET['image']);
// Then I replace the old docRoot with the new upload path,
// and kept the stripping of possible trailing slash off the document root
$docRoot = preg_replace('/\/$/', '', WP_IMAGE_UPLOAD_DIR);
// Then I change the code so it uses correct upload path.
if (!file_exists(WP_IMAGE_UPLOAD_DIR . $image))
{
header('HTTP/1.1 404 Not Found');
echo 'Error: image does not exist: ' . WP_IMAGE_UPLOAD_DIR . $image;
exit();
}
现在它适用于WP和WPMU。