• Resolved wpshushu

    (@wpshushu)


    In WP 5.7.1, hooking into content_save_pre

    
    add_filter('content_save_pre', function ($content) {
        error_log($content);
        return $content;
    });
    

    Each saves in the post editor results in two records in the error log. It appears that this filter is being called twice. Is this a bug?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    No, it’s actually quite common (though little known) for hooks to fire more than once per request. Typically there is no ill effect from redoing the same things all over again other than being redundant. In cases where it’s important a callback only execute once, the callback can remove itself from the filter stack after the first pass through. It’ll be back in place for the next request.

    Thread Starter wpshushu

    (@wpshushu)

    @bcworkz Thanks for the clarification.

    • This reply was modified 3 years, 7 months ago by wpshushu.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘content_save_pre called twice’ is closed to new replies.