Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter gregzimerman

    (@gregzimerman)

    Ha, sorry to debunk your theories!

    I’ll try the admin-ajax.php/admin-post.php methods tonight. It’s a great idea to try. I’m less familiar with constructing those requests, but I should be able to figure it out!

    And yes, I’m tailing my error logs while I test. I haven’t seen related warnings/errors yet, but hopefully something will bubble up with these new methods, or maybe it will just work. 🙂

    Thanks again for all the advice — I will let you know how it goes!

    Thread Starter gregzimerman

    (@gregzimerman)

    Thanks, it’s good to confirm that the functions above should be deleting the source files. Neither the originals or the attachments are being deleted. I’m using $force_delete=true if that has any significance on it.

    I want to debug pathing next. I know deletion works from a WordPress perspective since my CMS does it, but something different is happening on the command line or PHP script.

    And understood about wp-load.php. My code here was never meant for distribution, just the fastest way to get access to WP functionality for short term use scripts. I ran into a few errors myself when I first tried it, but I was able to resolve them.

    Thread Starter gregzimerman

    (@gregzimerman)

    @bcworkz Thanks for your response and the tag. I agree 100% on the need for granular control, but it’s crazy how hard I need to fight with WordPress to do this fairly normal administrative task, which I still haven’t been able to automate.

    I’ve moved on from WP CLI to write a simple script of my own, bootstrapping WordPress with “require_once( ‘wp-load.php’ );”, such that I can successfully run all kinds of WordPress queries and functions from a PHP script. But no matter what I try with wp_delete_post and wp_delete_attachment, the attachment post and it’s metadata are removed from the DB, but the file and it’s thumbnails are NOT removed from storage (S3).

    So there’s really no way high level way to delete a bunch of media files, given the IDs of their attachment posts? Again, I just need to replicate the functionality of the “delete permanently” link from the CMS (which obviously exists), but for 1,000,000+ records. I’m an engineer so I can handle some code, but I’m new to hands-on WP development — is there a hook or action that might help me here? I see do_action(‘before_delete_post’) mentioned as a possibility, but haven’t gotten that working yet either. I feel like I must be missing something obvious. Thanks in advance!

    PS: I realized I hadn’t mentioned, but my site is running on WordPress v4.5.2 and uses the plugins Amazon S3 and CloudFront v0.6.1 & Amazon Web Services v0.1.

    Thread Starter gregzimerman

    (@gregzimerman)

    As an update, I’ve been able to write a script using the WordPress CLI as well as one using WordPress API and wp_delete_post. Both remove the post record only, but not the attached files or thumbnails. Again, clicking “delete permanently” from the CMS does delete those thumbnails.

    The big question is — What does “delete permanently” from post.php fire that the WP CLI and standalone script don’t?

    I could also write a custom script including wp_delete_post and wp_delete_attachment? The confusing part is that wp_delete_post should call wp_delete_attachment when post_type=”attachment”, which is true here, but it’s not clear if that’s happening.

    Any ideas?

Viewing 4 replies - 1 through 4 (of 4 total)