bb_profile_admin_form

The BuddyPress bb profile admin form function.

Description

bb_profile_admin_form( (int) $id = 0 ); 

Parameters (1)

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

Usage

  1. if ( !function_exists( 'bb_profile_admin_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_admin_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_admin_form( $id = 0 ) { 
  2. global $wp_roles, $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. $bb_current_id = bb_get_current_user_info( 'id' ); 
  11.  
  12. $profile_admin_keys = bb_get_profile_admin_keys(); 
  13. $assignable_caps = bb_get_assignable_caps(); 
  14. $required = false; 
  15.  
  16. $roles = $wp_roles->role_names; 
  17. $can_keep_gate = bb_current_user_can( 'keep_gate' ); 
  18.  
  19. // Keymasters can't demote themselves 
  20. if ( ( $bb_current_id == $user->ID && $can_keep_gate ) || ( isset( $user->capabilities ) && is_array( $user->capabilities ) && array_key_exists( 'keymaster', $user->capabilities ) && !$can_keep_gate ) ) { 
  21. $roles = array( 'keymaster' => $roles['keymaster'] ); 
  22. } elseif ( !$can_keep_gate ) { // only keymasters can promote others to keymaster status 
  23. unset($roles['keymaster']); 
  24.  
  25. $selected = array( 'inactive' => ' selected="selected"' ); 
  26. ?> 
  27. <table id="admininfo"> 
  28. <tr class='form-field<?php if ( in_array( 'role', $error_codes ) ) echo ' form-invaliderror; ?>'> 
  29. <th scope="row"> 
  30. <label for="admininfo_role"><?php _e('User Type'); ?></label> 
  31. <?php if ( in_array( 'role', $error_codes ) ) echo '<em>' . $errors->get_error_message( 'role' ) . '</em>'; ?> 
  32. </th> 
  33. <td> 
  34. <select id="admininfo_role" name="role"> 
  35. <?php 
  36. foreach( $roles as $r => $n ) { 
  37. if ( isset( $user->capabilities ) && is_array( $user->capabilities ) && array_key_exists( $r, $user->capabilities ) ) { 
  38. $selected['inactive'] = ''; 
  39. $selected[$r] = ' selected="selected"'; 
  40. } elseif ( $r !== 'inactive' ) { 
  41. $selected[$r] = ''; 
  42. ?> 
  43. <option value="<?php echo $r; ?>"<?php echo $selected[$r]; ?>><?php echo $n; ?></option> 
  44. <?php 
  45. ?> 
  46. </select> 
  47. </td> 
  48. </tr> 
  49. <?php 
  50. if (count($assignable_caps)) : 
  51. ?> 
  52. <tr class="extra-caps-row"> 
  53. <th scope="row"><?php _e('Allow this user to'); ?></th> 
  54. <td> 
  55. <?php 
  56. foreach( $assignable_caps as $cap => $label ) : 
  57. $name = esc_attr( $cap ); 
  58. $checked = ''; 
  59. if ( isset( $user->capabilities ) && is_array( $user->capabilities ) && array_key_exists( $cap, $user->capabilities ) ) { 
  60. $checked = ' checked="checked"'; 
  61. $label = esc_html( $label ); 
  62. ?> 
  63.  
  64. <label><input name="<?php echo $name; ?>" value="1" type="checkbox"<?php echo $checked; ?> /> <?php echo $label; ?></label><br /> 
  65.  
  66. <?php endforeach; ?> 
  67.  
  68. </td> 
  69. </tr> 
  70.  
  71. <?php 
  72. endif; 
  73.  
  74. if ( is_array($profile_admin_keys) ) : 
  75. foreach ( $profile_admin_keys as $key => $label ) : 
  76. if ( $label[0] ) { 
  77. $class = 'form-field form-required required'; 
  78. $required = true; 
  79. } else { 
  80. $class = 'form-field'; 
  81. $title = esc_attr( $label[1] ); 
  82.  
  83. $name = esc_attr( $key ); 
  84. $type = isset($label[2]) ? esc_attr( $label[2] ) : 'text'; 
  85.  
  86. $checked = false; 
  87. if ( in_array( $key, $error_codes ) ) { 
  88. $class .= ' form-invaliderror; 
  89. $data = $errors->get_error_data( $key ); 
  90. if ( 'checkbox' == $type ) { 
  91. if ( isset($data['data']) ) 
  92. $checked = $data['data']; 
  93. else 
  94. $checked = $_POST[$key]; 
  95. $value = $label[3]; 
  96. $checked = $checked == $value; 
  97. } else { 
  98. if ( isset($data['data']) ) 
  99. $value = $data['data']; 
  100. else 
  101. $value = $_POST[$key]; 
  102.  
  103. $message = esc_html( $errors->get_error_message( $key ) ); 
  104. $message = "<em>$message</em>"; 
  105. } else { 
  106. if ( 'checkbox' == $type ) { 
  107. $checked = $user->$key == $label[3] || $label[4] == $label[3]; 
  108. $value = $label[3]; 
  109. } else { 
  110. $value = isset($user->$key) ? $user->$key : ''; 
  111. $message = ''; 
  112.  
  113. $checked = $checked ? ' checked="checked"' : ''; 
  114. $value = esc_attr( $value ); 
  115.  
  116. ?> 
  117.  
  118. <tr class="<?php echo $class; ?>"> 
  119. <th scope="row"> 
  120. <label for="<?php echo $name; ?>"><?php echo $title ?></label> 
  121. <?php echo $message; ?> 
  122. </th> 
  123. <td> 
  124. <?php if ( 'checkbox' == $type && isset($label[5]) ) echo "<label for='$name'>"; ?> 
  125. <input name="<?php echo $name; ?>" id="<?php echo $name; ?>" type="<?php echo $type; ?>"<?php echo $checked; ?> value="<?php echo $value; ?>" /> 
  126. <?php if ( 'checkbox' == $type && isset($label[5]) ) echo esc_html( $label[5] ) . "</label>"; ?> 
  127. </td> 
  128. </tr> 
  129.  
  130. <?php endforeach; endif; // $profile_admin_keys; $profile_admin_keys ?> 
  131.  
  132. </table> 
  133.  
  134. <?php if ( $required ) : ?> 
  135. <p class="required-message"><?php _e('These items are <span class="required">required</span>.') ?></p> 
  136.  
  137. <?php endif; ?> 
  138. <p><?php _e('Inactive users can login and look around but not do anything. Blocked users just see a simpleerrormessage when they visit the site.'); ?></p> 
  139. <p><?php _e('<strong>Note</strong>: Blocking a user does <em>not</em> block any IP addresses.'); ?></p> 
  140. <?php