Moderating Community Posts

Home Forums Calendar Products Events Calendar PRO Moderating Community Posts

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #1199398
    Thomas Claffy
    Participant

    I need to mix my rights. I want some people to be able to add events thru the community module without requiring admin approval but I do not want them in the backend. Is there any way to accomplish this? I cannot allow all events with no moderation

    #1199989
    Nico
    Member

    Hi there Thomas,

    Thanks for getting in touch with us! I can help you on this 🙂

    First of all let me say there’s no way to do this via settings. You can block admin access to the different roles, and ask for approval (Events will be set to Pending Review). What’s not possible is to have a user role bypassing this ‘pending review’ setting.

    Before I try to write a code snippet for this, let’s make sure we are on the same page. You want to have 2 users that can submit events via the Community form. One of them (suscribers) will need manual approval of submitted events, while there other role (contributor) won’t need approval. Both users roles won’t have back-end access. Is this correct?

    Please let me know about it and I’ll see if it’s possible to achieve this with a snippet,
    Best,
    Nico

    #1199994
    Thomas Claffy
    Participant

    Hi Nico,

    I think you have it.

    I currently have the following roles

    1. Subscribers who can only submit new and cannot publish and must submit changes to me that I edit.
    2. Contributor who can submit and cannot publish and can edit their own.

    It would be great if in the front end with no back end access, I could have

    3. ContributorPublisher who can submit, publish and edit their own.
    4. ContributorManager who can submit, publish and edit their own and also edit others.

    I can set those roles and rights up in the backend but I don’t know how to implement that in the front end. BTW, I am using Total and they added an Edit button right on the single event page for a user when they have edit rights so hopefully that would flow right thru when they have rights to edit based on their user role. I don’t expect a lot of new buttons and interface changes but if they would just have rights based on their roles then I guess submitting an event would immediately publish it?

    thanks

    tom

    #1200274
    Thomas Claffy
    Participant

    So actually according to WordPress.org, these roles should be defined as Author and Editor. See https://codex.wordpress.org/Roles_and_Capabilities. Are thy implemented in the Community Plugin?

    #1200801
    Nico
    Member

    Thanks for following up Tom!

    In the front-end of the site all users should be able to Submit and Edit their events (unless you change the config for this), but just see their own event on the front-end ‘My Events’ page. So the limitation would be to see other users events and edit those. This doesn’t work like WordPress default roles and capabilities. It just let users see the events they own and edit them.

    If you are trying to customize this you’ll need to override the template for ‘My Events’ and conditionally load all users events if the role is equal to ContributorManager (for example). If the users has the correct permissions I think there will be no troubles viewing the edit page for the event and saving the data. I just did a quick test editing another admin user event, and it worked as expected.

    Please let me know if this makes sense to you,
    Best,
    Nico

    #1200834
    Thomas Claffy
    Participant

    I realize this doesn’t work like the default WordPress roles and I guess I am questioning why? This seems to make sense in this case. Ultimately, it sounds like the editing is doable but how do they publish?

    #1201953
    Nico
    Member

    Thanks for following up Thomas!

    I realize this doesn’t work like the default WordPress roles and I guess I am questioning why?

    I’m afraid this decision has been made a couple of years ago so I have to be honest and say I’m not sure why the actual approach was taken. My guess is the simpler and lightest was the way to go. As explained above this is a basic workflow for submitting / editing your own events and not a complete front-end events admin.

    This seems to make sense in this case. Ultimately, it sounds like the editing is doable but how do they publish?

    Yeah, and I can help you if you decide to dive into this customization. I’m not sure about the question. Do you mean if they edit an existing event it will go back to draft or pending? Not sure about the concern here.

    Thanks,
    Nico

    #1201997
    Thomas Claffy
    Participant

    Nico,

    So I just set up an Editor role who has rights to edit others posts. This test user does not have any events. The Events list shows nothing so the first hurdle to get events the list when a user has rights to edit the post.

    As for publishing, when an event is added in community, by default it is draft. Those users that have publish rights should have a publish button for draft events.

    I think that is all it needs.

    Tom

    #1203546
    Nico
    Member

    Thanks for clarifying Tom!

    I’ll take a look at this tomorrow and see if there’s an easy way to get these things working as you need. Although I cannot promise anything as the support we provide on customizations is quite limited. But I’ll give this a try and see, maybe it’s easy to get this done!

    Best,
    Nico

    #1203800
    Thomas Claffy
    Participant

    Hi Nico,

    Thanks!

    My #1 priority would be the post status and I would be happy if the action of the existing submit button set the status of the post to publish when the user role has publish rights and draft for users with no publish rights when a new post is submitted. Maybe I should add this as an enhancement request?

    #2, The list of all events in the front end would, as you say, create a mini-admin role, which would be really useful to a lot of us folks managing calendars for a wide range of contributors where we want some help managing the posts but don’t want to open up the backend to someone else.

    #1206808
    Nico
    Member

    Hey Tom,

    Sorry for the delay here, please give me a bit more time to review this!

    Best,
    Nico

    #1207665
    Nico
    Member

    Hi there Tom,

    Thanks for the patience while I worked on this!

    My #1 priority would be the post status and I would be happy if the action of the existing submit button set the status of the post to publish when the user role has publish rights and draft for users with no publish rights when a new post is submitted. Maybe I should add this as an enhancement request?

    Place the code below inside your theme’s (or child theme’s) functions.php file and it should do the trick. As a sample I’m checking for the capability to ‘edit_other_posts’, and setting the event to draft if the current user doesn’t have that perm. This is a starting point for you to tweak this to your project needs.

    /**
    * Tribe, set community event status according to current user capabilities
    * User roles > https://codex.wordpress.org/Roles_and_Capabilities
    * Post Satus > https://codex.wordpress.org/Post_Status
    */
    function tribe_set_ce_status ( $event_id ) {

    // check for the desired capability
    if ( current_user_can('edit_others_posts', $event_id) ) {
    wp_update_post(array( 'ID' => $event_id, 'post_status' => 'publish'));
    } else {
    wp_update_post(array( 'ID' => $event_id, 'post_status' => 'draft'));
    }

    }

    add_action( 'tribe_community_event_updated', 'tribe_set_ce_status' );
    add_action( 'tribe_community_event_created', 'tribe_set_ce_status' );

    #2, The list of all events in the front end would, as you say, create a mini-admin role, which would be really useful to a lot of us folks managing calendars for a wide range of contributors where we want some help managing the posts but don’t want to open up the backend to someone else.

    Taking a second look into this, it’s not necessary to override the ‘community events list’ template. You can add this snippet to the theme’s (or child theme’s) functions.php file to make it work:

    /**
    * Tribe, filter community events my events query
    * User roles > https://codex.wordpress.org/Roles_and_Capabilities
    */
    function tribe_filter_my_events_query ( $args ) {

    // check for the desired capability
    if ( current_user_can('edit_others_posts') ) {
    unset( $args['author'] );
    }

    return $args;
    }
    add_filter( 'tribe_ce_my_events_query', 'tribe_filter_my_events_query' );

    Please give these two snippets a try and let me know if they work as intended,
    Best,
    Nico

    #1207956
    Thomas Claffy
    Participant

    Nico,

    Thanks for the code! Nice enhancement. It was very close although I tried 1st to copy and paste from the email and there must have been some of Microsoft’s formatting characters buried in there even after pasting into notepad so I came here and got the code and all is well. I did change the right to publish_post as that is really the permission I want to check when I want a user to be able to publish directly. The edit others function is great also as I can now have a mini admin without access to my back end. So I now have subscribers (can’t submit), contributors (new adds moderated and updates send me an email), author(can publish with no moderation/updates send me an email) and Editor ( can edit, delete all published posts/updates send me an email). Pretty robust change in what permissions I can give my users so for such a small change. If only the events list were sortable.

    The little bit of bad is attached. A nasty screen after a user adds an event with the publish right in the front end. User has to refresh the list to get the pretty view. Any solution? These folks will be power users so not the end of the world kind of thing.

    #1208193
    Thomas Claffy
    Participant

    Nico,

    Both of the new functions are throwing a PHP exception. Should it have a is_user_logged_in()wrapped around it somewhere?

    Thanks tom (vb.net guy…sorry)

    ****************************************************************************************

    PHP Error:
    [20-Dec-2016 00:02:11 UTC] PHP Parse error: syntax error, unexpected ‘=’, expecting ‘)’ in /home/myfergus/public_html/wp-content/themes/total-child-theme-master/functions.php on line 61

    Code:
    /**
    * Tribe, set community event status according to current user capabilities
    * User roles > https://codex.wordpress.org/Roles_and_Capabilities
    * Post Satus > https://codex.wordpress.org/Post_Status
    */
    function tribe_set_ce_status ( $event_id ) {

    // check for the desired capability
    if ( current_user_can(‘publish_posts’, $event_id) ) {
    wp_update_post(array( ‘ID’ => $event_id, ‘post_status’ => ‘publish’)); <- line 61 in my code
    } else {
    wp_update_post(array( ‘ID’ => $event_id, ‘post_status’ => ‘draft’));
    }

    }

    add_action( ‘tribe_community_event_updated’, ‘tribe_set_ce_status’ );
    add_action( ‘tribe_community_event_created’, ‘tribe_set_ce_status’ );

    ***************************************************************************************
    PHP Error:
    [20-Dec-2016 00:33:40 UTC] PHP Parse error: syntax error, unexpected ‘=’, expecting ‘)’ in /home/myfergus/public_html/wp-content/themes/total-child-theme-master/functions.php on line 78

    Code:
    /**
    * Tribe, filter community events my events query
    * User roles > https://codex.wordpress.org/Roles_and_Capabilities
    */
    function tribe_filter_my_events_query ( $args ) {

    // check for the desired capability
    if ( current_user_can(‘edit_others_posts’) ) { <— line 78 in my code
    unset( $args[‘author’] );
    }

    return $args;
    }

    add_filter( ‘tribe_ce_my_events_query’, ‘tribe_filter_my_events_query’ );

    #1209032
    Nico
    Member

    Hey Tom,

    Those errors seem to be caused by the chars in the code. Can you try copying it over again from the gist below?

    https://gist.github.com/niconerd/82db313919df6f7d6d330266baf5ead5

    Also I don’t think the code needs to be wrapped around ‘is_user_logged_in’. In any case I made a test submitting an event with a non-logged in users and got no errors on my test site.

    A nasty screen after a user adds an event with the publish right in the front end. User has to refresh the list to get the pretty view. Any solution? These folks will be power users so not the end of the world kind of thing.

    This plugin will surely help out → Redirect to different URL after event submission

    Please let me know if the code works now,
    Best,
    Nico

Viewing 15 posts - 1 through 15 (of 18 total)
  • The topic ‘Moderating Community Posts’ is closed to new replies.