Created
February 16, 2015 08:45
-
-
Save bryceadams/903fdf55b0fb18cb8979 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Hook into user_has_cap filter. This assumes you have setup resumes to require the capability 'has_active_job_package' | |
add_filter( 'user_has_cap', 'has_active_job_package_capability_check', 10, 3 ); | |
/** | |
* has_active_job_package_capability_check() | |
* | |
* Filter on the current_user_can() function. | |
* | |
* @param array $allcaps All the capabilities of the user | |
* @param array $cap [0] Required capability | |
* @param array $args [0] Requested capability | |
* [1] User ID | |
* [2] Associated object ID | |
*/ | |
function has_active_job_package_capability_check( $allcaps, $cap, $args ) { | |
// Only interested in has_active_job_package | |
if ( empty( $cap[0] ) || $cap[0] !== 'has_active_job_package' || ! function_exists( 'wc_paid_listings_get_user_packages' ) ) { | |
return $allcaps; | |
} | |
$user_id = $args[1]; | |
$packages = wc_paid_listings_get_user_packages( $user_id, 'job_listing' ); | |
// Has active package | |
if ( is_array( $packages ) && sizeof( $packages ) > 0 ) { | |
if ( $packages[0] == '2465' ) { | |
$allcaps[ $cap[0] ] = true; | |
} | |
} | |
// Has active listing | |
elseif ( $user_id > 0 ) { | |
$active_listings = get_posts( array( | |
'post_type' => 'job_listing', | |
'post_status' => array( 'publish' ), | |
'posts_per_page' => 1, | |
'author' => $user_id | |
) ); | |
if ( sizeof( $active_listings ) > 0 ) { | |
$allcaps[ $cap[0] ] = true; | |
} | |
} | |
return $allcaps; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment