diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2021-05-25 20:23:54 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2021-05-25 20:23:54 +0200 |
commit | 40fd00f9b5988690d09fb4f760577e54b51a9c5b (patch) | |
tree | a59229d7ee13eaf632b64bdbe630fd8b40426cbe /includes/admin/views | |
parent | 44ad0a77496b120eede51e60698e1caff093352c (diff) | |
download | gigologadmin-40fd00f9b5988690d09fb4f760577e54b51a9c5b.tar.gz gigologadmin-40fd00f9b5988690d09fb4f760577e54b51a9c5b.tar.bz2 gigologadmin-40fd00f9b5988690d09fb4f760577e54b51a9c5b.zip |
Refactor the AdminPage::get_user method.
No functional change, just trying to make sense of it.
Diffstat (limited to 'includes/admin/views')
-rw-r--r-- | includes/admin/views/giglog_admin_page.php | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index f84b497..7ae7628 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -49,21 +49,33 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { { $hf_user = wp_get_current_user(); $hf_username = $hf_user->user_login; + $users = array_map( + fn($usr) => $usr->user_login, + get_users( array( 'fields' => array( 'user_login' ) ) ) ); + + // This renders a user form, which we don't really use for anything + // other than to check which user (if any) the form was made for. + // Seems this could be done a bit simpler... + $userform = GiglogAdmin_AdminPage::returnuser($ctype, $cid); + $select = '<select name="'.$ctype.'">'; $select .= '<option value="">Please Select..</option>'; - $users = get_users( array( 'fields' => array( 'user_login' ) ) ); + foreach ( $users as $user ) { - $usr = $user->user_login; - $taken = strpos(GiglogAdmin_AdminPage::returnuser($ctype, $cid),$usr); - if($taken) $select .= '<option value="' .$usr. '" selected="selected">'.$usr; - else - { - $takenbyself = strpos(GiglogAdmin_AdminPage::returnuser($ctype, $cid),'name="unassignitem"'); - if($takenbyself && $usr==$hf_username) $select .= '<option value="' .$usr. '" selected="selected">'.$usr; - else - $select .= '<option value="'.$usr. '">'. $usr; + $taken = strpos($userform, $user); // != false if form contains $user + if($taken) { + $select .= '<option value="' .$user. '" selected="selected">'.$user; + } + else { + $takenbyself = strpos($userform, 'name="unassignitem"'); // != false if form is an unassign form + if($takenbyself && $user == $hf_username) { + $select .= '<option value="' .$user. '" selected="selected">'.$user; + } + else { + $select .= '<option value="'.$user. '">'. $user; + } $select .='</option>'; - } + } } $select .= '</select>'; return($select); |