{"id":1452,"date":"2013-01-25T17:06:44","date_gmt":"2013-01-25T09:06:44","guid":{"rendered":"http:\/\/alyzq.com\/?p=1452"},"modified":"2013-01-25T17:06:44","modified_gmt":"2013-01-25T09:06:44","slug":"%e8%a7%a3%e5%86%b3wordpress-3-4-1-%e6%97%a5%e5%bf%97id%e4%b8%8d%e8%bf%9e%e7%bb%ad%e7%9a%84%e5%8a%9e%e6%b3%95","status":"publish","type":"post","link":"https:\/\/alyzq.com\/?p=1452","title":{"rendered":"\u89e3\u51b3WordPress 3.4.1 \u65e5\u5fd7ID\u4e0d\u8fde\u7eed\u7684\u529e\u6cd5"},"content":{"rendered":"<p>\u9020\u6210\u53d1\u5e03\u6587\u7ae0ID\u4e0d\u8fde\u7eed\u7684\u539f\u56e0\u6709\u4e09\u4e2a\uff1a<br \/>\n\u4e00\u662f\u81ea\u52a8\u4fdd\u5b58\u529f\u80fd Auto-Save<br \/>\n\u4e8c\u662f\u5386\u53f2\u7248\u672c\u529f\u80fd Post Revisions<br \/>\n\u4e09\u662f\u81ea\u52a8\u8349\u7a3f\u529f\u80fd Auto-Draft<\/p>\n<p>\u9488\u5bf9WordPress 3.4.1\uff0c\u7ed9\u51fa\u4ee5\u4e0b\u89e3\u51b3\u65b9\u6cd5\uff1a<br \/>\n1\u3001\u6253\u5f00 wp-config.php \u6587\u4ef6\uff0c\u5728 $table_prefix = \u2018wp_\u2019; \u524d\u9762\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801(\u6ce8\u610f\uff0c\u4e00\u5b9a\u662f $table_prefix = \u2018wp_\u2019; \u8fd9\u884c\u7684\u524d\u9762)\uff1a<\/p>\n<p>define(&#8216;WP_POST_REVISIONS&#8217;, false);<br \/>\ndefine(&#8216;AUTOSAVE_INTERVAL&#8217;, false);<\/p>\n<p>2\u3001\u627e\u5230\u5e76\u6253\u5f00 wp-admin\\post-new.php \u548c wp-admin\\post.php \u8fd9\u4e24\u4e2a\u6587\u4ef6\uff0c\u5c06\u5176 wp_enqueue_script(\u2018autosave\u2019); \u6ce8\u91ca\u6216\u5220\u9664\u6389\u3002<\/p>\n<p>3\u3001\u6253\u5f00 wp-admin\\includes\\post.php \u6587\u4ef6\uff0c\u627e\u5230<\/p>\n<p>if ( $create_in_db ) {<br \/>\n$post_id = wp_insert_post( array( &#8216;post_title&#8217; => __( &#8216;Auto Draft&#8217; ), &#8216;post_type&#8217; => $post_type, &#8216;post_status&#8217; => &#8216;auto-draft&#8217; ) );<br \/>\n$post = get_post( $post_id );<br \/>\nif ( current_theme_supports( &#8216;post-formats&#8217; ) &#038;&#038; post_type_supports( $post->post_type, &#8216;post-formats&#8217; ) &#038;&#038; get_option( &#8216;default_post_format&#8217; ) )<br \/>\nset_post_format( $post, get_option( &#8216;default_post_format&#8217; ) );<br \/>\n} else {<\/p>\n<p>\u5c06\u5176\u66ff\u6362\u4e3a\uff1a<\/p>\n<p>if ( $create_in_db ) {<br \/>\nglobal $current_user;\/\/\u83b7\u53d6\u5f53\u524d\u767b\u5f55\u7ba1\u7406\u7528\u6237<br \/>\n$post = $wpdb->get_row( &#8220;SELECT * FROM $wpdb->posts WHERE post_status = &#8216;auto-draft&#8217; AND post_type = &#8216;$post_type&#8217; AND post_author = $current_user->ID ORDER BY ID ASC LIMIT 1&#8221; );\/\/\u83b7\u53d6\u6700\u65e9\u4e00\u6761\u81ea\u52a8\u8349\u7a3f<br \/>\nif ( !$post ) {<br \/>\n$post_id = wp_insert_post( array( &#8216;post_title&#8217; => __( &#8216;Auto Draft&#8217; ), &#8216;post_type&#8217; => $post_type, &#8216;post_status&#8217; => &#8216;auto-draft&#8217; ) );<br \/>\n$post = get_post( $post_id );<br \/>\n}<br \/>\nif ( current_theme_supports( &#8216;post-formats&#8217; ) &#038;&#038; post_type_supports( $post->post_type, &#8216;post-formats&#8217; ) &#038;&#038; get_option( &#8216;default_post_format&#8217; ) )<br \/>\nset_post_format( $post, get_option( &#8216;default_post_format&#8217; ) );<br \/>\n} else {<\/p>\n<p>\u6b64\u65b9\u6cd5\u662f\uff0c\u5982\u679c\u6570\u636e\u5e93\u5df2\u7ecf\u6709\u4e0d\u53ef\u89c1\u7684\u81ea\u52a8\u8349\u7a3f\u65e5\u5fd7\uff0c\u90a3\u4e48\u70b9\u51fb\u6dfb\u52a0\u65b0\u6587\u7ae0\u65f6\uff0c\u5c06\u4e0d\u4f1a\u518d\u81ea\u52a8\u4ea7\u751f\u65b0\u7684\u4e0d\u53ef\u89c1\u81ea\u52a8\u8349\u7a3f\uff0c\u800c\u662f\u76f4\u63a5\u8c03\u7528\u6700\u65e9\u7684\u4e00\u7bc7\u4e0d\u53ef\u89c1\u8349\u7a3f\u4f5c\u4e3a\u5f53\u524d\u6587\u7ae0\u6240\u9700\u7684\u6570\u636e\u5e93\u8bb0\u5f55\u6765\u4f7f\u7528\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9020\u6210\u53d1\u5e03\u6587\u7ae0ID\u4e0d\u8fde\u7eed\u7684\u539f\u56e0\u6709\u4e09\u4e2a\uff1a \u4e00\u662f\u81ea\u52a8\u4fdd\u5b58\u529f\u80fd Auto-Save \u4e8c\u662f &hellip; <a href=\"https:\/\/alyzq.com\/?p=1452\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[21],"_links":{"self":[{"href":"https:\/\/alyzq.com\/index.php?rest_route=\/wp\/v2\/posts\/1452"}],"collection":[{"href":"https:\/\/alyzq.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alyzq.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alyzq.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alyzq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1452"}],"version-history":[{"count":0,"href":"https:\/\/alyzq.com\/index.php?rest_route=\/wp\/v2\/posts\/1452\/revisions"}],"wp:attachment":[{"href":"https:\/\/alyzq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alyzq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1452"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alyzq.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}