Hi guys,
I was wondering if someone could help me out here, basically I'm teaching myself php, and I'm not 100% sure how to do what i want.
I am using wordpress with my website, and I want to convert the $user_level variable into an actual level (moderator, subscriber etc). When logged into my website, the user's login details, such as avatar, username and user level are displayed.
Currently, if a user is set to be a 'subscriber', rather than display the string 'subscriber' next to their name, the number '0' is shown. wordpress used to work on a 0-10 heirarchy level, but now has swapped to titles. however, the user's level is still displayed as a number.
Capability Administrator Editor Author Contributor Subscriber
level_10 X
level_9 X
level_8 X
level_7 X
level_6 X
level_5 X
level_4 X
level_3 X
level_2 X
level_1 X
level_0 X
(table showing how level number relates to role)
Now my idea was to create an array in a separate php file, with the numerical level related to the index:
$usertitle[0] = subscriber;
$usertitle[1] = contributor;
$usertitle[2] = author;
$usertitle[3] = Editor;
$usertitle[4] = Editor;
$usertitle[5] = Editor;
$usertitle[6] = Editor;
$usertitle[7] = Editor;
$usertitle[8] = Administrator;
$usertitle[9] = Administrator;
$usertitle[10] = Administrator;
then write a function where the $user_level variable (the numerical level) is passed to the array and used as the index key, which will then return the role.
return($usertitle[$user_level]) <something like this
This is where i encouter my problem - i have no idea how to do this! i have never written my own function before, or used an array in php. whilst i know what i want to do - i dont have any idea of how!
Any help on this matter would be greatly appreciated! thanks for reading this far too!
Cheers,
LFitz