I want to do a regex match to each post before it gets published, and if the regex fails to match, delete the post entirely, what hook should I use?
2 Answers
You need this filter:
function add_myself($content){
return $content." myself";
}
add_filter('content_save_pre','add_myself');
Found the answer here: https://stackoverflow.com/a/4147860/982517
-
This doesn't cover how to delete post though, which is probably tricky to do while it is saving.– RarstDec 13, 2013 at 15:28
You could do something like this. I tested it and it worked. I don't know how stable it is, so you should do some testing for yourself:
function rsp_remove_post_while_saving($post_id) {
remove_action( 'save_post', 'rsp_remove_post_while_saving', 13, 2 );
wp_trash_post($post_id);
}
function add_myself($content){
// if your post is not valid {
add_action( 'save_post', 'rsp_remove_post_while_saving' );
// }
}
add_filter('content_save_pre','add_myself');