Skip to content

Instantly share code, notes, and snippets.

@mikejolley
Last active May 4, 2022 14:12
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mikejolley/9668782 to your computer and use it in GitHub Desktop.
Save mikejolley/9668782 to your computer and use it in GitHub Desktop.
WP Job Manager Resumes & WC Paid Listings - If resumes require a 'has_active_job_package' capability, limit access to only those with an active job package. Once the package expires (e.g. job limit reached) access to resumes expires too.
// 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 ) {
$allcaps[ $cap[0] ] = true;
}
return $allcaps;
}
@arfoodie
Copy link

arfoodie commented May 5, 2014

Does this expire when the job listing does (30 days standard) or when the user no longer has jobs to post? I need the first one.

@ram1505
Copy link

ram1505 commented May 5, 2014

How to use this snippet? Does this also allow specifying a particular type of paid user with active subscription? Say if I have Free, Premium listings, can I just make a premium user with active subscription to view the cv?

@mikejolley
Copy link
Author

@arfoodie This will, as written, expire as soon as the package runs out of jobs

@sriram155 This code would be placed in the theme functions.php file.

get_user_job_packages() returns an array of data, including the product_id of the product purchased. You could loop through these values and check that ID against your desired product ID before giving access. Possible yes.

@ram1505
Copy link

ram1505 commented May 9, 2014

@mikejolley, thanks for the reply. I tried adding the gist in my themes/functions.php file and nothing has been changed or functioning special after this snippet being in place. I still can view the resumes and I subscribed only for 1 job listing. Should I configure the Theme Manager Plugin to some special settings too? I'm not getting the point of this feature. Why would it block someone access to resumes when his submission quota (for which he/ she has paid) instead of at the end of his subscription period (like 30 days or so). I agree with @arfoodie.

@mikejolley
Copy link
Author

@sriram155 read the comments in the gist. You also need to set the capability in Resumes > Settings to 'has_active_job_package'.

@ram1505
Copy link

ram1505 commented May 10, 2014

@mikejolley It works perfectly when I make the Resume visibility to 'has_active_job_package'. Like requested by @artfoodie, it would be perfect if the resume shows till their subscription period expires instead of the job post limits expiration. I recently purchased Restrict Content Pro from Pippin's Plugin to do exactly this and I am still struggling to get it work. Your Gist partially does what I want.

@ArtfulPussycat
Copy link

ArtfulPussycat commented Oct 6, 2016

@mikejolley This modification is having no effect. I've added the code to the functions file and set the has_active_job_package in resume visibility.
Resumes are still visible to anyone logged is an employer regardless of listings/packages.
Deprecated?

@jmurphy444
Copy link

This is not working for me......all EMPLOYERS can see all resumes......any ideas?

@Clems64
Copy link

Clems64 commented Dec 28, 2016

Hi everybody,

As @jmurphy444, it's not working for me...

I added "has_active_job_package" in settings and added the code snippet, first in the plugin, now in my functions.php file... it doesn't work.

Any idea ?

@zeesaying
Copy link

I have created 3 packages Free, Pro, Business. I want to give a certain page access to the only those users who have an active business package. How can i do that?

@tripflex
Copy link

Make sure and follow the documentation guys, you have to add this under capabilities in the resume configuration as well:
https://wpjobmanager.com/document/tutorial-require-an-active-job-package-to-view-resumes/

@ibby89
Copy link

ibby89 commented Jan 11, 2018

Do you have a list of hooks? I'm trying to build something similar that adds a job package for free when a user purchases a subscription (was trying to use one of the woocommerce product bundles plugins to do this but they don't work with the custom product types provided by wpjm).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment