Created
February 22, 2019 23:42
-
-
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
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( '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