Events Manager Pro and required user fields

Events Manager + Events Manager Pro is a great plugin team for taking bookings for events on WordPress websites. One hitch I’ve struck is that if you as webmaster need to edit a user, and the user hasn’t filled in all their details, Events Manager Pro won’t let you save without filling in all of its required fields (basically, address details). And of course, the chances are that you won’t know what those fields should contain.

Luckily, there’s a simple filter hook that lets you override this behaviour if you need to. Here’s how to let admins edit users without filling in the Events Manager Pro required fields, but still make regular users give up their details. Drop this code into a simple plugin, or add it to your theme’s functions.php file.

add_filter('emp_form_validate_field', 'empFormValidateField', 10, 4);

/**
* stop Events Manager Pro requiring booking related fields
* when user admin is editing user (e.g. changing user role)
* @param bool $result
* @param string $field
* @param string $value
* @param EM_Form $EM_Form
* @return bool
*/
function empFormValidateField($result, $field, $value, $EM_Form) {
    // if field has validation error and user is a user admin, ignore error
    if (!$result && current_user_can('edit_users')) {
        $result = true;
        array_pop($EM_Form->errors);
    }

    return $result;
}

Job is allowed to be partly done, if you’re an admin and just want to bloody well save the user! :)

Facebooktwittergoogle_plusredditlinkedinmailFacebooktwittergoogle_plusredditlinkedinmail
  • John Oleksowicz

    This is exactly what I was looking for! Thank you for saving me the time. Much appreciated!