Created
September 19, 2018 18:01
-
-
Save Pebblo/4f035d70b160c86f03442675e3d44e7f to your computer and use it in GitHub Desktop.
Example of how to allow multiple capabilities on a ticket, separate the capabilities with a comma.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // Please do not include the opening PHP tag if you already have one. | |
function tw_ee_wp_user_ticket_selector_check_multiple_caps( $cap, $id ){ | |
// Create an array of capabilities using the string set on the ticket. | |
// Separate each capability using a comma (,) | |
$caps_array = explode(',', $cap); | |
// Loop over the cap(s) set on the ticket and check if the current user has any of those caps. | |
foreach($caps_array as $single_cap) { | |
// Trim any whitespace that may be before/after the capability. | |
$single_cap = trim($single_cap); | |
//Check if the user has the cap on the account. | |
if( current_user_can($single_cap)) { | |
// If the user has the current cap, return it as they have access to the ticket. | |
return $single_cap; | |
} | |
} | |
// The user does not have the cap(s) on their account, just return the current caps. | |
return $cap; | |
} | |
add_filter( 'FHEE__EE_Capabilities__current_user_can__cap__wp_user_ticket_selector_check', 'tw_ee_wp_user_ticket_selector_check_multiple_caps', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment