由于图片版权问题,我想从我的Wordpress网站上删除从2012年到2015年7月的所有图片。我还想保留所有的文章或页面没有破碎的图片链接,删除images.If后,我手动删除一张图片(所有缩略图版本),然后在文章的前端显示损坏的图片链接。
有什么想法吗?
发布于 2017-03-03 23:35:45
进入FTP,在主题中查找uploads文件夹,文件就会相应地命名。
uploads/date...
您可以按月顺序查看已加载到WordPress中的所有图像,然后将其深入到day文件中。
发布于 2017-03-03 23:51:26
Wordpress在uploads中有一个文件夹结构,您可以创建一个脚本来删除这些文件夹或文件,如下所示
function recursive_remove_directory($directory, $empty=FALSE)
{
if(substr($directory,-1) == '/')
{
$directory = substr($directory,0,-1);
}
if(!file_exists($directory) || !is_dir($directory))
{
return FALSE;
}elseif(is_readable($directory))
{
$handle = opendir($directory);
while (FALSE !== ($item = readdir($handle)))
{
if($item != '.' && $item != '..')
{
$path = $directory.'/'.$item;
if(is_dir($path))
{
recursive_remove_directory($path);
}else{
unlink($path);
}
}
}
closedir($handle);
if($empty == FALSE)
{
if(!rmdir($directory))
{
return FALSE;
}
}
}
return TRUE;
}
你使用这个
recursive_remove_directory (WP_CONTENT_DIR.'/uploads/2012');
recursive_remove_directory (WP_CONTENT_DIR.'/uploads/2013');
recursive_remove_directory (WP_CONTENT_DIR.'/uploads/2014');
recursive_remove_directory (WP_CONTENT_DIR.'/uploads/2015/01');
recursive_remove_directory (WP_CONTENT_DIR.'/uploads/2015/02');
.....
recursive_remove_directory (WP_CONTENT_DIR.'/uploads/2015/06');
在你的functions.php文件中添加函数,然后占据WP_Query并获得2012 - 2015年7月的所有帖子,删除内容的图片,如下所示:
$content = get_the_content ();
$content = preg_replace ("/ <img [^>] + \> / i", "", $ content);
$content = apply_filters ('the_content', $ content);
$content = str_replace (']>', ']]>', $ content);
并占用wp_update_post更新内容,这将从内容中删除所有图像
https://stackoverflow.com/questions/42582835
复制相似问题