当前位置: 首页>>代码示例>>PHP>>正文


PHP WP_Import::fetch_remote_file方法代码示例

本文整理汇总了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;
 }
开发者ID:silverbux,项目名称:smartmag-magazine-wordpress,代码行数:37,代码来源:wp-import.php


注:本文中的WP_Import::fetch_remote_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。