0

我正在使用Smart Image Resizer来显示图像。这在单站点 WP 上运行良好。但它不适用于 WPMU。

有没有人使用子域在 WPMU 中使用 Smart Image Resizer?

4

1 回答 1

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。

于 2010-09-21T20:38:08.057 回答