Hello, it sounds like you need these features:
1. The ability to store a number value in each User's profile, representing the number of post "credits".
2. The ability to test whether or not a User has any remaining credits, and allow them to create a new post using Forms based on whether or not they have any remaining credits
3. The ability for Users to create posts from the front-end of the site using Forms
4. The ability to automatically subtract one "credit" each time the User posts a new post with Forms
Features 1, 2, and 3 are possible in Toolset without any extra custom coding, but Feature #4 requires a small custom code snippet I can help you implement.
First, you must create a number custom field in User Profiles. For example, I would call this field something like "credits". You can create this field in Toolset > Custom Fields > User Fields tab. You should probably set a default value of 0 here, so new Users have no credits.
Next, you need a new post Form that allows your Users to submit posts from the front-end of the site. You'll create that Form in Toolset > Post Forms.
Once the Form has been created, you need to display it to some Users conditionally, based on the value of that User's "credits" field. You can use Toolset's conditional block to create a condition that compares the current logged-in User's "credits" field to see if it is greater than or equal to a static value of 1. Since it is not possible to select User fields in the conditional builder yet, you must use the Advanced Editor to edit the conditional terms.
The correct conditional syntax looks like this:
( ( '[types usermeta="credits" output="raw" current_user="true"][/types]' gte '1' ) )
See the screenshot here. You would replace credits with the slug of your custom number field, if it is not "credits".
Then you will drag a Form block into that conditional block, so that the Form is only displayed if the condition is true. If the field is not greater than or equal to 1, no Form will be displayed.
https://toolset.com/course-lesson/using-toolset-conditional-block/
Finally, you need to implement a custom code snippet to automatically decrement the custom field value whenever this Form is submitted successfully. We have a PHP API cred_save_data that can be used for this purpose. You can create a new snippet in Toolset > Settings > Custom Code, or add it to your child theme's functions.php file. Here is an example you can customize for your site:
// automatically subtract 1 from the current user's credits field
// when a new post form is submitted
// https://toolset.com/forums/topic/allow-users-to-input-a-set-number-of-posts-via-user-form/
add_action('cred_save_data', 'tssupp_decrement_credits',10,2);
function tssupp_decrement_credits($post_id, $form_data) {
// edit these values as needed
$slug = 'credits';
$forms = array( 123 );
// do not edit below this line
if ( in_array( $form_data['id'], $forms ) )
{
$user = wp_get_current_user();
$credits = get_user_meta( $user->ID, 'wpcf-' . $slug, true );
if( $credits >= 1 )
{
$credits = $credits-1;
update_user_meta( $user->ID, 'wpcf-' . $slug, $credits );
}
}
}
Where the code says "edit these values as needed", you should replace credits with the slug of the custom field you created for the User Profile. You should also replace 123 with the numeric ID of the new post Form which your Users will use to create new posts. If there are multiple new post Forms, you can supply a comma-separated list of numeric Form IDs like this:
$forms = array( 123, 456, 789 );
One thing you should be aware of is if you create an Edit User Form, or a New User Form, you will probably NOT want to include the credits field in that Form, which would allow the User to manually modify their number of credits. You probably want to manage that only in wp-admin instead.
Let me know if you have questions about this, or if I've misunderstood what you want to accomplish.