Support » Plugins and Hacks » Hacks » How to break wp_insert_post operation with an error

  • I have researched on this a lot but mostly getting stuff about applying hacks etc. I have added a new condition in wp_insert_post as below which checks for a particular title and stops the post from being inserted to the database if the condition is met.

    if ( empty($post_type) )
    		$post_type = 'post';
    
    	if ( empty($post_status) )
    		$post_status = 'draft';
    
    	if ($post_title == 'XYZ') {
       return  new WP_Error('broke', __("I've fallen and can't get up"));
    }

    Hence if the title of my post is XYZ then the post will not be published. It works fine but I still get the Post Published message. I am looking to replace this message with an error message. Anyone can help me out with this?

    Thanks

  • The topic ‘How to break wp_insert_post operation with an error’ is closed to new replies.