Site icon Hip-Hop Website Design and Development

delete_post hook – deleting a number of gadgets

I’m utilizing delete_post hook.

add_action('delete_post', array($this, 'remove_audio_file')); // delete publish occasion

(Utilizing it inside the category).

Once I delete a single publish I’ve no downside retrieving its ID.

international $publish;

Nevertheless, once I delete a number of posts (2 or extra) $publish turns into NULL.
Are you able to advise why is that / what I’m doing fallacious ?

EDIT:

perform remove_audio_file() {
        international $publish;
        if ($publish != NULL) {
           $unique_id = get_post_meta($post->ID, 'ecpt_unique_id', true);
            $username = get_userdata($post->post_author)->user_login;
            $uploadrr = new bt_uploader();
            $dirPath = $uploadrr->audio_folder() . $username . '/' . $unique_id;
            if (is_dir($dirPath)) {
                foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirPath, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $path) {
                    $path->isFile() ? unlink($path->getPathname()) : rmdir($path->getPathname());
                }
            } 
        }
    }