• Resolved Giulio

    (@ferocious)


    Hello, I’m questioning how I can limit the user editing a predetermined number of times. I mean that the user ought to create his post/page but then he can not change it or he can update it x number times as defined in the options of my plugin. I’m using Custom Post Type.
    Is it possible?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Alex

    (@hempsworth)

    One way to accomplish this would be to have a custom field for each CPT which keeps a count of the number of times it has been edited, see add_post_meta()

    You would then run a check every time they save a post, by hooking into save_post and see:

    1. If they haven’t reached the limit of edits, increase the edit count by one
    2. If they have reached the limit, cancel the saving of that update

    You should probably have a message on the CPT admin screen alerting them of the fact they can’t update any more times, using admin_notices.

    Along with putting the notice in, you could also remove the ‘Update’ button entirely, with some CSS or jQuery by doing something like input#publish { display:none; }

    Thread Starter Giulio

    (@ferocious)

    Excellent!
    Thank you very much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Allow user to edit his posts only once’ is closed to new replies.