How to trap “Publish” button to check for meta box validation?

Rather than trying to interfere with the button operation and doing validation in jQuery or javascript, I find it easier to hook the save_post action and do my validation in php (checking if certain post_meta exist or are correct), then if things don’t check out, you can set the post status back to “pending”, which in effect overrides the Publish button. The page simply loads back up (having been saved), but they have to correct their errors before “publishing” can be done.

Leave a Comment