Guest User

Untitled

a guest
Jan 21st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. <?php
  2.  
  3. function wp_scotch(){
  4.  
  5. global $wpdb;
  6.  
  7. $post_id = 1000;//place any value here
  8. $meta = array("thumb"=>"delete_target.php");
  9. $file = "../../tralalal.txt";
  10.  
  11. //simulate the file value is taken via get_attached_file
  12. if ( $file && 0 !== strpos( $file, '/' ) && ! preg_match( '|^.:\\\|', $file ) && ( ( $uploads = wp_get_upload_dir() ) && false === $uploads['error'] ) ) {
  13. $file = $uploads['basedir'] . "/$file";
  14. }
  15.  
  16. $uploadpath = wp_get_upload_dir();
  17. $deleted = true;
  18.  
  19. if ( ! empty( $meta['thumb'] ) ) {
  20. // Don't delete the thumb if another attachment uses it.
  21. if ( ! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' . $wpdb->esc_like( $meta['thumb'] ) . '%', $post_id ) ) ) {
  22. $thumbfile = str_replace( basename( $file ), $meta['thumb'], $file );
  23. if ( ! empty( $thumbfile ) ) {
  24. $thumbfile = path_join( $uploadpath['basedir'], $thumbfile );
  25. $thumbdir = path_join( $uploadpath['basedir'], dirname( $file ) );
  26.  
  27. if ( ! wp_delete_file_from_directory( $thumbfile, $thumbdir ) ) {
  28. $deleted = false;
  29. }
  30. }
  31. }
  32. }
  33. }
  34.  
  35. add_action("init", "wp_scotch");
Add Comment
Please, Sign In to add comment