我正在使用delete_post
钩
add_action(\'delete_post\', array($this, \'remove_audio_file\')); // delete post event
(在类内使用)。
当我删除一篇文章时,检索它的ID没有问题。
global $post;
但是,当我删除多篇帖子时(2篇或更多)
$post
成为
NULL
.你能告诉我为什么我做错了吗?
编辑:
function remove_audio_file() {
global $post;
if ($post != 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());
}
}
}
}