I’ll show a custom – error message.
function ccl($data, $postarr = '') {
if($data['post_status'] == "publish"){
$data['post_status'] = "draft";
echo '<div id="my-custom-error" class="error fade"><p>Publish not allowed</p></div>';
}
return $data;
}
add_filter( 'wp_insert_post_data' , 'ccl' , '99' );
I’ve try many thinks but everytime a success message comes from wordpress that the article published. Can i kill the success message and show my own error message?
tanks for help…
You can’t print an error in a
wp_insert_post_datafilter because the user is redirected immediately after this. The best thing to do is to hook into the redirect filter and add a message variable to the query string (this will overwrite any existing WordPress message).So, add the redirect filter in your
wp_insert_post_datafilter function.Then add a message variable in the redirect filter function.
Finally hook into the
post_updated_messagesfilter and add your message so WordPress knows what to print.