Skip to content

Instantly share code, notes, and snippets.

@UserMetaPro
Last active August 29, 2015 14:04
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 UserMetaPro/6b967a331625b39972ee to your computer and use it in GitHub Desktop.
Save UserMetaPro/6b967a331625b39972ee to your computer and use it in GitHub Desktop.
Edit only if the field is blank
add_filter( 'user_meta_field_config', 'editOnlyBlank', 10, 2 );
function editOnlyBlank( $field, $fieldID ) {
global $userMeta;
// Change Target_Field_ID
if ( $fieldID <> 'Target_Field_ID' ) return $field;
// Uncomments this line if an admin are allowed to edit value
// if ( $userMeta->isAdmin() ) return $field;
$field['read_only'] = ! empty( $field['field_value'] ) ? true : false;
return $field;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment