/class.profile.php

  1. <?php 
  2.  
  3.  
  4. /** 
  5. * GPAISRProfile class. 
  6. */ 
  7. class GPAISRProfile { 
  8.  
  9.  
  10. /** 
  11. * __construct function. 
  12. * 
  13. * @access public 
  14. * @return \GPAISRProfile 
  15. * @since 0.6 
  16. */ 
  17. function __construct() { 
  18.  
  19. // new user contact field 
  20. add_filter( 'user_contactmethods', array( &$this, 'user_contactmethods' ) ); 
  21.  
  22. add_action( 'init', array( &$this, 'upgrade' ) ); 
  23.  
  24. /** 
  25. * @since 0.7.2 
  26. * 
  27. * @param array $contact_methods 
  28. * 
  29. * @return array 
  30. */ 
  31. function user_contactmethods( $contact_methods ) { 
  32. $contact_methods['googleplus'] = __( 'Google+', 'gpaisr' ); 
  33. return $contact_methods; 
  34.  
  35. /** 
  36. * Will upgrade the user meta data 
  37. * 
  38. * @since 0.7.2 
  39. * 
  40. */ 
  41. function upgrade() { 
  42. if ( false === (bool) get_option( 'gpaisr_gplus_link_move', false ) ) { 
  43.  
  44. $users = get_users(); 
  45. foreach ( $users as $user ) { 
  46. $old_gplus_link = get_user_meta( $user->ID, 'gplus_link', true ); 
  47.  
  48. // check if there is a old gplus link. if not, continue 
  49. if ( empty( $old_gplus_link ) ) { 
  50. continue; 
  51.  
  52. $new_gplus_link = get_user_meta( $user->ID, 'googleplus', true ); 
  53.  
  54. // check if there is already a gplus link in the users meta (maybe from Yoast SEO Plugin). If yes, continue 
  55. if ( ! empty( $new_gplus_link ) ) { 
  56. continue; 
  57.  
  58. // alright. there is no gplus link, so add the new one ... 
  59. update_user_meta( $user->ID, 'googleplus', $old_gplus_link ); 
  60.  
  61. // ... and delete the old one 
  62. delete_user_meta( $user->ID, 'gplus_link' ); 
  63.  
  64. update_option( 'gpaisr_gplus_link_move', true ); 
  65.  
  66.  
  67.  
.