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 still haven't figured this out yet. Is this the right way? I tried $_POST['content'] = "nothing" and $_POST['content'] = 0 neither work for me. I'm using following way

function changeContent() {
     $_POST['content'] = "nothing"; 
}
add_action('publish_post', 'changeContent');

I want to change the content before it's written into the database.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You might check out the content_edit_pre filter.

Your example would then look like this:

function wpse89725_pre_edit_content( $content, $post_id ) {
   $content = "nothing";
   return $content;
}
add_filter( 'content_edit_pre', 'wpse89725_pre_edit_content', 10, 2 );

You can read more about this filter in the Codex:

https://codex.wordpress.org/Plugin_API/Filter_Reference/content_edit_pre

Edit:

You can also try the edit_post_content filter:

add_filter( 'edit_post_content', 'my_pre_edit_content', 10, 2 );

Since we have in the file /wp-includes/post.php these lines:

 $value = apply_filters("edit_{$field}", $value, $post_id);
 // Old school
 $value = apply_filters("{$field_no_prefix}_edit_pre", $value, $post_id);

both of these filters should work, but the filters *_edit_pre seems to be on the way out and replaced by edit_*.

share|improve this answer
    
thanks! but here it says content_edit_pre is depreciated in version 3.5? I tried a few related ones, but they are all said to be depreciated? so strange.. adambrown.info/p/wp_hooks/hook/content_edit_pre –  Arch1tect Mar 7 '13 at 2:47
    
It's a dynamic hook: $value = apply_filters("{$field_no_prefix}_edit_pre", $value, $post_id); so that might be the reason why the adambrown-scraper can't find it. It works on my 3.5.1 install. –  birgire Mar 7 '13 at 2:52
    
I updated the answer ;-) –  birgire Mar 7 '13 at 3:06
    
Thanks a lot~ I tried both and both work, and I'll use the latter. I chose your answer already, btw do you have any idea why intercepting post value won't work? $_POST['content'] = "nothing" –  Arch1tect Mar 7 '13 at 3:10
    
great thanks - I think the post has already been saved when you call the publish_post action. Your example might work with the init hook and the $_POST['post_content'] but I don't think it's ideal to mess with the $_POST variable ;-) –  birgire Mar 7 '13 at 3:24

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.