WordPress简单实现发布文章自动下载远程图片

Home / Article MrLee 2015-6-8 3591

前面有Hacklog Remote Image Autosave插件下载图片,不过还不够精简,而且名字也没有改成日期,这样有重复名字的就不好了。还是自己实现一个插件好了。上源码
post_content,$post_ID);
	//Replace the image in the post
	wp_update_post(array('ID' => $post_ID, 'post_content' => $updated));
	// re-hook this function
	add_action('publish_post', 'fetch_images');
}
function post_save_images($content,$post_id){
	set_time_limit(360);
	$preg=preg_match_all('/$dirs['baseurl'].'/'._wp_relative_upload_path($file),
		'post_mime_type'=>$filetype['type'],
		'post_title'=>preg_replace('/.[^.]+$/','',basename($file)),
		'post_content'=>'',
		'post_status'=>'inherit'
	);
	$attach_id=wp_insert_attachment($attachment,$file,$id);
	$attach_data=wp_generate_attachment_metadata($attach_id,$file);
	wp_update_attachment_metadata($attach_id,$attach_data);
	return $attach_id;
}
?>
直接把这个文件添加到压缩包再上传到wordperss启动就行了,只要发布文章自动采集远程所有的图片(除了防采集的图片地址和本站的图片)。

本文链接:https://www.it72.com/3305.htm

推荐阅读
最新回复 (0)
返回