pre_delete_post
钩子过滤器是否为立柱deletion 应该发生。因此回调函数必须返回布尔值:true
- 是否继续删除,false
- 如果没有。
pre_trash_post
钩子过滤器是否为立柱trashing 应该发生。因此回调函数必须返回布尔值:true
- 是否继续进行垃圾清理,false
- 如果没有。
add_filter( \'pre_delete_post\', \'filter_function_name\', 10, 2 );
add_filter( \'pre_trash_post\', \'filter_function_name\', 10, 2 );
function filter_function_name( $delete, $post ) {
// You have a field with user IDs for the post, get them as array of IDs
$authors = array(1, 2, 3);
// Get current user ID, who attempts to delete the post
$current_user_ID = get_current_user_id();
// make a check if the current user ID is among the co-authors IDs
if ( !in_array( $current_user_ID, $authors ) ) {
// If so, return false to prevent post deletion
return false;
}
// else do nothing, and return default value
return $delete;
}