0

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?

0

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. – Rarst Dec 13 '13 at 15:28
0

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');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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