Advertisement
sysReboot

my-custom-functions.php for nicknames

Nov 28th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. <?php
  2. /**
  3. * Plugin Name: My Custom Functions
  4. * Plugin URI: http://yoursite.com
  5. * Description: This is an awesome custom plugin with functionality that I'd like to keep when switching things.
  6. * Author: Your Name
  7. * Author URI: http://yoursite.com
  8. * Version: 0.1.0
  9. */
  10.  
  11. /* Place custom code below this line. */
  12. add_action('personal_options_update', 'check_display_name');
  13. add_action('edit_user_profile_update', 'check_display_name');
  14. function check_display_name($user_id) {
  15. global $wpdb;
  16. $err['display'] = $wpdb->get_var($wpdb->prepare("SELECT COUNT(ID) FROM $wpdb->users WHERE display_name = %s AND ID <> %d", $_POST['display_name'], $_POST['user_id']));
  17. $err['nick'] = $wpdb->get_var($wpdb->prepare("SELECT COUNT(ID) FROM $wpdb->users as users, $wpdb->usermeta as meta WHERE users.ID = meta.user_id AND meta.meta_key = 'nickname' AND meta.meta_value = %s AND users.ID <> %d", $_POST['nickname'], $_POST['user_id']));
  18. foreach($err as $key => $e) {
  19. if($e >= 1) {
  20. $err[$key] = $_POST['username'];
  21. add_filter('user_profile_update_errors', "check_{$key}_field", 10, 3);
  22. }
  23. }
  24. }
  25. function check_display_field($errors, $update, $user) {
  26. $errors->add('display_name_error',__('Sorry, Display Name is already in use. It needs to be unique.'));
  27. return false;
  28. }
  29. function check_nick_field($errors, $update, $user) {
  30. $errors->add('display_nick_error',__('Sorry, Nickname is already in use. It needs to be unique.'));
  31. return false;
  32. }
  33. /* Place custom code above this line. */
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement