[Resolved] Limiting User’s ability to change custom post
This thread is resolved. Here is a description of the problem and solution.
Problem:
I'm wondering if there is a way to limit the User from changing his/her custom post to a X number of times a month. For example, I only want to allow the User to change images twice a month.
Solution:
There isn't such kind of built-in feature, you can consider custom codes:
I'm wondering if there is a way to limit the User from changing his/her custom post to a X number of times a month. For example, I only want to allow the User to change images twice a month. Is there a way to do that?
That seems very complicated. And would it create unnecessary posts (Change-logs)? If I have 200 regular custom posts, then another 400 (2 for each posts) change-logs post, wouldn't it slow down the site?
Q1) wouldn't it slow down the site?
If there are 200 regular custom posts, it will be more than 400 change-logs posts, since 1 month 2 change-logs posts, for example after 3 month, there could be 1200 change-logs posts.
It depends on your server compatibility, in most case, it won't slow down the site.
Q2) Isn't there an easier way? Maybe just a counter?
In this case, I don't think there is an easier way, and since there isn't such kind of built-in feature within Toolset, you can check it with our Toolset contractor: https://toolset.com/contractors/
Since it needs custom PHP codes, please provide a test site with the same problem, also point out the problem page URL and form URL, I can try to setup a demo for you.
I have two forms, ID 49 and ID 1355. ID 49 is the form to change text, phone numbers and other custom post fields. Form ID 1355 has everything form ID 49 has and it also has the images the users can change.
So the Form to change the images is ID 1355. I was wondering if there is a way to only allow the user to change the images twice a month (or a number the admin can change in the admin dashboard). Once they hit the number allowed, maybe they will only be able to use Form ID 49 change their custom post. Then next month would come and they would be allowed to change the images again on ID 1355.
But if you find a different and easier way to do it, I appreciate it.
Luo is on vacation. This is Minesh here and I'll take care of this ticket in Luo's absence. Hope this is OK.
I see Luo has created a test page where he added two forms:
=> hidden link
When you say limiting, Can you please explain what you want to limit? I see the ticket started with some other issue and in between, there is talk of custom code and at last Luo created the above test page to limit the entry.
If you can check the above test page and tell me with what conditions you want to limit what, that will help me to understand the issue first and then I will be able to guide you in the right direction.
I mentioned to Luo that I wanted to limit my users ability to change images to twice a month, meaning, once the custom post is created, they can only change images twice a month based on the day it was published. And yes, both image fields.
Ok - thanks for the confirmation but there is no such native feature available that should fulfill such custom requirement. To offer the help for such custom code is above and beyond the scope of our support policy and we as a supporter need to work within the defined support policy.
The test page that is created by Luo, I checked that and I'm not sure what Luo try to demontrate with the test page he created as simply there its not possible to fulfill your requirement to limit the image upload twice per month without writing the custom code.
Maybe you should use the cred_save_data hook when form is submitted and check if images are changed, maybe you can use the hook cred_before_save_data and if images are changed, you should add a meta field with that post where meta key should be the user ID and meta value should be the count of image changed. first time it should be set to 1 and next time if the meta key = user id found then you can set increment that by 1.
Later, You can check this meta key and if value >= 2 then you should hide the form. You can use the [wpv-conditional] statement to display your conditional output.