打開文件 wp-content\themes\justnews\functions.php
查找代碼:
if(is_singular('post') && in_the_loop() && is_main_query() && isset($options['expand_more']) && $options['expand_more'] == '1'){
$content .= '<div class="entry-readmore"><div class="entry-readmore-btn"></div></div>';
}
在下面增加:
if (isset($options['save_remote_img']) && $options['save_remote_img'] == '1') {
preg_match_all('/<img[^>]*src=[\'"]([^\'"]+)[\'"].*>/iU', $content, $matches);
if (!empty($matches[1])) {
foreach ($matches[1] as $image_url) {
// 獲取遠(yuǎn)程圖片
$image = file_get_contents($image_url);
// 生成本地文件名
$upload_dir = wp_upload_dir();
$filename = basename($image_url);
$local_image_path = $upload_dir['path'] . '/' . $filename;
// 保存圖片到本地
file_put_contents($local_image_path, $image);
// 替換文章中的遠(yuǎn)程圖片鏈接為本地鏈接
$content = str_replace($image_url, $upload_dir['url'] . '/' . $filename, $content);
}
}
}
這樣后臺如果開啟了 保存遠(yuǎn)程圖片 得情況 使用接口發(fā)布得文章也會自動將文章內(nèi)得圖片下載到本地了。