Filter ‘wp_insert_post_data’, when called? | WordPress.org

On the course I’m doing the code below sets a custom post type ‘note’ status to private but also makes sure if a post has a status of trash this status is not changed so the user can continue to delete posts.

My question is this. The filter hook wp_insert_post_data I thought only got called when data was being inserted but it also seems to be called when a user deletes! Hence the extra condition being added i.e. $data['post_status'] != 'trash'

Even the WP documentation says

Filters slashed post data just before it is inserted into the database.

So why is this hook being called when trying to delete?

    function makeNotePrivate($data) {
        if($data['post_type'] == 'note' AND $data['post_status'] != 'trash') {
            $data['post_status'] = "private";
        }
        return $data;
    }
    add_filter('wp_insert_post_data', 'makeNotePrivate', 10, 2);
  • This topic was modified 6 days, 12 hours ago by GusGF.
  • This topic was modified 6 days, 12 hours ago by GusGF.



Source link