wordpress 关闭自动保存autosave 自动草稿auto-draft完整方法

Nenge123 Wordpress

流程

  • 文件 ~/wp-config.php
<?php
  define( 'AUTOSAVE_INTERVAL', 99999999999 ); //超过99999999999秒才保存
  define('WP_POST_REVISIONS', 99999999999 );  //超过99999999999秒才保存
?>
  • 后台文件 ~/wp-admin/includes/post.php

    取消自动草稿auto-draft

<?php
if ( $create_in_db ) {
  /**
   * 原始代码
   * $post_id = wp_insert_post(
   * array(
   * 'post_title'  => __( 'Auto Draft' ),
   * 'post_type'   => $post_type,
   * 'post_status' => 'auto-draft',
   * ),
   * false,
   * false
   * );
   * $post    = get_post( $post_id );
   * 修改为以下代码
   */
  $posts = query_posts(array(
    'post_status' => 'auto-draft',
    'post_type' => $post_type,
    'posts_per_page' => 1
  ));
  if ($posts) {
    $post = get_post($posts[0]->ID);
  } else {
    $post_id = wp_insert_post(array(
       'post_title' => __('Auto Draft') ,
       'post_type' => $post_type,
       'post_status' => 'auto-draft',
    ));
    $post = get_post($post_id);
  }
?>

评论