The after_delete_post
Hook in WPFTS
The after_delete_post
hook is a standard WordPress hook that fires after a post has been deleted. WPFTS uses this hook to remove the deleted post’s data from the search index.
What WPFTS Does When after_delete_post
is Called:
- Calling
wpfts_post_reindex()
: The plugin calls thewpfts_post_reindex()
function with the ID of the deleted post and the flag$is_force_remove = true
. This results in the removal of the post’s entry from thewpftsi_index
table and all related data from other index tables.
Important Functions Involved in Handling after_delete_post
:
wpfts_post_reindex($post_id, true)
How to Use This in Addon Development:
Addon developers usually don’t need to interact with this hook directly. WPFTS automatically handles the removal of posts from the index. However, if your addon adds data to the index that is related to posts, you can use this hook to clean up your data when a post is deleted.
Additional Notes:
- Data removal from the index happens synchronously with the post deletion, ensuring the index remains up-to-date.
- The
wpfts_post_reindex()
function is also used to update the index when a post is saved (with the flag$is_force_remove = false
).
This hook demonstrates how WPFTS maintains the accuracy of the search index when posts are deleted.