Make WordPress Core

Opened 12 years ago

Closed 10 years ago

#26832 closed defect (bug) (fixed)

Unable to force delete using get_delete_post_link()

Reported by: henrywright's profile henry.wright Owned by: chriscct7's profile chriscct7
Milestone: 4.4 Priority: normal
Severity: normal Version: 3.8
Component: Posts, Post Types Keywords: needs-testing has-patch
Focuses: Cc:

Description

I seem to be unable to force delete when using get_delete_post_link()

Doing the following inside the loop sends the post to trash.

get_delete_post_link( $post_id, '', true );

Shouldn't passing true as the third parameter cause the post to be permanently deleted?

http://codex.wordpress.org/Function_Reference/get_delete_post_link

Attachments (2)

26832.patch (560 bytes) - added by chriscct7 10 years ago.
26832.2.patch (716 bytes) - added by johnbillion 10 years ago.

Download all attachments as: .zip

Change History (16)

#1 @bcworkz
12 years ago

  • Keywords dev-feedback added

The problem appears to be in source:/trunk/src/wp-admin/post.php#L291 $force = ! EMPTY_TRASH_DAYS;

The constant defaults to 30, so for most people $force will be false. This appears to be logic to send deletions to trash unless trash is disabled by setting the constant to 0. As this is in the 'delete' case and not the 'trash' case, this logic seems out of place to me. If code reaches this point, the trash option should not even be a possibility, though there appears to be some reason for not deleting attachments which I'm unfamiliar with, and the reason I've not provided a patch.

#2 @henry.wright
12 years ago

bcworkz

Perhaps this just needs an update to the Codex explaining that define( 'EMPTY_TRASH_DAYS', 0 ); must be defined in config.php in order for force delete to work? Then again, not everybody would want to disable trash completely across their whole site just to make the get_delete_post_link function work.

#3 @nacin
12 years ago

  • Component changed from General to Trash

#4 @nacin
12 years ago

  • Component changed from Trash to Posts, Post Types

@chriscct7
10 years ago

#5 @chriscct7
10 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 4.4
  • Owner set to chriscct7
  • Status changed from new to assigned

Feedback is requested on whether the function should change as proposed. It seems to me to make more sense.

This ticket was mentioned in Slack in #core by chriscct7. View the logs.


10 years ago

#7 @chriscct7
10 years ago

  • Keywords commit added; dev-feedback removed

#8 @johnbillion
10 years ago

  • Keywords needs-patch added; has-patch commit removed

The issue isn't in the get_delete_post_link() function, so 26832.patch will have no effect. The issue is that a post that's "deleted" with the link from get_delete_post_link( $post_id, '', true ) is actually trashed.

The issue is in the logic in the 'delete' case in wp-admin/post.php which only deletes a post if EMPTY_TRASH_DAYS is empty.

#9 follow-up: @johnbillion
10 years ago

  • Keywords has-patch needs-testing added; needs-patch removed

26832.2.patch should address this, but needs full testing and we also need to check if anywhere in the admin is using a delete link when it should be using a trash link.

#10 @chriscct7
10 years ago

  • Keywords needs-patch added; has-patch needs-testing removed

@johnbillion what about adding a forcedelete action?

Also, you need the changes in the original patch because without them, the link runs the trash not delete action.

#11 @chriscct7
10 years ago

  • Keywords needs-testing added

#12 @chriscct7
10 years ago

I'll contradict myself and point out I was misreading the original conditional. Ignore comment:10

#13 in reply to: ↑ 9 @SergeyBiryukov
10 years ago

  • Keywords has-patch added; needs-patch removed

Replying to johnbillion:

26832.2.patch should address this, but needs full testing and we also need to check if anywhere in the admin is using a delete link when it should be using a trash link.

We use a delete link in WP_Posts_List_Table::handle_row_actions() and attachment_submit_meta_box(). Both look proper and are only displayed if EMPTY_TRASH_DAYS is disabled or the post is already in Trash.

#14 @SergeyBiryukov
10 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 34794:

Respect the force_delete parameter of get_delete_post_link().

Previously, it only worked if EMPTY_TRASH_DAYS was disabled.

Props johnbillion, chriscct7.
Fixes #26832.

Note: See TracTickets for help on using tickets.