我正在尝试创建一个插件,该插件将通过管理面板(wp admin/edit tags.php)从数据库中删除有关删除自定义帖子(sp\\U场馆)的图片和其他信息
在插件中,我使用它来捕捉事件:
add_action( \'delete_post\', \'kg_delete_post\' );
function kg_delete_post($postId) {
$post = get_post($postId);
if ($post->post_type != \'attachment\') {
return false;
}
$url = str_replace($dirs[\'baseurl\'],\'\',$post->guid);
$urlParts = explode("/",$url);
$numberOfParts = sizeof($urlParts) - 1;
$dirs = wp_upload_dir();
$fileNameParts = explode(".", $urlParts[$numberOfParts]);
$fileName = str_replace(\'.\' . end($fileNameParts), \'\', $urlParts[$numberOfParts]) . "-*." . end($fileNameParts);
$path =$dirs[\'basedir\'] ."/". $urlParts[$numberOfParts-2] . "/" . $urlParts[$numberOfParts-1] . "/";
$fullPath = $path . $urlParts[$numberOfParts];
$fullPathSearch = $path . $fileName;
@unlink($fullPath);
foreach (glob($fullPathSearch) as $filename) {
@unlink($path . $filename);
}
}
它适用于:
wp_delete_post($Id, true)
但看起来通过管理面板删除的事件不一样。
我应该用什么来让它工作?非常感谢。