Advertisement
bowenac

Untitled

Sep 4th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. //Add Role To Register Link
  2. add_action('register_form', 'register_role_custom');
  3.  
  4. function register_role_custom(){ ?>
  5.  
  6.     <input id="role" type="hidden" tabindex="0" size="0" value= "<?php if (isset($_GET['role'])){echo $_GET['role'];} ?>" name="role"/>
  7.  
  8. <?php
  9. }
  10.  
  11. add_action('user_register', 'custom_user_role');
  12.  
  13. function custom_user_role($user_id, $password="", $meta=array()) {
  14.  
  15.     $userdata = array();
  16.     $userdata['ID'] = $user_id;
  17.     $userdata['role'] = $_POST['role'];
  18.  
  19.     if (($userdata['role'] == "employer") or ($userdata['role'] == "candidate"))  {
  20.     wp_update_user($userdata);
  21.     }
  22. }
  23.  
  24. //2. Add validation. In this case, we make sure first_name is required.
  25. add_filter('registration_errors', 'custom_registration_errors', 10, 3);
  26. function custom_registration_errors ($errors, $sanitized_user_login, $user_email) {
  27.  
  28.     if (empty( $_POST['role'])){
  29.     $errors->add( 'no_role_error', __('<strong>ERROR</strong>: No Role Set in URL','mydomain') );
  30.     return $errors;
  31.     }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement