这个wp_delete_post()
有pre_delete_post
在删除之前进行筛选,您可以使用它来防止自定义帖子类型被删除。
function prevent_cpt_delete( $delete, $post, $force_delete ) {
// Is it my post type someone is trying to delete?
if ( \'my_post_type\' === $post->post_type && ! $force_delete ) {
// Try to trash the cpt instead
return wp_trash_post( $post->ID ); // returns (WP_Post|false|null) Post data on success, false or null on failure.
}
return $delete;
}
add_filter(\'pre_delete_post\', \'prevent_cpt_delete\', 10, 3);