admin管理员组文章数量:1312635
Per default, the way to disable autosaving and post revisions, is to modify wp-config.php
. Is there a way, to do that from within a plugin or a themes functions.php
?
Per default, the way to disable autosaving and post revisions, is to modify wp-config.php
. Is there a way, to do that from within a plugin or a themes functions.php
?
- Have you already checked when and where the constants get checked for the first time? Any research? Also, please mind your markup. Thanks. Btw, I fixed your title to fit your spare contents. – kaiser Commented Feb 2, 2016 at 15:01
- Did any of the answers worked for you? If so, it would be nice to accept since doing so builds trust to others facing the same issues. – marikamitsos Commented Sep 11, 2016 at 11:51
- @marikamitsos I have posted it as answer. However, finally I've managed not to disable what WP thinks is reccomended. – T.Todua Commented Sep 12, 2016 at 14:02
- In that case, you can always accept your own answer. Or even post how you've "...managed not to disable what WP thinks is recommended" – marikamitsos Commented Sep 14, 2016 at 14:12
4 Answers
Reset to default 1You mentioned:
Is there a way, to do that from within a plugin or a themes functions.php?
You may want to try the following code. Just place it inside your theme's functions.php file. Using it, you do NOT have to alter the wp-config.php file.
define('WP_POST_REVISIONS', false);
function disable_autosave() {
wp_deregister_script('autosave');
}
add_action('wp_print_scripts', 'disable_autosave');
i have found this code:
define('my_revisions_amount', 1); // let keep only one revision
define('my_autosave_interval', 600); // 600 minutes is enough
if (is_admin()){
add_filter( 'wp_revisions_to_keep', function(){
return my_revisions_amount;
} );
add_filter( 'wp_print_scripts', function(){
wp_localize_script( 'autosave', 'autosaveL10n',
array(
'autosaveInterval'=> my_autosave_interval,
'blog_id' => get_current_blog_id(),
)
);
}, 11 );
}
This is my way of disabling autosave. It can be improved:
jQuery(document).ajaxSend(function( event, jqxhr, settings) {
if(settings && settings.data && settings.data.indexOf("wp_autosave") > 0) {
jqxhr.abort();
}
});
Just checks the ajax request before it's sent to the server, and then cancels it if it's data contains wp_autosave
string.
For guys who use WordPress 5.0+ version with Gutenberg Editor, the below code snippet works to disable auto drafting/saving.
/**
* Disables auto-saving feature for Gutenberg Editor (set interval by 3600s)
*/
add_filter( 'block_editor_settings', 'rsm0128_block_editor_settings', 10, 2 );
function rsm0128_block_editor_settings( $editor_settings, $post ) {
$editor_settings['autosaveInterval'] = 3600;
return $editor_settings;
}
本文标签: autosaveDisable autosave and post revisions from inside a theme or plugin
版权声明:本文标题:autosave - Disable auto-save and post revisions from inside a theme or plugin 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741895735a2403565.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论