Skip to content

Commit

Permalink
Fix for compatibility with plugins that allow profile fields to be ed…
Browse files Browse the repository at this point in the history
…ited in the front-end when wp_dropdown_roles() is not available.
  • Loading branch information
benhuson committed Jul 1, 2014
1 parent 65e0cd5 commit 69af009
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions admin/expire-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function extra_user_profile_fields( $user ) {
<select name="expire_user_role" id="expire_user_role">
<?php
echo '<option value="">' . __( "Don't change role", 'expire-users' ) . '</option>';
wp_dropdown_roles( $expire_user->on_expire_default_to_role );
$this->dropdown_roles( $expire_user->on_expire_default_to_role );
?>
</select>
</td>
Expand Down Expand Up @@ -208,7 +208,9 @@ function extra_user_profile_fields( $user ) {
<?php
}
?>
<br /><a href="<?php echo admin_url( 'users.php?page=expire_users' ); ?>"><?php _e( 'View and configure messages', 'expire-users' ); ?></a>
<?php if ( is_admin() ) { ?>
<br /><a href="<?php echo admin_url( 'users.php?page=expire_users' ); ?>"><?php _e( 'View and configure messages', 'expire-users' ); ?></a>
<?php } ?>
</fieldset>
</td>
</tr>
Expand Down Expand Up @@ -309,4 +311,30 @@ function is_admin_screen( $screen_id ) {
return false;
}

/**
* Clone of wp_dropdown_roles()
*
* wp_dropdown_roles() is only available in the admin. Some plugins like "Theme My Login"
* allow for editing profile fields on the front end so we need this functionality available
* when not in the admin.
*
* @param string $selected slug for the role that should be already selected
*/
function dropdown_roles( $selected = false ) {
$p = '';
$r = '';

$editable_roles = array_reverse( get_editable_roles() );

foreach ( $editable_roles as $role => $details ) {
$name = translate_user_role( $details['name'] );
if ( $selected == $role ) {
$p = "<option selected='selected' value='" . esc_attr( $role ) . "'>$name</option>";
} else {
$r .= "<option value='" . esc_attr( $role ) . "'>$name</option>";
}
}
echo $p . $r;
}

}

0 comments on commit 69af009

Please sign in to comment.