Okay
  Public Ticket #2798779
Prevent guest to change/edit en event they didn't created.
Closed

Comments

  •  1
    intel started the conversation

    Hi Zhivko, 

    i let guest to create events in calendar in front end. 

    But now they can change events created by other guests. How can i prevent that? 

    They still need to create event, but they shouldn't change/edit en event they didn't created. 

  •  894
    Zhivko replied

    What is your calendar back-end visibility option set to?


    Stachethemes Developer

  •  1
    intel replied

    Hi Zhivko,

    this is set to public public anyone.

    See attached screenshot. 

  •  894
    Zhivko replied

    Set the back-visibility of the calendar to "Just Me".

    They will be able to edit their events until the administrator approve it. Once approved only the admin will be allowed to make changes to this event.


    Stachethemes Developer

  •  1
    intel replied

    I changed it as you suggested but this giving not that what i want :( 

    Right now, anybody can create an event, but they can't edit this event after they clicked on "save" button. 

    The meaning is that they can edit theirs event after they saved it, but they shouldn't be allowed to edit others event. 

    Can it be done by giving them "subscriber" user status. So they need to login first, then they can add event and edit event if they are logged in? But they shouldn't be allowed to edit others event.

  •  894
    Zhivko replied

    This filter will allow only event authors to edit their own events.

    add_filter('stec_user_can_edit_event', function($default, $event) {
        
        // prevent non logged in users to edit events
        if ( !is_user_logged_in() ) {
            return false;
        }
        // super admin can edit all
        if ( is_super_admin() ) {
            return true;
        }
        $user_id      = get_current_user_id();
        $event_author = $event->get_author();
        
        
        // allow author to edit their own events
        if ( $user_id === $event_author ) {
            return true;
        }
        
     
        return false;
    }, 10, 2);

    Stachethemes Developer