Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save thisissandip/f192da2b5f41ed2f3fe2d61c8b253c8c to your computer and use it in GitHub Desktop.

Select an option

Save thisissandip/f192da2b5f41ed2f3fe2d61c8b253c8c to your computer and use it in GitHub Desktop.
add_action('admin_init', function () {
$role = get_role('administrator');
if (!$role) {
return;
}
// Core Bookings capabilities
$caps = array(
'manage_bookings_settings',
'manage_bookings_timezones',
'manage_bookings_connection',
);
// Resource types from Bookings
if (function_exists('wc_booking_get_product_resource_post_types')) {
$resource_types = wc_booking_get_product_resource_post_types();
} else {
$resource_types = array();
}
$types = array_merge($resource_types, array('bookable_person', 'wc_booking'));
foreach ($types as $type) {
$caps = array_merge($caps, array(
"edit_{$type}",
"read_{$type}",
"delete_{$type}",
"edit_{$type}s",
"edit_others_{$type}s",
"publish_{$type}s",
"read_private_{$type}s",
"delete_{$type}s",
"delete_private_{$type}s",
"delete_published_{$type}s",
"delete_others_{$type}s",
"edit_private_{$type}s",
"edit_published_{$type}s",
));
}
// Global availability
$caps = array_merge($caps, array(
'edit_global_availability',
'read_global_availability',
'delete_global_availability',
'edit_global_availabilities',
'delete_global_availabilities',
));
// Assign all caps to admin
foreach ($caps as $cap) {
if (!$role->has_cap($cap)) {
$role->add_cap($cap);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment