Skip to content

Instantly share code, notes, and snippets.

@bryceadams
Created January 16, 2015 11:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryceadams/a770c3459653415fe7b5 to your computer and use it in GitHub Desktop.
Save bryceadams/a770c3459653415fe7b5 to your computer and use it in GitHub Desktop.
<?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 );
}
@stephyhogan
Copy link

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?

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