本文整理匯總了PHP中WP_Import::fetch_remote_file方法的典型用法代碼示例。如果您正苦於以下問題:PHP WP_Import::fetch_remote_file方法的具體用法?PHP WP_Import::fetch_remote_file怎麽用?PHP WP_Import::fetch_remote_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類WP_Import
的用法示例。
在下文中一共展示了WP_Import::fetch_remote_file方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: fetch_remote_file
/**
* Use local images instead of remote images
*
* @see WP_Import::fetch_remote_file()
*/
public function fetch_remote_file($url, $post)
{
// only use if demo-data is present in the url
if (!strstr($url, '/demo-data/')) {
return parent::fetch_remote_file($url, $post);
}
// extract the file name and extension from the url
$file_name = basename($url);
// get placeholder file in the upload dir with a unique, sanitized filename
$upload = wp_upload_bits($file_name, 0, '', $post['upload_date']);
if ($upload['error']) {
return new WP_Error('upload_dir_error', $upload['error']);
}
// use the local image and write it to the placeholder file
$local_file = WP_CONTENT_DIR . '/' . substr($url, strrpos($url, '/themes/'));
file_put_contents($upload['file'], file_get_contents($local_file));
$filesize = filesize($upload['file']);
if (0 == $filesize) {
@unlink($upload['file']);
return new WP_Error('import_file_error', __('Zero size file downloaded', 'wordpress-importer'));
}
$max_size = (int) $this->max_attachment_size();
if (!empty($max_size) && $filesize > $max_size) {
@unlink($upload['file']);
return new WP_Error('import_file_error', sprintf(__('Remote file is too large, limit is %s', 'wordpress-importer'), size_format($max_size)));
}
// keep track of the old and new urls so we can substitute them later
$this->url_remap[$url] = $upload['url'];
$this->url_remap[$post['guid']] = $upload['url'];
// r13735, really needed?
return $upload;
}