[wp-trac] [WordPress Trac] #20168: How to: Avoid a bunch of useless Auto Draftt ID entries related in posts table and disable autosave feature in 'post-new.php'?
WordPress Trac
wp-trac at lists.automattic.com
Sun Mar 4 06:07:24 UTC 2012
#20168: How to: Avoid a bunch of useless Auto Draftt ID entries related in posts
table and disable autosave feature in 'post-new.php'?
-------------------------+------------------------------
Reporter: josoroma | Owner:
Type: enhancement | Status: closed
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 3.3.1
Severity: normal | Resolution: invalid
Keywords: |
-------------------------+------------------------------
Old description:
> I got it! Buuuuut I had to edit 2 core files, yes! 2 core files :(
>
> I know is not a cool plugin hack, but maybe a cool patch for WP, Im using
> 3.3.1 version.
>
> Well, here is my little hack/contribution:
>
> ----------------------------------------
> wp-admin/post-new.php
> ----------------------------------------
>
> 1 Comment:
>
> //wp_enqueue_script('autosave');
> 2 Change:
>
> $post = get_default_post_to_edit( $post_type, true );
> $post_ID = $post->ID;
> by:
>
> $post = array();
> $post_ID = 0;
>
> ----------------------------------------
> wp-admin/post.php
> ----------------------------------------
>
> 1 Change:
>
> if ( isset( $_GET['post'] ) )
> $post_id = $post_ID = (int) $_GET['post'];
> elseif ( isset( $_POST['post_ID'] ) )
> $post_id = $post_ID = (int) $_POST['post_ID'];
> else
> $post_id = $post_ID = 0;
> by:
>
> if ( isset( $_GET['post'] ) ) {
>
> $post_id = $post_ID = (int) $_GET['post'];
>
> } elseif ( isset( $_POST['post_ID'] ) ) {
>
> if ( empty($_POST['post_ID']) ) {
>
> $post_type = wp_kses($_POST['post_type']);
>
> if( !post_type_exists($post_type) ) {
>
> $post_type = 'post';
>
> }
>
> check_admin_referer('update-' . $post_type . '_' . (int)
> $_POST['post_ID']);
>
> global $user_ID;
>
> $defaults = array(
> 'post_status' => 'draft',
> 'post_type' => $post_type,
> 'post_author' => (int) $user_ID,
> );
>
> $postarr = wp_parse_args( $_POST, $defaults );
>
> $post_ID = wp_insert_post($postarr);
>
> $post_id = (int) $post_ID;
>
> redirect_post($post_id);
>
> exit;
>
> } else {
>
> $post_id = $post_ID = (int) $_POST['post_ID'];
>
> }
>
>
> } else {
>
> $post_id = $post_ID = 0;
>
> }
>
> I am using JQuery to hide: add media stuff. Just only a unique ID entry
> is created in posts table (and not a bunch of useless Auto Draft entries
> related) and media stuff will be visible after user manually saves
> current post.
>
> Rare behavior: When a user logins for the first time and is redirected to
> Dashboard, WP creates an Auto Draft entry in posts table, hmmm, crazy!
> Somebody knows why it works like that?
>
> A better solution: perhaps not altering at any chance core files? It will
> be a great one! For example, with a checkbox in Settings-->Writing to
> check or uncheck if we want the "autosave" feature or not. Somebody else
> wants to apply this patch?
>
> Thanks in advance.
New description:
I got it! Buuuuut I had to edit 2 core files, yes! 2 core files :(
I know is not a cool plugin hack, but maybe a cool patch for WP, Im using
3.3.1 version.
Well, here is my little hack/contribution:
{{{
----------------------------------------
wp-admin/post-new.php
----------------------------------------
1 Comment:
//wp_enqueue_script('autosave');
2 Change:
$post = get_default_post_to_edit( $post_type, true );
$post_ID = $post->ID;
by:
$post = array();
$post_ID = 0;
----------------------------------------
wp-admin/post.php
----------------------------------------
1 Change:
if ( isset( $_GET['post'] ) )
$post_id = $post_ID = (int) $_GET['post'];
elseif ( isset( $_POST['post_ID'] ) )
$post_id = $post_ID = (int) $_POST['post_ID'];
else
$post_id = $post_ID = 0;
by:
if ( isset( $_GET['post'] ) ) {
$post_id = $post_ID = (int) $_GET['post'];
} elseif ( isset( $_POST['post_ID'] ) ) {
if ( empty($_POST['post_ID']) ) {
$post_type = wp_kses($_POST['post_type']);
if( !post_type_exists($post_type) ) {
$post_type = 'post';
}
check_admin_referer('update-' . $post_type . '_' . (int)
$_POST['post_ID']);
global $user_ID;
$defaults = array(
'post_status' => 'draft',
'post_type' => $post_type,
'post_author' => (int) $user_ID,
);
$postarr = wp_parse_args( $_POST, $defaults );
$post_ID = wp_insert_post($postarr);
$post_id = (int) $post_ID;
redirect_post($post_id);
exit;
} else {
$post_id = $post_ID = (int) $_POST['post_ID'];
}
} else {
$post_id = $post_ID = 0;
}
}}}
I am using JQuery to hide: add media stuff. Just only a unique ID entry is
created in posts table (and not a bunch of useless Auto Draft entries
related) and media stuff will be visible after user manually saves current
post.
Rare behavior: When a user logins for the first time and is redirected to
Dashboard, WP creates an Auto Draft entry in posts table, hmmm, crazy!
Somebody knows why it works like that?
A better solution: perhaps not altering at any chance core files? It will
be a great one! For example, with a checkbox in Settings-->Writing to
check or uncheck if we want the "autosave" feature or not. Somebody else
wants to apply this patch?
Thanks in advance.
--
Comment (by dd32):
And for anyone who has come across this, Please don't re-open it, Instead,
if you have a better solution, create a new ticket detailing the pro's and
cons of that method.
Required reading priot to that however: The wp-hackers thread that led to
this ticket: http://lists.automattic.com/pipermail/wp-
hackers/2012-February/042398.html Otto's posts in that thread in
particular ( [http://lists.automattic.com/pipermail/wp-
hackers/2012-February/042402.html 1]
[http://lists.automattic.com/pipermail/wp-
hackers/2012-February/042409.html 2] and
[http://lists.automattic.com/pipermail/wp-
hackers/2012-February/042401.html 3]) as well as the prior tickets:
#11889, #11145, #11990
Auto-drafts were added to solve a real problem, and they serve a purpose.
They are automatically Garbage-collected, so you will not have a extreme
number in your database forever.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/20168#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list