Hallo,
ich habe ein kleines, großes Problem.
Ich habe mit 2 Extrafelder für die Benutzerprofile angelegt. Das funktioniert auch alles prima.
Nur möchte ich, das nur der Administrator die Felder sehen und ändern kann. Dies habe ich mit
if( current_user_can( 'administrator' ) ){ Felder }
realisiert.
Jetzt erscheinen die Felder nur beim Admin. Dieser kann sie ändern und die Änderungen weden gespeichert, alles super.
Wenn sich nun aber ein Benutzer einloggt. Da sieht er die Felder nicht. Und wenn er jetzt sein Profil speichert werden die Werte wieder zurückgesetzt. Das soll natürlich nicht so sein.
Hier mal mein Plugin:
<?php
function fb_add_custom_user_profile_fields( $user ) {
if( current_user_can( 'administrator' ) ){
?>
<h3>
<?php _e('Extra Profile Information', 'Avenue'); ?>
</h3>
<table class="form-table">
<tr>
<th><label for="Mitarbeiter Status">
<?php _e('Employee status', 'Avenue'); ?>
</label></th>
<td><select name="mhqstatus" id="mhqstatus" class="regular-text">
<option value="1" <?php selected( esc_attr( get_the_author_meta( 'mhqstatus', $user->ID ) ), '1' ); ?>>offline</option>
<option value="2" <?php selected( esc_attr( get_the_author_meta( 'mhqstatus', $user->ID ) ), '2' ); ?>>online</option>
</select>
<span class="description">
<?php _e('Please choose the status.', 'Avenue'); ?>
</span></td>
</tr>
<tr>
<th><label for="Mitarbeiter Aufgabe">
<?php _e('Employee task', 'Avenue'); ?>
</label></th>
<td><select name="mhqtask" id="mhqtask" class="regular-text">
<option value="1" <?php selected( esc_attr( get_the_author_meta( 'mhqtask', $user->ID ) ), '1' ); ?>>Gast</option>
<option value="2" <?php selected( esc_attr( get_the_author_meta( 'mhqtask', $user->ID ) ), '2' ); ?>>Redaktion</option>
<option value="3" <?php selected( esc_attr( get_the_author_meta( 'mhqtask', $user->ID ) ), '3' ); ?>>Fotos</option>
<option value="4" <?php selected( esc_attr( get_the_author_meta( 'mhqtask', $user->ID ) ), '4' ); ?>>Redaktion & Fotos</option>
</select>
<span class="description">
<?php _e('Please choose the task.', 'Avenue'); ?>
</span></td>
</tr>
</table>
<?php } }
function fb_save_custom_user_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return FALSE;
update_usermeta( $user_id, 'mhqstatus', $_POST['mhqstatus'] );
update_usermeta( $user_id, 'mhqtask', $_POST['mhqtask'] );
}
add_action( 'show_user_profile', 'fb_add_custom_user_profile_fields' );
add_action( 'edit_user_profile', 'fb_add_custom_user_profile_fields' );
add_action( 'personal_options_update', 'fb_save_custom_user_profile_fields' );
add_action( 'edit_user_profile_update', 'fb_save_custom_user_profile_fields' );
?>
Alles anzeigen
Ich hoffe es kann mir jemand helfen,
derDenis