Created
April 2, 2018 21:05
-
-
Save tripflex/df834a3b8cefa6e60174c3a2f3b6af84 to your computer and use it in GitHub Desktop.
Give user Job or Resume Visibility Package on registration when using WP Job Manager Packages addon
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 | |
add_action( 'user_register', 'give_wpjmp_vis_job_user_package_on_registration' ); | |
add_action( 'user_register', 'give_wpjmp_vis_resume_user_package_on_registration' ); | |
/** | |
* Give user custom Job Visibility Package on registration | |
* | |
* | |
* @since @@version | |
* | |
* @param $user_id | |
*/ | |
function give_wpjmp_vis_job_user_package_on_registration( $user_id ) { | |
global $wpdb; | |
if ( wpjmp_give_pack_check_user_role( 'employer', $user_id ) ) { | |
$wpdb->insert( | |
"{$wpdb->prefix}wpjmpack_user_packages", | |
array( | |
'user_id' => $user_id, | |
'product_id' => 0, // This should be set to the ID of a package in WooCommerce if you want it to show a package name! | |
'package_type' => 'job_listing', // job_listing for job packages, resume for resume packages | |
'handler' => 'woocommerce', // !!! DO NOT CHANGE THIS VALUE !!! | |
// Browse is either enabled or disabled (no limits exist for browse) | |
'allow_browse' => 1, // 1 for enable - 0 for disable | |
// Apply can have a limit if specified, otherwise set to zero (0) for unlimited | |
'allow_apply' => 1, // 1 for enable - 0 for disable | |
'apply_limit' => 5, // 0 for unlimited, this example sets it to max of 5 applications before requiring new package | |
// View can have a limit if specified, otherwise set to zero (0) for unlimited | |
'allow_view' => 1, // 1 for enable - 0 for disable | |
'view_limit' => 0, // 0 for unlimited | |
) | |
); | |
} | |
} | |
/** | |
* Give user custom Resume Visibility Package on registration | |
* | |
* | |
* @since @@version | |
* | |
* @param $user_id | |
*/ | |
function give_wpjmp_vis_resume_user_package_on_registration( $user_id ) { | |
global $wpdb; | |
if ( wpjmp_give_pack_check_user_role( 'candidate', $user_id ) ) { | |
$wpdb->insert( | |
"{$wpdb->prefix}wpjmpack_user_packages", | |
array( | |
'user_id' => $user_id, | |
'product_id' => 0, // This should be set to the ID of a package in WooCommerce if you want it to show a package name! | |
'package_type' => 'resume', // job_listing for job packages, resume for resume packages | |
'handler' => 'woocommerce', // !!! DO NOT CHANGE THIS VALUE !!! | |
// Browse is either enabled or disabled (no limits exist for browse) | |
'allow_browse' => 1, // 1 for enable - 0 for disable | |
// Apply can have a limit if specified, otherwise set to zero (0) for unlimited | |
'allow_contact' => 1, // 1 for enable - 0 for disable | |
'contact_limit' => 0, // 0 for unlimited | |
// View can have a limit if specified, otherwise set to zero (0) for unlimited | |
'allow_view' => 1, // 1 for enable - 0 for disable | |
'view_limit' => 5, // 0 for unlimited, this example sets it to max of 5 resume views before requiring new package | |
// View name can have a limit if specified, otherwise set to zero (0) for unlimited | |
'allow_view_name' => 1, // 1 for enable - 0 for disable | |
'view_name_limit' => 0, // 0 for unlimited | |
) | |
); | |
} | |
} | |
/** | |
* Check if user has specific role | |
* | |
* | |
* @since @@version | |
* | |
* @param $role | |
* @param null $user_id | |
* | |
* @return bool | |
*/ | |
function wpjmp_give_pack_check_user_role( $role, $user_id = null ) { | |
if ( is_numeric( $user_id ) ) { | |
$user = get_userdata( $user_id ); | |
} else { | |
$user = wp_get_current_user(); | |
} | |
if ( empty( $user ) ) { | |
return false; | |
} | |
return in_array( $role, (array) $user->roles ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example code for giving only Job Packages: https://gist.github.com/tripflex/140bfa98527080da16a2341954609c85