Limit fields to edit once published, community

Home Forums Calendar Products Community Events Limit fields to edit once published, community

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1061522
    James
    Participant

    Hi,

    I am making a website for our village and are using your pro and community plugins.

    I was wondering if it is possible to limit the fields that can be edited after a post has been published for community events, currently if a admin publishes a user’s event then the user can go in and change anything they want. I am fine with them changing the description and title etc but would like to prevent them from editing the date and time as a lot of the events will be using the communal village hall so times can only be changed after checking with the bookings secretary, who is an admin and will log in and change the event details for them.

    I did think about removing the inputs from the form, or just changing the visibility to none for the ones I don’t want to show but the event creation and edit form seem shared so was unsure how to do this.

    Another solution could be to change the event to a draft again after the user edits someone, again I’m unsure how to do that.

    Any help would be much appreciated.

    Thanks

    James

    #1062714
    Nico
    Member

    Hi James,

    Thanks for reaching out to us, and sorry for my delayed reply. I’m looking into the issue and trying to find the simplest approach to solve this, but it’s getting a little tricky!

    Just wanted to give you a quick heads up on this. I’ll be updating the thread soon!

    Best,
    Nico

    #1062726
    Nico
    Member

    Hey James,

    Thanks for your patience while I looked into this!

    I figured out the best way to do this would be to create a template override for the edit-event.php template (located at wp-content/plugins/the-events-calendar-community-events/src/Tribe/views/) and add the following function to use in conditionals later on the template:


    ...
    function is_edit_page ( ) {
    global $post;
    return is_a ($post, 'WP_POST');
    }

    if ( ! defined( 'ABSPATH' ) ) {
    die( '-1' );
    }
    ...

    So for example let’s say you want to hide the date ‘part’ of the form if the user is editing, then you can do the following:

    ...
    <?php if ( !is_edit_page() ) : ?>
    <?php tribe_get_template_part( 'community/modules/datepickers' ); ?>
    <?php endif; ?>
    ...

    Please let me know if this makes sense to you and if you can make it work,
    Best,
    Nico

    #1062864
    James
    Participant

    Hi,

    Thankyou for your response that seems like a good way of doing it and I will give it a try!

    After talking with my client about this they think it might be better to allow editing of certain fields (which your code should achieve) but also set the event as a draft again after it has been edited so an admin has to approve it. Do you have any idea how this could be achieved? I know there is an option to set whether community events are submitted as drafts or as published, so was thinking I could create an override that checks if the form is the edit form, and if so will submit the event as a draft instead of published.

    I appreciate your help as I’m aware I’m not using the plugin quite as intended!

    Thanks,

    James

    #1063383
    Nico
    Member

    James,

    Glad you find that approach useful!

    …also set the event as a draft again after it has been edited so an admin has to approve it. Do you have any idea how this could be achieved?

    Sure! You’ll need to add the following snippet to your theme (or child theme) functions.php file:


    /*
    * The Events Calendar - Allways set to draft CE form sumissions
    */
    add_action( 'tribe_community_event_updated', 'ce_set_draft' );
    add_action( 'tribe_community_event_created', 'ce_set_draft' );

    function ce_set_draft ( $event_id ) {
    $current_post = get_post( $event_id, 'ARRAY_A' );
    $current_post['post_status'] = 'draft';
    wp_update_post($current_post);
    }

    Please let me know if that works for you,
    Best,
    Nico

    #1078926
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Limit fields to edit once published, community’ is closed to new replies.