Skip to content

Instantly share code, notes, and snippets.

Created December 31, 2013 04:38
Show Gist options
  • Save anonymous/8192689 to your computer and use it in GitHub Desktop.
Save anonymous/8192689 to your computer and use it in GitHub Desktop.
This code should enable different user levels to add/ edit custom fields in the Wordpress. Solution to http://wpquestions.com/question/showChronoLoggedIn/id/9118
<?php
add_action( 'user_profile_update_errors', 'validate_field' );
function validate_field(&$errors, $update = null, &$user = null)
{
if($user->has_cap('s2member_level2')) { // Custom fields only display to business accounts
// Nested if to check for field(s)
if ($_POST['exp_years']=='' or $_POST['exp_years']==NULL) // Change to check for empty or any regular expression.
{
$errors->add('empty_exp_years', "ERROR: Please select a valid value for exp years!");
}
}else if($user->has_cap('s2member_level3')) {
// Do this
}else {
// Do that!
}
}
?>
@fahdi
Copy link

fahdi commented Dec 31, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment