Hello,
As you already concluded yourself in your other related topic 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 is called with a context parameter value of raw. In that context the filter you want to use is never called.
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?
@blockmeister
I didn’t find the sanitize_post_field hook on WP dev docs https://developer.ww.wp.xz.cn/?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.
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.
- Set a breakpoint after the line where the filter is applied in
post.php->sanitze_post_field and
- 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