Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function wp_scotch(){
- global $wpdb;
- $post_id = 1000;//place any value here
- $meta = array("thumb"=>"delete_target.php");
- $file = "../../tralalal.txt";
- //simulate the file value is taken via get_attached_file
- if ( $file && 0 !== strpos( $file, '/' ) && ! preg_match( '|^.:\\\|', $file ) && ( ( $uploads = wp_get_upload_dir() ) && false === $uploads['error'] ) ) {
- $file = $uploads['basedir'] . "/$file";
- }
- $uploadpath = wp_get_upload_dir();
- $deleted = true;
- if ( ! empty( $meta['thumb'] ) ) {
- // Don't delete the thumb if another attachment uses it.
- 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 ) ) ) {
- $thumbfile = str_replace( basename( $file ), $meta['thumb'], $file );
- if ( ! empty( $thumbfile ) ) {
- $thumbfile = path_join( $uploadpath['basedir'], $thumbfile );
- $thumbdir = path_join( $uploadpath['basedir'], dirname( $file ) );
- if ( ! wp_delete_file_from_directory( $thumbfile, $thumbdir ) ) {
- $deleted = false;
- }
- }
- }
- }
- }
- add_action("init", "wp_scotch");
Add Comment
Please, Sign In to add comment