Title: filter before save
Last modified: May 15, 2021

---

# filter before save

 *  Resolved [wpshushu](https://wordpress.org/support/users/wpshushu/)
 * (@wpshushu)
 * [5 years ago](https://wordpress.org/support/topic/filter-before-save/)
 * Hello,
 * I wonder if there is a specific filter hook before a block pattern is saved? 
   Tried [content_save_pre ](https://developer.wordpress.org/reference/hooks/field_no_prefix_save_pre/)
   but it doesn’t apply.
 * Thanks

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [BlockMeister](https://wordpress.org/support/users/blockmeister/)
 * (@blockmeister)
 * [5 years ago](https://wordpress.org/support/topic/filter-before-save/#post-14442388)
 * Hello,
 * As you already concluded yourself in your [other related topic](https://wordpress.org/support/topic/filter-reusable-block-save/)
   on the Developing with WordPress forum, this is not a plugin specific issue.
 * What I gathered is that when the block editor saves a post (via REST API), [`sanitize_post_field`](https://developer.wordpress.org/reference/functions/sanitize_post_field/)
   is called with a `context` parameter value of `raw`. In that context the filter
   you want to use is never called.
    -  This reply was modified 5 years ago by [BlockMeister](https://wordpress.org/support/users/blockmeister/).
 *  Plugin Author [BlockMeister](https://wordpress.org/support/users/blockmeister/)
 * (@blockmeister)
 * [5 years ago](https://wordpress.org/support/topic/filter-before-save/#post-14442450)
 * Follow up: I run an xdebug session and it turned out the sanitization process
   is run in different contexts, including the ‘db’ context where the `content_save_pre`
   filter is actually applied!
 * Could it be your `add_filter` is added too late?
 *  Thread Starter [wpshushu](https://wordpress.org/support/users/wpshushu/)
 * (@wpshushu)
 * [5 years ago](https://wordpress.org/support/topic/filter-before-save/#post-14446282)
 * [@blockmeister](https://wordpress.org/support/users/blockmeister/)
 * I didn’t find the `sanitize_post_field` hook on WP dev docs [https://developer.wordpress.org/?s=sanitize_post_field&post_type%5B%5D=wp-parser-hook](https://developer.wordpress.org/?s=sanitize_post_field&post_type%5B%5D=wp-parser-hook)
 * I set my add_filter priority to `1` and saving still doesn’t trigger my filter.
 *  Plugin Author [BlockMeister](https://wordpress.org/support/users/blockmeister/)
 * (@blockmeister)
 * [5 years ago](https://wordpress.org/support/topic/filter-before-save/#post-14446668)
 * That is not a hook but a function called by the save procedure.
    Inside you’ll
   find the filter you’re using.
 * My advise is to try a debugger (I use Xdebug) to get more insight into the call
   order.
    1. Set a breakpoint after the line where the filter is applied in
        post.php->sanitze_post_field
       and
    2. Set a breakpoint in your filter handler.
 * If breakpoint 1 is hit but 2 wasn’t, then you know your handler isn’t hooked 
   correctly.
 * I hope this helps you a step further in you investigation.
 * As your issue is not related to this plugin, I would kindly ask you, to ask further
   community assistance in the ‘Developing with WordPress Forum’.
    _IMHO the moderator
   there shouldn’t have closed your topic there._
 * Success!
 * Kind regards
 *  Thread Starter [wpshushu](https://wordpress.org/support/users/wpshushu/)
 * (@wpshushu)
 * [5 years ago](https://wordpress.org/support/topic/filter-before-save/#post-14450560)
 * [@blockmeister](https://wordpress.org/support/users/blockmeister/) Thanks for
   the note. Following ticket [https://wordpress.org/support/topic/filter-reusable-block-updates/](https://wordpress.org/support/topic/filter-reusable-block-updates/)

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘filter before save’ is closed to new replies.

 * ![](https://ps.w.org/blockmeister/assets/icon-256x256.png?rev=2598699)
 * [BlockMeister - Block Pattern Builder](https://wordpress.org/plugins/blockmeister/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/blockmeister/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/blockmeister/)
 * [Active Topics](https://wordpress.org/support/plugin/blockmeister/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/blockmeister/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/blockmeister/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [wpshushu](https://wordpress.org/support/users/wpshushu/)
 * Last activity: [5 years ago](https://wordpress.org/support/topic/filter-before-save/#post-14450560)
 * Status: resolved