wordpress禁止保存草稿

文章描述:

WordPress在发布文章保存草稿会生成很多大量的数据,会沉淀在数据库里面,使得数据库越来越臃肿,那么如何禁止WordPress自动保存草稿呢?

1.在根目录下面找到wp-config.php文件,打开找到:

define(\'WP_DEBUG\', false);

下面添加:

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

 

wordpress禁止保存草稿

2.打开wp-admin/includes/post.php,大约在670行,找到以下代码:

注释掉:

$post_id = wp_insert_post(
   array(
      \'post_title\'  => __( \'Auto Draft\' ),
      \'post_type\'   => $post_type,
      \'post_status\' => \'auto-draft\',
   )
);
$post    = get_post( $post_id );
if ( current_theme_supports( \'post-formats\' ) && post_type_supports( $post->post_type, \'post-formats\' ) && get_option( \'default_post_format\' ) ) {
   set_post_format( $post, get_option( \'default_post_format\' ) );
}

添加以下代码:

global $wpdb;
if ( $create_in_db ) {
    global $current_user;
    $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 );
    }
    if ( current_theme_supports( \'post-formats\' ) && post_type_supports( $post->post_type, \'post-formats\' ) && get_option( \'default_post_format\' ) )
        set_post_format( $post, get_option( \'default_post_format\' ) );
}

 

© 版权声明
THE END
点赞0打赏 分享
评论 抢沙发

请登录后发表评论

    请登录后查看评论内容