Beispiel #1
0
/**
 * Map the meta capabilities
 *
 * @since	1.3
 * @param	arr		$caps		The users actual capabilities
 * @param	str		$cap		The capability name
 * @param	int		$user_id	The user ID
 * @param	arr		$args		Adds the context to the cap. Typically the object ID.
 */
function mdjm_addon_map_meta_cap($caps, $cap, $user_id, $args)
{
    // If editing, deleting, or reading a package or addon, get the post and post type object.
    if ('edit_mdjm_package' == $cap || 'delete_mdjm_package' == $cap || 'read_mdjm_package' == $cap || 'publish_mdjm_package' == $cap) {
        $post = get_post($args[0]);
        if (empty($post)) {
            return $caps;
        }
        $post_type = get_post_type_object($post->post_type);
        // Set an empty array for the caps.
        $caps = array();
    }
    // If editing a package or an addon, assign the required capability. */
    if ('read_mdjm_package' == $cap) {
        if (in_array($user_id, mdjm_get_event_employees($post->ID))) {
            $caps[] = $post_type->cap->edit_posts;
        } else {
            $caps[] = $post_type->cap->edit_others_posts;
        }
    } elseif ('delete_mdjm_package' == $cap) {
        if (in_array($user_id, mdjm_get_event_employees($post->ID))) {
            $caps[] = $post_type->cap->delete_posts;
        } else {
            $caps[] = $post_type->cap->delete_others_posts;
        }
    } elseif ('read_mdjm_package' == $cap) {
        if ('private' != $post->post_status) {
            $caps[] = 'read';
        } elseif (in_array($user_id, mdjm_get_event_employees($post->ID))) {
            $caps[] = 'read';
        } else {
            $caps[] = $post_type->cap->read_private_posts;
        }
    }
    // Return the capabilities required by the user.
    return $caps;
}
/**
 * Determine if an employee is working a specific event
 *
 * @since	1.3
 * @param	int		$event_id		The event ID
 * @param	int		$employee_id	The employee user ID
 * @return	bool	True if working the event, otherwise false
 */
function mdjm_employee_working_event($event_id, $employee_id = '')
{
    $event_employees = mdjm_get_event_employees($event_id);
    $employee_id = !empty($employee_id) ? $employee_id : get_current_user_id();
    if (!$event_employees || !in_array($employee_id, $event_employees)) {
        return false;
    } else {
        return true;
    }
}