Skip to content

Instantly share code, notes, and snippets.

@andrasguseo
Created December 6, 2017 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrasguseo/dc41114506ad261001b3eaf980ba580e to your computer and use it in GitHub Desktop.
Save andrasguseo/dc41114506ad261001b3eaf980ba580e to your computer and use it in GitHub Desktop.
Community Events: Set the event status based on user role
<?php
/**
* Description: The snippet will allow you to automatically set the status
* of community events based on user role.
*
* Plugins: The Events Calendar, Community Events
* Author: Victor Zarranz, Andras Guseo
* Last updated: December 6, 2017
*
* User roles: administrator, editor, author, contributor, subscriber
* https://codex.wordpress.org/Roles_and_Capabilities
* Post stati: publish, future, draft, pending, private, trash
* https://codex.wordpress.org/Post_Status
*/
function tribe_community_set_event_status ( $event_id ) {
// If editor, then set status to published
if ( current_user_can( 'editor' ) ) {
$post_status = 'publish';
}
// If subscriber, then set status to draft
elseif ( current_user_can( 'subscriber' ) {
$post_status = 'draft';
}
// Fallback, for anything else set to draft
else {
$post_status = 'draft';
}
$args = array(
'ID' => $event_id,
'post_status' => $post_status,
);
wp_update_post( $args );
}
add_action( 'tribe_community_event_created', 'tribe_community_set_event_status' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment