bb_profile_data_form

The BuddyPress bb profile data form function.

Description

bb_profile_data_form( (int) $id = 0 ); 

Parameters (1)

0. $id — Optional. (int)
The id.

Usage

  1. if ( !function_exists( 'bb_profile_data_form' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-template.php'; 
  3.  
  4. // The id. 
  5. $id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bb_profile_data_form($id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/bp-forums/bbpress/bb-includes/functions.bb-template.php  
  1. function bb_profile_data_form( $id = 0 ) { 
  2. global $errors; 
  3. if ( !$user = bb_get_user( bb_get_user_id( $id ) ) ) 
  4. return; 
  5.  
  6. if ( !bb_current_user_can( 'edit_user', $user->ID ) ) 
  7. return; 
  8.  
  9. $error_codes = $errors->get_error_codes(); 
  10. $profile_info_keys = bb_get_profile_info_keys(); 
  11. $required = false; 
  12. if ( in_array( 'delete', $error_codes ) ) 
  13. echo '<div class="form-invalid error">' . $errors->get_error_message( 'delete' ) . '</div>'; 
  14. ?> 
  15. <table id="userinfo"> 
  16. <?php 
  17. if ( is_array($profile_info_keys) ) : 
  18. $bb_current_id = bb_get_current_user_info( 'id' ); 
  19. foreach ( $profile_info_keys as $key => $label ) : 
  20. if ( $label[0] ) { 
  21. $class = 'form-field form-required required'; 
  22. $required = true; 
  23. } else { 
  24. $class = 'form-field'; 
  25. $title = esc_attr( $label[1] ); 
  26.  
  27. $name = esc_attr( $key ); 
  28. $type = isset($label[2]) ? esc_attr( $label[2] ) : 'text'; 
  29. if ( !in_array( $type, array( 'checkbox', 'file', 'hidden', 'image', 'password', 'radio', 'text' ) ) ) { 
  30. $type = 'text'; 
  31.  
  32. $checked = false; 
  33. if ( in_array( $key, $error_codes ) ) { 
  34. $class .= ' form-invaliderror; 
  35. $data = $errors->get_error_data( $key ); 
  36. if ( 'checkbox' == $type ) { 
  37. if ( isset($data['data']) ) 
  38. $checked = $data['data']; 
  39. else 
  40. $checked = $_POST[$key]; 
  41. $value = $label[3]; 
  42. $checked = $checked == $value; 
  43. } else { 
  44. if ( isset($data['data']) ) 
  45. $value = $data['data']; 
  46. else 
  47. $value = $_POST[$key]; 
  48.  
  49. $message = esc_html( $errors->get_error_message( $key ) ); 
  50. $message = "<em>$message</em>"; 
  51. } else { 
  52. if ( 'checkbox' == $type ) { 
  53. $checked = $user->$key == $label[3] || $label[4] == $label[3]; 
  54. $value = $label[3]; 
  55. } else { 
  56. $value = isset($user->$key) ? $user->$key : ''; 
  57. $message = ''; 
  58.  
  59. $checked = $checked ? ' checked="checked"' : ''; 
  60. $value = esc_attr( $value ); 
  61.  
  62. ?> 
  63.  
  64. <tr class="<?php echo $class; ?>"> 
  65. <th scope="row"> 
  66. <label for="<?php echo $name; ?>"><?php echo $title; ?></label> 
  67. <?php echo $message; ?> 
  68. </th> 
  69. <td> 
  70. <?php 
  71. if ($key == 'display_name') { 
  72. ?> 
  73. <select name="display_name" id="display_name"> 
  74. <?php 
  75. $public_display = array(); 
  76. $public_display['display_displayname'] = $user->display_name; 
  77. //$public_display['display_nickname'] = $user->nickname; 
  78. $public_display['display_username'] = $user->user_login; 
  79. if ( isset($user->first_name) ) { 
  80. $public_display['display_firstname'] = $user->first_name; 
  81. if ( isset($user->last_name) ) { 
  82. $public_display['display_firstlast'] = $user->first_name.' '.$user->last_name; 
  83. $public_display['display_lastfirst'] = $user->last_name.' '.$user->first_name; 
  84. if ( isset($user->last_name) ) 
  85. $public_display['display_lastname'] = $user->last_name; 
  86.  
  87. $public_display = array_unique(array_filter(array_map('trim', $public_display))); 
  88.  
  89. foreach($public_display as $id => $item) { 
  90. ?> 
  91. <option id="<?php echo esc_attr( $id ); ?>" value="<?php echo esc_attr( $item ); ?>"><?php echo esc_html( $item ); ?></option> 
  92. <?php 
  93. ?> 
  94. </select> 
  95. <?php 
  96. } else { 
  97. ?> 
  98. <?php if ( 'checkbox' == $type && isset($label[5]) ) echo '<label for="' . $name . '">'; ?> 
  99. <input name="<?php echo $name; ?>" id="<?php echo $name; ?>" type="<?php echo $type; ?>"<?php echo $checked; ?> value="<?php echo $value; ?>" /> 
  100. <?php if ( 'checkbox' == $type && isset($label[5]) ) echo esc_html( $label[5] ) . '</label>'; ?> 
  101. <?php 
  102. ?> 
  103. </td> 
  104. </tr> 
  105.  
  106. <?php endforeach; endif; // $profile_info_keys; $profile_info_keys ?> 
  107.  
  108. </table> 
  109.  
  110. <?php bb_nonce_field( 'edit-profile_' . $user->ID ); if ( $required ) : ?> 
  111.  
  112. <p class="required-message"><?php _e('These items are <span class="required">required</span>.') ?></p> 
  113.  
  114. <?php 
  115. endif;