Skip to content

Instantly share code, notes, and snippets.

@tripflex
Last active August 29, 2015 14:24
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/ea0bfa7525c1808e3d0a to your computer and use it in GitHub Desktop.
Save tripflex/ea0bfa7525c1808e3d0a to your computer and use it in GitHub Desktop.
Auto populate candidate_email meta key with current user's email address
<?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