'activate_plugins', 'editor' => 'publish_pages', 'author' => 'publish_posts', 'contributor' => 'edit_posts', 'subscriber' => 'read', ); return isset( $capability[ $min_user_role ] ) ? $capability[ $min_user_role ] : 'manage_options'; } /** * Check if current user can manage Capacity Rules. * * @return bool */ function wpbc_resource_capacity__user_can_manage() { return wpbc_is_mu_user_can_be_here( 'only_super_admin' ) && current_user_can( wpbc_resource_capacity__get_manage_cap() ); } /** * Block direct page rendering when the user does not have Capacity Rules access. * * @param bool $is_show_this_page Whether page should be shown. * @param string $page_tag Page tag. * @param string $active_page_tab Active tab. * @param string $active_page_subtab Active subtab. * * @return bool */ function wpbc_resource_capacity__check_showing_page( $is_show_this_page, $page_tag, $active_page_tab, $active_page_subtab ) { if ( ( 'wpbc-resources' === $page_tag ) && ( 'capacity' === $active_page_tab ) && ! wpbc_resource_capacity__user_can_manage() ) { return false; } return $is_show_this_page; } add_filter( 'wpbc_before_showing_settings_page_is_show_page', 'wpbc_resource_capacity__check_showing_page', 20, 4 ); /** * Enqueue CSS for Capacity Rules. * * @param string $where_to_load Where assets are loaded. * * @return void */ function wpbc_resource_capacity_enqueue_css_files( $where_to_load ) { if ( ( ! is_admin() ) || ( ! in_array( $where_to_load, array( 'admin', 'both' ), true ) ) ) { return; } if ( ! wpbc_resource_capacity__is_page() ) { return; } wp_enqueue_style( 'wpbc-resource-capacity-page', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/page_resource_capacity.css', array( 'wpbc-all-admin' ), WP_BK_VERSION_NUM ); } add_action( 'wpbc_enqueue_css_files', 'wpbc_resource_capacity_enqueue_css_files', 66 ); /** * Enqueue JS for Capacity Rules. * * @param string $where_to_load Where assets are loaded. * * @return void */ function wpbc_resource_capacity_enqueue_js_files( $where_to_load ) { if ( ( ! is_admin() ) || ( ! in_array( $where_to_load, array( 'admin', 'both' ), true ) ) ) { return; } if ( ! wpbc_resource_capacity__is_page() ) { return; } wp_enqueue_script( 'wpbc-resource-capacity-page', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/page_resource_capacity.js', array( 'jquery', 'wpbc_all' ), WP_BK_VERSION_NUM, array( 'in_footer' => WPBC_JS_IN_FOOTER ) ); wp_localize_script( 'wpbc-resource-capacity-page', 'wpbc_resource_capacity_page', array( 'i18n' => array( 'auto_cancel_warning' => __( 'Warning!!! After you approved the specific booking(s), all your pending bookings of the same booking resource as an approved booking for the dates, which are intersect with dates of approved booking, will be automatically canceled!', 'booking' ), 'always_available_warning' => __( 'Warning! You allow unlimited number of bookings per same dates, its can be a reason of double bookings on the same date. Do you really want to do this?', 'booking' ), ), ) ); } add_action( 'wpbc_enqueue_js_files', 'wpbc_resource_capacity_enqueue_js_files', 66 ); /** * Capacity Rules tab on the Resources page. */ class WPBC_Page_Resource_Capacity extends WPBC_Page_Structure { /** * Settings API instance. * * @var WPBC_Settings_API_Capacity|false */ private $settings_api = false; /** * Whether settings were saved during this request. * * @var bool */ private $is_updated = false; /** * Menu slug. * * @return string */ public function in_page() { if ( ! wpbc_resource_capacity__user_can_manage() ) { return (string) wp_rand( 100000, 1000000 ); } return 'wpbc-resources'; } /** * Register tab. * * @return array */ public function tabs() { return array( 'capacity' => array( 'is_show_top_path' => true, 'left_navigation__default_view_mode' => 'compact', 'title' => __( 'Capacity Rules', 'booking' ), 'hint' => __( 'Manage booking capacity, pending-day availability, and related resource rules.', 'booking' ), 'page_title' => __( 'Capacity Rules', 'booking' ), 'link' => '', 'position' => '', 'css_classes' => 'wpbc_top_tab__resource_capacity', 'icon' => '', 'font_icon' => 'wpbc_icn_filter_none', 'font_icon_right' => 'wpbc-bi-question-circle', 'default' => false, 'disabled' => false, 'hided' => false, 'subtabs' => array(), 'folder_style' => 'order:15;', ), ); } /** * Get Settings API class. * * @return WPBC_Settings_API_Capacity */ public function settings_api() { if ( false === $this->settings_api ) { $this->settings_api = new WPBC_Settings_API_Capacity(); } return $this->settings_api; } /** * Save settings. * * @return void */ public function maybe_update() { $form_name = 'wpbc_resource_capacity_form'; // phpcs:ignore WordPress.Security.NonceVerification.Missing if ( ! isset( $_POST[ 'is_form_sbmitted_' . $form_name ] ) ) { return; } check_admin_referer( 'wpbc_settings_page_' . $form_name ); if ( ! wpbc_resource_capacity__user_can_manage() ) { return; } $validated_fields = $this->settings_api()->validate_post(); foreach ( $validated_fields as $field_name => $field_value ) { if ( false !== strpos( $field_name, '__promote_upgrade' ) ) { unset( $validated_fields[ $field_name ] ); } } $this->settings_api()->save_to_db( $validated_fields ); $this->is_updated = true; } /** * Page content. * * @return false|void */ public function content() { do_action( 'wpbc_hook_settings_page_header', 'resource_capacity' ); if ( ! wpbc_resource_capacity__user_can_manage() ) { return false; } if ( function_exists( 'wpbc_js_for_bookings_page' ) ) { wpbc_js_for_bookings_page(); } if ( $this->is_updated ) { wpbc_show_changes_saved_message(); } $submit_form_name = 'wpbc_resource_capacity_form'; ?>