TypeRocket / typerocket

TypeRocket is a highly integrated MVC WordPress framework with beautiful UI components for the modern developer.
https://typerocket.com
454 stars 62 forks source link

PostType::saveTitleAs hook gets called when post gets deleted #233

Closed jdoubleu closed 3 years ago

jdoubleu commented 3 years ago

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.

kevindees commented 3 years ago

@jdoubleu addressed https://github.com/TypeRocket/core/commit/a2ad515ae7f234a97dfe3a2338849ca59f4c19a7 and https://github.com/TypeRocket/core/commit/388e1e6415caa50860502f15e36064191570ae5f