本文整理汇总了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;
}