WordPress.org

Make WordPress Core

Opened 9 years ago

Closed 7 years ago

#5792 closed defect (bug) (worksforme)

delete_post doesn't appear to be called when deleting via AJAX

Reported by: Viper007Bond Owned by:
Milestone: Priority: high
Severity: normal Version: 2.5
Component: Administration Keywords: needs-patch
Focuses: Cc:

Description

I have a plugin that uses delete_post to do some stuff when a post is deleted. If I disable JS and click on a delete post link in Manage -> Posts, my function runs fine. However, if I delete the post via AJAX, my function doesn't seem to run.

Anyone able to reproduce? The AJAX calls wp_delete_post() which is where the hook is located, so I'm not quite sure why it's not working.

Change History (9)

#1 @Viper007Bond
9 years ago

  • Summary changed from delete_post doesn't appear to be used when deleting via AJAX to delete_post doesn't appear to be called when deleting via AJAX

#2 follow-up: @fitztrev
9 years ago

Yes, I have been working on this problem and can reproduce. I mentioned last week in the forum where someone else had the same issue: http://wordpress.org/support/topic/150151?replies=3

Just like you, I have no idea why it is occurring.

#3 @Viper007Bond
9 years ago

  • Priority changed from normal to high

#4 in reply to: ↑ 2 @Viper007Bond
9 years ago

  • Keywords needs-patch added

Replying to fitztrev:

Yes, I have been working on this problem and can reproduce.

Ah, okay, good, it's not just me.

#5 @markjaquith
9 years ago

Cannot reproduce on trunk. Set up a test plugin to send me an e-mail with the post ID. Worked fine with an AJAX delete.

#6 @Viper007Bond
9 years ago

  • Keywords needs-patch removed

Hmm, my test plugin that I just wrote does indeed work with AJAX: http://pastebin.ca/898269

However, my original hugely complex plugin does not. Here's the function that uses the hook:

function remove_uploads( $post_ID ) {
	$images = get_post_meta($post_ID, 'mig_images', TRUE);

	foreach ( (array) $images as $image ) {
		@unlink(ABSPATH . $image['path']);
		@unlink(ABSPATH . $image['thumbpath']);
	}

	$thumbnail = get_post_meta($post_ID, 'mig_thumbnail', TRUE);
	if ( !empty($thumbnail) ) @unlink(ABSPATH . get_post_meta($post_ID, 'mig_thumbnail', TRUE));
}

#7 @lloydbudd
8 years ago

  • Keywords needs-patch added

#8 @Jehan
8 years ago

Hi,

I had a similar bug on Wordpress 2.6 where I used delete_post for a plugin. Now it seems, as far as my tests went, that everything is all right with Wordpress 2.7. I don't see the bug anymore. Maybe the people who reported this bug in the first place may confirm if they still have this bug for their code on the latest version?

#9 @Viper007Bond
7 years ago

  • Milestone 2.9 deleted
  • Resolution set to worksforme
  • Status changed from new to closed

We'll assume this is working with WordPress 2.7. Reopen if not.

Note: See TracTickets for help on using tickets.