The problem is that is_user_logged_in
is a pluggable function, and is therefore loaded after this plugin logic is called. The solution is to make sure that you don't call this too early. This can be done by wrapping this logic in a function and calling it from 'init'
function rizwan_insert_coupons()
{
if(isset($_POST['save_coupons']) and $_POST['save_coupons']=='yes'){
//lots of stuff
/*
* Inserting New Coupon as Post
*/
$post = array();
$post['post_status'] = 'publish';
$post['post_type'] = 'coupons';
$post['post_title'] = $title;
$post['post_content'] = $description;
$post_id = wp_insert_post( $post );
//lots more stuff
}
}
add_action('init', 'rizwan_inert_coupons');