TypeRocket/typerocket

PostType::saveTitleAs hook gets called when post gets deleted

jdoubleu opened this issue · 1 comments

When I delete a post, the PostType::saveTitleAs hook gets called. This is because "deleting" the post actually just moves it to the "trash", which requires a post update.

See the stack trace below:

posttype-mycustom.php:34, tk\register\posttype\pricelist\{closure:/path/to/posttype-mycustom.php:33-35}()
Registry.php:278, TypeRocket\Register\Registry::TypeRocket\Register\{closure:/path/to/plugin/typerocket-pro-v5/typerocket/vendor/typerocket/core/src/Register/Registry.php:264-284}()
class-wp-hook.php:294, WP_Hook->apply_filters()
class-wp-hook.php:316, WP_Hook->do_action()
plugin.php:484, do_action()
post.php:4384, wp_insert_post()
post.php:4486, wp_update_post()
post.php:3309, wp_trash_post()
post.php:260, {main}()

I think at this point, calling that hook, is unnecessary. First of all, the post already has a title at that point and secondly the intent is to remove the post.

You might be able to catch this case inside the hook by checking the post object's post_status ( == "trash") property.