I believe you can just check if the post status is trash
, and if so, don’t run the rest of your code. E.g. (PS: I intentionally used strict comparison, i.e. using ===
as in $pagenow === 'post.php'
)
function post_extra_save( $post_id, $post ) {
global $pagenow;
if ($pagenow === 'post.php' && 'trash' !== $post->post_status) {
... your code.
}
}
Alternatively, run your code only if the post status is publish
or that it’s in one of a whitelisted/allowed statuses list. E.g.
function post_extra_save( $post_id, $post ) {
global $pagenow;
$allowed_statuses = array( 'publish', 'private' ); // list of allowed post statuses
if ($pagenow === 'post.php' && in_array( $post->post_status, $allowed_statuses )) {
... your code.
}
}