WordPress禁用自动保存草稿去除文章修订功能

下面的方法需要修改源文件所以在打开每一个文件之前,记得一定要先做好备份!

禁用文章修订历史版本

1.打开 wp-config.php 文件
2.在 $table_prefix = \’wp_\’; 前面添加下面的两行代码:

define(\'WP_POST_REVISIONS\', false);//禁用历史修订版本
define(\'AUTOSAVE_INTERVAL\', false);//自动保存时间设置为一天

如下:

禁用自动保存功能

1.打开 wp-admin/post.php 文件,搜索 if ( \’attachment\’ !== $post_type ) ,找到以下代码 150-151行

if ( \'attachment\' !== $post_type )
wp_enqueue_script(\'autosave\');

将这两行用注释符号//注释即可!如下:

2.打开 wp-admin/post-new.php 文件,搜索 wp_enqueue_script( \’autosave\’ ); (69行),在代码前面加//将其注释或删除

禁用自动草稿功能

打开 wp-adminincludespost.php 文件,搜索 if ( $create_in_db ) { 找到以下代码 597行

$post_id = wp_insert_post( array( \'post_title\' => __( \'Auto Draft\' ), \'post_type\' => 
$post_type, \'post_status\' => \'auto-draft\' ) ); $post = get_post( $post_id );

修改为:

global $current_user,$wpdb; $post = $wpdb->get_row( "SELECT * FROM $wpdb->posts WHERE post_status = \'auto-draft\' AND post_type = \'$post_type\' AND post_author = $current_user->ID ORDER BY ID ASC LIMIT 1" ); if (!($post) ) { $post_id = wp_insert_post( array( \'post_title\' => __( \'Auto Draft\' ), \'post_type\' => $post_type, \'post_status\' => \'auto-draft\' ) ); $post = get_post( $post_id ); }

如下:

标签:WordPress 发布于:2019-10-23 09:09:59