Last active
August 29, 2015 14:24
-
-
Save tripflex/ea0bfa7525c1808e3d0a to your computer and use it in GitHub Desktop.
Auto populate candidate_email meta key with current user's email address
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 | |
// !!! Don't add the <?php above if you're adding this to the end of your functions.php file !!! | |
add_filter( 'field_editor_auto_populate_candidate_email', 'auto_populate_candidate_email_field' ); | |
function auto_populate_candidate_email_field( $field_value ){ | |
// If field value is already set (means it was pulled from user meta) then return that value | |
// or if user is not logged in return whatever $field_value is already set as | |
if( ! empty( $field_value ) || ! is_user_logged_in() ) return $field_value; | |
// Get the current user information | |
$current_user = wp_get_current_user(); | |
// As long as user object is returned and has user_email property, set field_value | |
if( is_object( $current_user ) && isset( $current_user->user_email ) ) $field_value = $current_user->user_email; | |
return $field_value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment