Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
that's interesting, thanks for looking into it. I had found the {$field_no_prefix}_save_pre but I wasn't sure how it worked. Thanks! –  Tom Oakley Apr 1 at 22:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.