User Posts Limit

How to set post creation limit for authors?
In the plugin settings set ‘Author’ in role, ‘Posts’ in post type and the limit.

How to make rules that applied on certain post type to limit by the total posts from this post type in the website and apply it on guests as well?
Update the post type:

add_filter( 'upl_query', 'upl_limit_total_posts' );
add_filter( 'upl_rule_limit_current_user_role_check', 'upl_convert_user_role', 10, 2 );

function upl_limit_total_posts( $args ) {
	$post_type = 'post';
	if ( $post_type === $args['post_type'] ) {
		unset( $args['author'] );
	return $args;

function upl_convert_user_role( $check, $i ) {
	$post_type = 'post';
	return $post_type === get_option( 'upl_posts_type' )[ $i ] && ! is_user_logged_in() ? true : $check;

How to make rules that applied on certain post type to limit by posts in specific categories only?
Update the post type and the categories id (make sure users can’t migrate posts from/into unrestricted posts categories):

add_filter( 'upl_query', 'upl_specific_category' );
function upl_specific_category( $args ) {
	$post_type = 'post';
	$category_id = [ '4', '2' ];
	if ( $post_type === $args['post_type'] ) {
		$args['cat'] = $category_id;
	return $args;

How to make rules that applied on certain post type to limit only specific post statuses?
Update the post type and the post statuses (make sure users can’t migrate posts from/into unrestricted post status):

add_filter( 'upl_query', 'upl_specific_post_status' );
function upl_specific_post_status( $args ) {
	$post_type = 'post';
	$post_status = [ 'any' ];
	if ( $post_type === $args['post_type'] ) {
		$args['post_status'] = $post_status;
	return $args;

How to modify the cycle for rules that applied on certain post type?
Update the post type and the cycle:

add_filter( 'upl_query', 'upl_modify_cycle' );
function upl_modify_cycle( $args ) {
	$post_type = 'post';
	$cycle = '3 days ago';
	if ( $post_type === $args['post_type'] ) {
		$args['date_query']['after'] = $cycle;
	return $args;

How to display to the users only the limits that applied on them based on the selected ‘Priority’ option?

add_filter( 'upl_display_prioritized_rules_enabled', '__return_true' );

How to prevent users to exceed the limits by opening multiple ‘new post’ windows?

add_filter( 'upl_skip_auto_draft_enabled', '__return_true' );

How to hide the ‘Add New’ button when posts limit exceeded?

add_filter( 'upl_hide_add_new_button_enabled', '__return_true' );

How to define limits for the total number of multiple post types?
Update the packages’ names and the post types they include:

add_action( 'init', 'upl_create_packages' );
add_action( 'admin_init', 'upl_add_author_support' );
add_filter( 'upl_rule_limit_current_post_type_check', 'upl_convert_post_types', 10, 3 );
add_filter( 'upl_query', 'upl_apply_packages', 10, 2 );

function upl_create_packages() {
	$packages = [ 'Basic Package', 'Premium Package' ];
	foreach ( $packages as $package ) {
		register_post_type( sanitize_key( $package ), [ 'labels' => [ 'name' => $package ] ] );

function upl_add_author_support() {
	$post_types = [ 'post', 'page', 'media' ];
	if ( current_user_can( get_option( 'upl_manage_cap' ) ) ) {
		foreach ( $post_types as $post_type ) {
			add_post_type_support( $post_type, 'author' );

function upl_convert_post_types( $check, $i, $current_post_type ) {
	$packages_types = [
		'Basic Package' => [ 'post', 'page' ],
		'Premium Package' => [ 'post', 'page', 'media' ]
	foreach ( $packages_types as $package => $types ) {
		if ( sanitize_key( $package ) === get_option( 'upl_posts_type' )[ $i ] && in_array( $current_post_type, $types ) ) {
			return true;
	return $check;

function upl_apply_packages( $args, $i ) {
	$packages_types = [
		'Basic Package' => [ 'post', 'page' ],
		'Premium Package' => [ 'post', 'page', 'media' ]
	foreach ( $packages_types as $package => $types ) {
		if ( sanitize_key( $package ) === get_option( 'upl_posts_type' )[ $i ] ) {
			$args['post_type'] = $types;
	return $args;

How to lock the edit of posts for some user role when certain condition are met?
Update the post type, the role, and the condition:

add_filter( 'get_post_metadata', 'upl_lock_posts', 10, 5 );
function upl_lock_posts( $value, $object_id, $meta_key, $single, $meta_type ) {
	$post_type = 'post';
	$role = 'editor';
	$condition = 'active' !== get_user_meta( get_current_user_id(), 'membership_level', true );
	$admin_id = '1';
	return '_edit_lock' === $meta_key && $post_type === get_post_type( $object_id ) && in_array( $role, wp_get_current_user()->roles ) && $condition ? time() . ':' . $admin_id : $value;

How to make rules that apply on certain post type to limit by the posts of the current user instead of the assigned owner (suitable for frontend forms that create the post as admin and are modified only afterwards)?
Update the post type:

add_filter( 'upl_query', 'upl_limit_current_user' );
function upl_limit_current_user( $args ) {
	$post_type = 'post';
	if ( $post_type === $args['post_type'] && ! is_admin() ) {
		$args['author'] = get_current_user_id();
	return $args;

How to allow posts limit per user (via the Users Screen)?

add_filter( 'upl_rule_num_limit', 'upl_user_num_limit', 10, 3 );
add_action( 'show_user_profile', 'upl_add_num_limit_user_data' );
add_action( 'edit_user_profile', 'upl_add_num_limit_user_data' );
add_action( 'personal_options_update', 'upl_save_num_limit_user_data' );
add_action( 'edit_user_profile_update', 'upl_save_num_limit_user_data' );
add_filter( 'manage_users_columns', 'upl_num_limit_user_table' );
add_filter( 'manage_users_custom_column', 'upl_num_limit_user_table_row', 10, 3 );

function upl_user_num_limit( $num_limit, $i, $user ) {
	$user_limit = get_user_meta( $user, 'num_limit', true );
	return '' !== $user_limit ? $user_limit : $num_limit;

function upl_add_num_limit_user_data( $user ) {
	if ( current_user_can( get_option( 'upl_manage_cap', 'manage_options' ) ) ) { ?>
		<h3><?php esc_html_e( 'User Posts Limit', 'user-posts-limit' ); ?></h3>
		<table class="form-table">
				<th><label for="num_limit"><?php esc_html_e( 'Limit', 'user-posts-limit' ); ?></label></th>
					<input type="number" min="0" name="num_limit" value="<?php echo esc_attr( get_user_meta( $user->ID, 'num_limit', true ) ); ?>" class="regular-text" />
					<p class="description"><?php esc_html_e( 'It will override the limit of all the rules that applies on this user', 'user-posts-limit' ); ?></p>
	<?php }

function upl_save_num_limit_user_data( $user_id ) {
	if ( current_user_can( get_option( 'upl_manage_cap', 'manage_options' ) ) ) {
		update_user_meta( $user_id, 'num_limit', sanitize_text_field( $_POST['num_limit'] ) );

function upl_num_limit_user_table( $columns ) {
	$columns['num_limit'] = __( 'Limit', 'user-posts-limit' );
	return $columns;

function upl_num_limit_user_table_row( $row_output, $column_id_attr, $user_id ) {
	return 'num_limit' === $column_id_attr ? get_user_meta( $user_id, 'num_limit', true ) : $row_output;

63 responses to “User Posts Limit”

  1. Hello! How to reset the user limit if the user buys not a product but a membership? Im using paid membership pro. There are three levels of membership – bronze, silver, gold.

  2. Hi! I installed the plugin to use in Multisite.

    Limit configured products to 20 for Shop Manager (Woocommerce), but when I try to 21 product registration, he accuses the following error instead of talking “excedito limit.”

    Error (Warning: Creating default object from empty value in C: \ xampp \ htdocs \ experienciaonlinelojas \ wp-admin \ includes \ post.php on line 713)

  3. Truly awesome plugin.
    What if user has two roles. One role max 10. Another max 0. How do I display the capability (max) for only the role with the ability? Thanks!

    • Hi Mark,
      Please redownload the plugin and then use the code from the ‘How to display in the dashboard only the most permissive limit’ section in the docs

  4. Hello, it would be great if every time a limitation is created for a different user role, it would be added to a list, where said limitation rule could be edited or deleted, just like the Limit Post plugin had it, which has been outdated for 5 years. and it was fantastic.

    Greetings and thank you very much for your contribution, you are great.

  5. Hi!
    How can I unrestrict multiple users in one function?
    like the first example but with multiple ids?

    Thank you very much

  6. Hi Condless,
    Thanks for creating this plugin. It’s very useful.
    I tried to use “[upl_hide type=”post”][/upl_hide]” to hide some contents, when the login-in user’s post exceeds the limit.
    However, nomatter if it exceeds the limit or not, it always hides the contents which is wrapped in.

    Any comment?

    • Well, actually i did some workaround, by updating the option based on the user_id, altough it is not really an effective solution by using the plugin.

      Hope you can make the feature to change the limit based on the user applied on the future, and i’m ready to pay for it too, thanks for your reply.

  7. Is the post limit for active posts? I am using Geodirectory and want to have post limits for any custom post type (listing). So a premium user role would be limited to 10 active posts. If they have 10 posts, and delete one of these, or make it inactive, it would reduce active posts to 9, which is below their limit. This would allow them to create a new post. Possible?

    • Hi Chris,
      See the section: ‘How to make rules that applied on certain post type to limit specific post status?’
      You will also have to make sure the users can’t restore deleted/inactive listing.

  8. Can the post count include the sum of posts for all custom post types? I have 3 custom post types and want to allow a maximum number of active posts, but this could be any post type.
    #active posts = active CPT1 + active CPT2 + active CPT3
    #active posts <= post limit (set by role)

    • Please try the following code (update the CPT slugs):
      add_filter( 'upl_query', 'upl_multiple_post_types' );
      function upl_multiple_post_types( $args ) {
      $args['post_type'] = [ 'CPT1', 'CPT2', 'CPT3' ];
      return $args;

    • Hello,
      Thank you for providing this code. I am just now giving it a try. I added this code and changed CPT1, CPT2 and CPT3 to the slugs for the three CPT’s. When I go to the UPL settings to limit the post for a user role, what post type do I select in the list?
      Thank you.

    • Hi Condless,

      Thank you for the reply. I am still not clear on how to do this.

      In the User Posts Limit settings, there is a list of 23 types of posts in the dropdown. These are: Posts, Pages, Media, Navigation Menu Items, Custom CSS, Changesets, oEmbed Responses, User Requests, Reusable blocks, Templates, Type blocks, Templates, Types Groups, Types User Groups, Types Term Groups, Elements, Views, Content Templates, Posts, Businesses for Sale, Listings, Listings (1), Listings (2), WordPress Archives Blocks. I notice that “Posts” is listed twice in the dropdown.

      The three that I used to test are CPT1 = listing, CPT2 = listing-1 and CPT3 = listing-2.

      Which one do I select? I do not see one that has a name that is created by UPL.

      Is it possible to have UPL create a new Post Type name in the list that can be defined in UPL settings. Like Premium UPL = CPT1 + CPT2 + CPT3. The name Premium UPL would show in the dropdown in the selection for the User Role settings. Would be great to be able to create more than one of these UPL Categories – Premium UPL, Standard UPL, etc. to represent different package levels for user roles.

      Thanks again for the help.

    • Hi Condless,

      Adding to my last reply.

      The reason for this request, is that I am working on a membership directory site. I want to offer multiple membership levels.

      Premium Broker 10 Listings
      Premium Broker 20 Listings
      Seller Single Listing

      These roles will have access to certain CPT’s (which I can control using Paid Membership Pro. I want to have these packages limit the posts available to different CPT’s.

      I hope that this helps to clarify the request.


    • Hello. Adding a comment to the two replies sent earlier. I tested the UPL plugin with the three CPT’s – listing, listing-1 and listing-2. I see that they all work independently, and the error message displays if the post limit is exceeded for any one of the post types. I was hoping that the post limit could be set for a sum of the three CPT’s, and the limit would be compared to the sum.

      Please let me know if this can be done.

      Ideally, there would be separate limits for different CPT’s, and these could be used for different user roles independently.

      If this can be performed as a custom solution, please email if better to provide details.

      Thank you.

    • Hi Kieran,
      It can work as long as the form is producing posts/pages or any other post type, try searching the post type in the ‘Type’ option (on the plugin settings).

  9. Thank you for the fast reply, I really appreciate it.

    The plugin is working perfectly on the backend. If I go over the post limit I get this message ” You have created the maximum amount of Review pages for this plan ”

    But, If I use the ACF Extended Front-End form, it doesn’t limit me and creates the post.

    When submitting the Front-End form, I am logged into the correct user role.

  10. I am using User Posts Limit plugin on my website. Anyone can register on the website and I have set a limit on the number of images they can add. No matter what I choose in the notifications section when using the plugin, it does not give the notification properly. The full screen option does not work either. How can I fix these?


    • Maybe you misunderstood me. There are no problems with translation and writing. Two of the notification options do not work when I set an image adding limit. Notifications do not appear on the image upload page.

    • Hi, the plugin’s built-in notifications aren’t compatible with image upload, you can translate the current message (which comes from WordPress) as per as your needs.

  11. Hello, while adding the media upload limit in the plugin, I chose the empty notification type. This type of notification returns ‘wp_insert_post_empty_content’ in post.php file. This warning does not comply with the media upload limit. Will you make development about it and add a warning in the plugin?

    • Hi,
      Please wrtie your message in the ‘text’ option, choose ’embed’ in the Notification option, and add this code into your theme’s functions.php file:
      add_filter( 'gettext', 'upl_media_notice', 10, 3 );
      function upl_media_notice( $translated_text, $untranslated_text, $domain ) {
      return is_admin() && 'Content, title, and excerpt are empty.' == $untranslated_text ? get_option( 'upl_message' ) : $translated_text;

    • You did what I did by adding a function to the functions.php file. Again, the error message in post.php changes. This error message may also appear in different error states. Are you considering adding an error message field to the plugin instead?

    • Hi,
      You mean you need different error message for the image upload limit error? you can change this line in the code:
      get_option( 'upl_message' )
      to this:
      'Image upload limit'

  12. Thank you for your plugin! I use it in my site but i have one problem, I use multiple roles with multiple restriction and I need to show restrictions for the highest role or most permissive limit. But with your additional code I can see only 1 restriction even if I have it 10 for highest role. So can I somehow show for user restrictions by roles? Or all permissive limit instead of 1?

Leave a Reply

Your email address will not be published.