Created
January 16, 2015 11:49
-
-
Save bryceadams/a770c3459653415fe7b5 to your computer and use it in GitHub Desktop.
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_wcpl_user_package_on_registration' ); | |
function give_wcpl_user_package_on_registration( $user_id ) { | |
global $wpdb; | |
if ( wpjm_check_user_role( 'employer', $user_id ) ) { | |
$wpdb->insert( | |
"{$wpdb->prefix}wcpl_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_count' => 0, // Leave | |
'package_duration' => 30, // How long job listings last | |
'package_limit' => 1, // How many jobs can be posted for free | |
'package_featured' => 0, // 0 = not featured | |
'package_type' => 'job_listing' | |
) | |
); | |
} | |
} | |
function wpjm_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
Question, because customizing functions.php isn't my strength...
I want to give free listings to regular WP user roles and only make the employer role pay. How would I modify this to allow, say admins and authors, to post for free?