There are two problems with your code snippet:
1) Comparison
The first problem is in this line:
if( $post_id === $frontpage || $post_id === $blogpage ) {
where you’re strictly comparing int
with string
.
Notice that ===
comparison will only return TRUE
if both variables are of the same type and have the same value.
Try this instead:
if( $post_id == $frontpage || $post_id == $blogpage ) {
where ==
will perform a type conversion, or simply use the (int)
typecasting:
if( $post_id === (int) $frontpage || $post_id === (int) $blogpage ) {
You could also use intval()
.
2) Priority
The second problem is the callback priority. You should run your callbacks earlier, for example, with priority 1
instead of the default 10
:
add_action( 'wp_trash_post', 'tcb_page_delete_check', 1 );
add_action( 'before_delete_post', 'tcb_page_delete_check', 1 );
Hope this helps.