What to use instead of the content_save_pre filter?

I read on Adam Brown’s website that the content_save_pre filter is depreciated as of WordPress 3.8 – is this true? It doesn’t say it on the official codex page for content_save_pre so I’m skeptical. If it is depreciated, which filter would I use to edit the content after I press Publish/Update but before it writes it to the database?

Related posts

Leave a Reply

1 comment

  1. What Adam Brown’s site says is that the hook no longer appears in 3.8. I greped a 3.9 and found:

    bash-4.2# grep -Rni 'content_save_pre' *
    wp-includes/kses.php:1327: * The wp_filter_post_kses() function is added to the 'content_save_pre',
    wp-includes/kses.php:1344:      add_filter('content_save_pre', 'wp_filter_post_kses');
    wp-includes/kses.php:1370:      remove_filter('content_save_pre', 'wp_filter_post_kses');
    wp-includes/default-filters.php:89:foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content' ) as $filter ) {
    

    Interestingly the filter is not applied anywhere, but is still used by the Core in several places. That would be a big oversight. If you look around a bit more you will find this:

    http://adambrown.info/p/wp_hooks/hook/{$field_no_prefix}_save_pre
    

    So grep again a bit less rigidly and right at the bottom:

    wp-includes/post.php:2010:                      $value = apply_filters("{$field_no_prefix}_save_pre", $value);
    

    It is a dynamic filter, which I assume is why Adam Brown lost track. This is confirmed by the Codex itself:

    The “content_save_pre” filter is part of a group of dynamic filters that allow you to sanitize content prior to saving it in the
    database. This filter runs in wp-admin.

    http://codex.wordpress.org/Plugin_API/Filter_Reference/content_save_pre
    

    I believe that that is the hook you are looking for. In other words, content_save_pre should still work. It is generated dynamically but should still work.