Hi, as a new admin of the Event Calendar plugin I have two questions.
1: Is there a way to make a page or dedicated, stand-alone button that brings up the "Dashboard"? I want users, including event managers, to mostly interact with the calendar from the front-end. The "Dashboard" link from the main Calendar view is the only way I have found to bring this up, but it's a very helpful view and I would love to be able to put it on its own page.
2: I have some event hosts who would like to be able to make Private events. This could mean several different things, depending on the capabilities of the plugin. One major definition is that the event would not show up on the main Calendar or, if it did, it would require either a password to view any details, or that the logged-in user who is viewing it would have already been Invited to the event. This leads to another approach that would be desirable, which is an "invite only" event, i.e. an event that only people who the event host has Invited will be able to see it. I don't know if there is a way to do this with the current permissions model which seems based around Wordpress User Levels and doesn't seem to incorporate any kind of "status in relation to event" permissions.
I would love your help with both of these questions. Thanks!
1) The dashboard can be displayed on a separate page via shortcode [stec_dashboard]
2) I don't have a solution to this at the moment. I will check today if I can insert a new permission type "invited" to the permissions list and will let you know.
You will have to insert some extra PHP code in your child-theme functions.php file.
The code will add new permission "Invited users".
When this option is added to the event Read Permissions the event will be visible only to users that are invited to this event.
There is one downside to this: It won't work for users that are already invited unless you update their attendance.
The code:
// Register new permission "Invited users"
// This permission allows users to view events they have been invited to
// This permission works only for event read permission option
add_filter('stec_permissions_list', function ($list) {
$list[] = array(
'label' => esc_html__('Invited users', 'stec'),
'value' => 'stec_invited',
);
return $list;
});
// Register new meta field "attendee_emails" in stec_event post type
// This is a helper meta field to store all attendee emails for an event
// This field is used to check if a user is invited to an event during REST API requests
add_action('init', function () {
register_post_meta(
'stec_event',
'attendee_emails',
array(
'type' => 'string',
'single' => false,
'show_in_rest' => false,
'default' => ''
)
);
});
// Add attendee email to "attendee_emails" meta field when an attendee is created
add_action('stec_after_attendee_create_item', function ($attendance_id) {
$event_id = get_post_meta($attendance_id, 'event_id', true);
$attendee_email = get_post_meta($attendance_id, 'attendee_email', true);
$event_attendee_emails = get_post_meta($event_id, 'attendee_emails', true);
if (!is_array($event_attendee_emails)) {
$event_attendee_emails = array();
}
if (in_array($attendee_email, $event_attendee_emails)) {
return;
}
add_post_meta($event_id, 'attendee_emails', $attendee_email);
});
// Update "attendee_emails" meta field when an attendee is updated
add_action('stec_after_attendee_update_item', function ($result) {
$result_data = $result->get_data();
$attendance_id = $result_data['id'];
$event_id = get_post_meta($attendance_id, 'event_id', true);
$attendee_email = get_post_meta($attendance_id, 'attendee_email', true);
$event_attendee_emails = get_post_meta($event_id, 'attendee_emails', false);
if (in_array($attendee_email, $event_attendee_emails)) {
return;
}
add_post_meta($event_id, 'attendee_emails', $attendee_email);
});
// Remove attendee email from "attendee_emails" meta field when an attendee is deleted
add_action('stec_before_attendee_delete_item', function ($attendance_id) {
$event_id = get_post_meta($attendance_id, 'event_id', true);
$attendee_email = get_post_meta($attendance_id, 'attendee_email', true);
delete_post_meta($event_id, 'attendee_emails', $attendee_email);
});
// Inserts additional meta query logic that checks whether the user is invited to an event
// and the event has "stec_invited" read permission
add_action('rest_stec_event_query', function ($q, $r) {
if (!is_user_logged_in()) {
return $q;
}
if ('event' !== $r->get_param('context')) {
return $q;
}
$meta = &$q['meta_query'];
if (3 !== count($meta)) {
return $q;
}
$meta[0][] = array(
'relation' => 'AND',
array(
'key' => 'attendee_emails',
'value' => get_userdata(get_current_user_id())->user_email,
'compare' => 'IN'
),
array(
'key' => 'read_permission',
'value' => 'stec_invited',
'compare' => 'IN'
),
);
return $q;
}, 10, 2);
Hi, as a new admin of the Event Calendar plugin I have two questions.
1: Is there a way to make a page or dedicated, stand-alone button that brings up the "Dashboard"? I want users, including event managers, to mostly interact with the calendar from the front-end. The "Dashboard" link from the main Calendar view is the only way I have found to bring this up, but it's a very helpful view and I would love to be able to put it on its own page.
2: I have some event hosts who would like to be able to make Private events. This could mean several different things, depending on the capabilities of the plugin. One major definition is that the event would not show up on the main Calendar or, if it did, it would require either a password to view any details, or that the logged-in user who is viewing it would have already been Invited to the event. This leads to another approach that would be desirable, which is an "invite only" event, i.e. an event that only people who the event host has Invited will be able to see it. I don't know if there is a way to do this with the current permissions model which seems based around Wordpress User Levels and doesn't seem to incorporate any kind of "status in relation to event" permissions.
I would love your help with both of these questions. Thanks!
It has been almost a week since I opened this ticket and no response! That's disappointing. Can you at least give a response here?
Hi,
Sorry for the late reply. I just saw your ticket.
1) The dashboard can be displayed on a separate page via shortcode [stec_dashboard]
2) I don't have a solution to this at the moment. I will check today if I can insert a new permission type "invited" to the permissions list and will let you know.
Stachethemes Developer
Hi again,
I think I have a solution to your problem ( 2 ) .
You will have to insert some extra PHP code in your child-theme functions.php file.
The code will add new permission "Invited users".
When this option is added to the event Read Permissions the event will be visible only to users that are invited to this event.
There is one downside to this: It won't work for users that are already invited unless you update their attendance.
The code:
Stachethemes Developer