admin管理员组

文章数量:1415484

I'm building a plugin that registers a custom post type. I'm looking for a way to limit the number of these types of posts at which point the user can no longer 'Add New' posts to this post type.

Is there any particular filter that would allow me to modify the add/edit screen accordingly, or perhaps something else you can think of?

Any help would be greatly appreciated.

-- Update

Just to clarify why I've chosen post types over options, however if you still think it's worthwhile to look at options let me know :).

Well the idea is that the plugin is freemium, and paid users will have the chance to create as many as they want, however free users will be restricted. On the paid side, a post type makes sense due to the repetition of structure.

Each post will have a lot of meta data stored in it. Inherently, using an options page would in my mind be straying away from the 'creatable' nature of a post type wherein users can easily add/edit/delete them.

I'm building a plugin that registers a custom post type. I'm looking for a way to limit the number of these types of posts at which point the user can no longer 'Add New' posts to this post type.

Is there any particular filter that would allow me to modify the add/edit screen accordingly, or perhaps something else you can think of?

Any help would be greatly appreciated.

-- Update

Just to clarify why I've chosen post types over options, however if you still think it's worthwhile to look at options let me know :).

Well the idea is that the plugin is freemium, and paid users will have the chance to create as many as they want, however free users will be restricted. On the paid side, a post type makes sense due to the repetition of structure.

Each post will have a lot of meta data stored in it. Inherently, using an options page would in my mind be straying away from the 'creatable' nature of a post type wherein users can easily add/edit/delete them.

Share Improve this question edited Sep 14, 2014 at 18:37 AliBaba asked Sep 14, 2014 at 18:20 AliBabaAliBaba 12 bronze badges 4
  • You mean you want to restrict how many posts, aka the user can create 5 'pages' but not 6? Or do you mean in general? aka users can create any pages they want so long as in total they are 5 or less? – Tom J Nowell Commented Sep 14, 2014 at 18:24
  • @TomJNowell I mean that users can create up to a maximum number in total for the custom post type, so let's say 5. Once the user creates 5 then they can't add another until they delete an existing one (5 or less at any one time). – AliBaba Commented Sep 14, 2014 at 18:27
  • Well the idea is that the plugin is freemium, and paid users will have the chance to create as many as they want, however free users will be restricted. On the paid side, a post type makes sense due to the repetition of structure. – AliBaba Commented Sep 14, 2014 at 18:33
  • 1 So it is not a per user restriction it is a per install restriction? What's to stop the user removing the check in the code? – Tom J Nowell Commented Sep 14, 2014 at 18:39
Add a comment  | 

1 Answer 1

Reset to default 0

In order to enforce your post limitation until the user pays the license, I suppose you should check if limit is reached when:

  1. user clicks on "add new"
  2. user displays list of current entries

AFAIK, the way to do that is to use the relevant hooks but that depends a bit of the user experience you want to create.

For example, if you use the action hook publish_post, you could force the "draft" status of the post until the user has paid.

See the full action hooks list here.

本文标签: admin menuLimit number of posts under a post type