Skip Navigation

[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:

For example:
https://toolset.com/forums/topic/limiting-users-ability-to-change-custom-post/#post-1377659

Relevant Documentation:

This support ticket is created 5 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 32 replies, has 3 voices.

Last updated by FelipeP5703 4 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#1377569

Tell us what you are trying to do?

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?

#1377659

Hello,

There isn't such kind of built-in feature, you can consider custom codes:

For example:
1) Create a post type "Change-logs", setup one-to-many relationship between your custom post type and "Change-logs"

2) After users change his/her custom post with Toolset Forms plugin, use filter hook "cred_form_validate" to trigger a PHP function:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

3) In this PHP function, do these:
- Check if the image field value is changed
- If value is changed, count related "Change-logs" of this month:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/#wp_query-argument-for-querying-by-related-posts
https://developer.wordpress.org/reference/classes/wp_query/#date-parameters
- If count is equal or above 2, return an error message
- If count is below 2, then insert a new "Change-logs" post, and setup the post type relationship between new "Change-logs" post and current post:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

#1377987

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?

Isn't there an easier way? Maybe just a counter?

#1378495

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/

#1378769
#1379537

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.

#1379883

You already have access to the test site from the other thread. It's the demo test site dtstage.felipewpenna.com

I was going to check what was the ID form but I go this error while trying to access the site: hidden link

#1380519

Those PHP errors have been fixed, please point out the problem page URL and form URL, thanks

#1380851

Ok great.

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.

#1381607

Thanks for the details, I am checking it in your website, will update here if there is anything found.

#1381701

Since you did not point out he problem page URL, I have to created a new page in your website to test both forms:
hidden link

Form ID 49, there isn't image field.

Form ID 1355, there are two image fields:
- Imagem de Perfil
- Fotos para Anúncio
Which one do you want to setup the limitation?

Please provide above details? thanks

#1386959

Sorry I was away and did not have internet. I need to limit both please

#1386979

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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.

#1387047

Minesh,

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.

#1387865

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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.

However, Toolset Forms offers the hook that you may use:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_before_save_data
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

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.

More info;
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

Maybe you try to find Contractors here:
=> https://toolset.com/contractors/?wpv_view_count=573709&wpv-contractor-project-type%5B%5D=help-me-develop-something&wpv-wpcf-how-big-projects-can-you-handle=&wpv-wpcf-do-you-provide-maintenance=0&wpv-site-theme%5B%5D=astra&wpv-wpcf-i-can-also-give-quotation-based-on-project-description=1&wpv-wpcf-how-small-projects-can-you-take=&wpv-contractor-language%5B%5D=en