Skip to content

Instantly share code, notes, and snippets.

@tripflex
Created February 22, 2019 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripflex/1f0d4616a7eb51fc7931ecb13e8742a9 to your computer and use it in GitHub Desktop.
Save tripflex/1f0d4616a7eb51fc7931ecb13e8742a9 to your computer and use it in GitHub Desktop.
Set user role to employer when job submitted using WP Job Manager Field Editor
<?php
add_action( 'job_manager_job_submitted', 'smyles_set_user_as_employer_on_submit' );
function smyles_set_user_as_employer_on_submit(){
if( $user_id = get_current_user_id() ){
$user = new WP_User( $user_id );
if( ! in_array( 'employer', (array) $user->roles ) ){
// You can add the role (keeping subscriber or other roles)
$user->add_role( 'employer' );
// Or set to just this role
// $user->set_role( 'employer' );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment