WordPress restrict access to custom post types for user roles

If you’re creating custom post types to wordpress site sometimes you need to restrict access to custom post types from back-end to other users. For a example if you created the custom post type named “Campaigns” and you want to enable that “Campaigns” page from admin panel only administrator user role.To do this I’ll show very simple method by explaining from start to end.Hope every users can understand easily.
Let’s start from adding custom post types named “Campaigns”.

If we added above code all users can see it after them logged into their dashboard.Subscribers can view that too. 🙂
To restrict access to custom post type you can send parameters via “capability_type” as following.

Final fully code is like this.

Then this campaign page viewable for administrator user privileges only.
Hope this would be help.Comment here if you have any problems regarding this.