-
-
Save mikejolley/20d77105f88e54f0c01e 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_or_job_capability_check', 10, 3 ); | |
/** | |
* has_active_job_package_or_job_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_or_job_capability_check( $allcaps, $cap, $args ) { | |
// Only interested in has_active_job_package | |
if ( empty( $cap[0] ) || $cap[0] !== 'has_active_job_package' || ! function_exists( 'get_user_job_packages' ) ) { | |
return $allcaps; | |
} | |
$user_id = $args[1]; | |
$packages = get_user_job_packages( $user_id ); | |
// Has active package | |
if ( is_array( $packages ) && sizeof( $packages ) > 0 ) { | |
$allcaps[ $cap[0] ] = true; | |
} | |
// Has active job listing | |
if ( is_user_logged_in() ) { | |
$active_jobs = get_posts( array( | |
'post_type' => 'job_listing', | |
'post_status' => array( 'publish', 'pending' ), | |
'ignore_sticky_posts' => 1, | |
'posts_per_page' => 1, | |
'author' => get_current_user_id(), | |
'fields' => 'ids' | |
) ); | |
if ( sizeof( $active_jobs ) > 0 ) { | |
$allcaps[ $cap[0] ] = true; | |
} | |
} | |
return $allcaps; | |
} |
Up, it seem that i fixed thee error.
Don"t know exactly, i think i had "[has_active_job_package]" before, and now only "has_active_job_package" in the fields.
Well, sorry and thanks :)
Hey I know this is old, but just curious if this restrict certain packages? Is the 10, 3 identifying the package ID? Don't know if you will get this but would be awesome of you if you did reply. Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey !
Just updated all my plugins, and a change this script (https://gist.github.com/mikejolley/9668782) to the one above to restrict resume access to payed users (the ones with active job package).
But the code isn't working anymore, so nobody have access to resume, if in the configuration there is "[has_active_job_package]" as you can see here : http://oi58.tinypic.com/f2sevo.jpg.
This is really annoying, I'm obliged to set all employer to be able to view resumes, as the package check doesn't wor kanymore.
Is there a special things to do ? Is this only work with "employer" user type ? Or dont work with free package ?
Thanks