This is completely untested but I think the concept is good, and good idea too though I’d have an angry mob with pitchforks to face.
- Set a marker for your post when the post is previewed. You can save
it in either$wpdb->options
or$wpdb->postmeta
. I haven’t
quite decided which would be better, and it probably depends on
details of the implementation. (But probably$wpdb->postmeta
). - Check that marker before you allow a post to be published.
So…
function set_preview_marker_wpse_99671() {
if (is_preview()) {
// set the marker
}
}
add_action('pre_get_posts','set_preview_marker_wpse_99671');
Then check the key before you allow publishing.
// code shamelessly stolen from another answer
// http://wordpress.stackexchange.com/questions/96762/how-to-make-a-meta-box-field-a-requirement/96767#96767
function req_meta_wpse_96762($data){
$allow_pending = false;
if (isset($_POST['meta'])) {
foreach ($_POST['meta'] as $v) {
if ('your_required_key' === $v['key'] && !empty($v['value'])) {
$allow_pending = true;
}
}
}
if (false === $allow_pending) {
$data['post_status'] = 'draft';
}
return $data;
}
add_action('wp_insert_post_data','req_meta_wpse_96762');
You might want to unset that key when the post is published to force the preview check again if it is edited.