关闭WordPress自动保存和文章修订功能
<p><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>今天发文章时,惊奇的发现文章的ID竟然已经到达了19了。鉴于我以前折腾Wordpress的经验,我知道这是Wordpress的“自动保存和文章修订功能”在作怪。但是,该怎么才能关闭Wordpress的这个功能呢?!还是问“谷老师”吧。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>经过“谷老师”的指点,找到了解决办法。其实很简单,只需在wp-config.php中加入以下代码即可: </span></p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
define('AUTOSAVE_INTERVAL', 120 ); // 设置自动保存间隔,单位是秒,默认60 <br>
define('WP_POST_REVISIONS', false ); // 禁用文章修订功能 <br>
define('WP_POST_REVISIONS', 3); // </p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>根据你的需要将上述三行代码放到wp-config.php中,如果你不知道放在文件什么位置,这个文件中已经有很多define开头的代码,和他们放在一起就可以。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>很简单对吧,就像这两个功能都是累赘,毫无用处,如果你只想知道这些,写这篇文章就毫无意义了。甚至你可能还不是百分之百的清楚自动保存和文章修订到底有什么区别,到底谁是让数据库数据膨胀的罪魁祸首。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>那么我们继续看一看这两个东西。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><strong style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>自动保存(Auto-Save) </strong><br><br><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>这是一个非常实用的功能,当你编辑文章的时候,WordPress每隔60秒自动保存你输入的内容,防止因为电脑挂机或者断电而丢失辛苦劳动的成果。这个功能不同于自动修订,你完全不用担心它会让你的数据库数据膨胀,因为它只会创建一条记录,每隔60秒更新一次,当文章发布后,这条记录的post_status会从draft变成publish,没有一点浪费的地方。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>唯一给你带来麻烦的可能是保存间隔太短,服务器难受,写文章可能有间歇性卡的感觉,那么你可以将时间设置的长一点。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>define('AUTOSAVE_INTERVAL', 120 ); // 设置自动保存间隔,单位是秒,默认60 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>如果你倾向于用Word编辑,之后拷贝到WordPress的编辑器中,你也可以完全禁用自动保存功能,在主题的functions.php中加上如下代码就可以 </span></p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
function disable_autosave() { <br>
wp_deregister_script('autosave'); <br>
} <br>
add_action('wp_print_scripts','disable_autosave'); </p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>禁用后的副作用:预览功能不可用,必须保存为草稿才能预览 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>如果服务器还不错,这个自动保存功能基本不影响什么,Sola使用了60秒保存一次的自动保存,喜欢用WP的编辑器边写边预览,经常误点WP菜单(现在的菜单鼠标滑过就会弹出子菜单,很容易点错),要是没有60秒一次的自动保存,真不知道要浪费多少时间重新编辑了。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>文章修订(Post Revisions) </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>在编辑文章时,如果文章标题、内容或者摘要等字段发生变化,WordPress就会将当前版本保存为一个修订版,方便你想退回到之前的版本,这有点像svn的工作方式。随之而来的问题是,数据库会被修订版撑的很大,加之有自动保存的功能,让这个修订功能多少显得有点累赘。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>我们可以控制修订版的数量,例如一篇文章最多保存3个修订版 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>define('WP_POST_REVISIONS', 3); </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>这样,每创建一篇文章,数据库中会有1条auto-save+最多3条revision。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>或者完全禁用 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>define('WP_POST_REVISIONS', false ); </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>可以通过运行一条SQL语句彻底删除修订版以及与之相关的meta信息 </span></p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
DELETE a,b,c FROM wp_posts a <br>
LEFT JOIN wp_term_relationships b <br>
ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c <br>
ON (a.ID = c.post_id) WHERE a.post_type = 'revision'; </p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><strong style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>关于自动草稿</strong><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'> </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>自动保存产生的记录叫做草稿,还有一种记录叫做自动草稿,自动草稿在你点击写文章时就会自动创建。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>如果你点击写文章后: </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>输入内容,自动保存生效 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>手动将文章保存为草稿 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><strong style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>发布文章</strong><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'> </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>自动草稿记录会被转换成草稿或者文章,从而不产生垃圾数据。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>如果你点击写文章,什么也没写就关闭了,就产生了一条自动草稿垃圾记录,修改这个问题需要更改源代码,如果感兴趣可以google一下,但如果可以养成良好的写文章习惯,自动草稿根本不是问题,WordPress也有一些回收机制,例如每次新建文章时会自动清除7天以前的自动草稿。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>用插件管理文章不同版本 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>有一些插件可以帮助我们清理数据库,管理文章的各个版本。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>
Wp Cleaner<span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'> </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>使用时注意不要误删草稿,有时候我们会将没写完的文章保存为糟糕,删了就惨了。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>
Revision Control<span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'> </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>如果用短小精悍来形容Wp Cleaner,那么Revision Control就是五脏俱全了,功能强大,界面相对也复杂些。</span></p>
頁:
[1]