| 1 |
<?php |
| 2 |
/** |
| 3 |
* Booking Resources domain authorization helpers. |
| 4 |
* |
| 5 |
* @package Booking Calendar |
| 6 |
* @since 11.9.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
if ( ! function_exists( 'wpbc_catalog_booking_resources_get_role_capability' ) ) { |
| 14 |
/** |
| 15 |
* Map an established Booking Calendar minimum-role option to a capability. |
| 16 |
* |
| 17 |
* This belongs to the Resource domain rather than its catalog page because |
| 18 |
* other authorized consumers, including the Setup Wizard, create Resources |
| 19 |
* without loading the catalog UI. |
| 20 |
* |
| 21 |
* @param string $role_option Booking Calendar option containing a minimum role. |
| 22 |
* |
| 23 |
* @return string WordPress capability name. |
| 24 |
*/ |
| 25 |
function wpbc_catalog_booking_resources_get_role_capability( $role_option ) { |
| 26 |
$minimum_role = get_bk_option( sanitize_key( $role_option ) ); |
| 27 |
$capabilities = array( |
| 28 |
'administrator' => 'activate_plugins', |
| 29 |
'editor' => 'publish_pages', |
| 30 |
'author' => 'publish_posts', |
| 31 |
'contributor' => 'edit_posts', |
| 32 |
'subscriber' => 'read', |
| 33 |
); |
| 34 |
|
| 35 |
return isset( $capabilities[ $minimum_role ] ) ? $capabilities[ $minimum_role ] : 'manage_options'; |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
if ( ! function_exists( 'wpbc_catalog_booking_resources_get_manage_capability' ) ) { |
| 40 |
/** |
| 41 |
* Return the capability required by the canonical Resources role setting. |
| 42 |
* |
| 43 |
* Free installations use the Settings role because they do not expose the |
| 44 |
* multi-resource role option. Paid editions use the Resources role so every |
| 45 |
* Resource-domain consumer enforces the same administration boundary. |
| 46 |
* |
| 47 |
* @return string WordPress capability name. |
| 48 |
*/ |
| 49 |
function wpbc_catalog_booking_resources_get_manage_capability() { |
| 50 |
$role_option = class_exists( 'wpdev_bk_personal' ) ? 'booking_user_role_resources' : 'booking_user_role_settings'; |
| 51 |
$capability = wpbc_catalog_booking_resources_get_role_capability( $role_option ); |
| 52 |
|
| 53 |
/** |
| 54 |
* Filter the capability required to manage Booking Resources. |
| 55 |
* |
| 56 |
* @param string $capability WordPress capability name. |
| 57 |
*/ |
| 58 |
return (string) apply_filters( 'wpbc_catalog_booking_resources_manage_capability', $capability ); |
| 59 |
} |
| 60 |
} |
| 61 |
|