PHP not giving perfect output

In wordpress Im using function.php for achieving 1450 wordcount for free user using this script

 //How to Set a Minimum Length for WordPress Posts
 function display_short_error_message($messages)
   global $post;
   $content = $post->post_content;
   if (str_word_count($content) < 1500 ) {
     $error_message = 'Post Should be at Least 1500 Words';
     add_settings_error('post_short_error', '', $error_message, 'error');
     settings_errors( 'post_short_error' );
     $post->post_status = 'draft';
   return $messages;
 add_action('post_updated_messages', 'display_short_error_message');

but the problemm is its it triggers error & action &mAKE PROST DRAFT

But i cant find decent customization like draft post,private post error display in professional form