there are many ways to do level based filtering - and it depends on what you want to do exactly, but basically you just need simple conditionals ( if - else
or if - then
or switch
statements ) again - depends on context.
if( current_user_can( 'level_10' ) ){
echo 'A - content for user level 10';
} elseif( current_user_can( 'level_8' ) ) {
echo 'B - content for user level 8 and above';
} elseif( current_user_can( 'level_6' ) ) {
echo 'C - content for user level 6 and above';
} // ok for wordpress < 3.0
/*
* Please read my note below regarding user levels to roles conversion
*/
if( current_user_can( 'manage_options' ) ){
echo 'A - content for user level Admin';
} elseif( current_user_can( 'publish_pages' ) ) {
echo 'B - content for user level Editor and above';
} elseif( current_user_can( 'publish_posts' ) ) {
echo 'C - content for user level Author and above';
} // ok for wordpress > 3.0
which will output totally different content for each user , but also means that user level 10 will NOT SEE the content of level 6.. ( unless you drop the else.. )
// when Admin logged
A - content for user level Admin
// when level editor and above logged
B - content for user level Editor and above
// when level author and above logged
C - content for user level Author and above
or
if( current_user_can( 'publish_posts' ) ){ // Author
echo 'A - content for Author and above';
if( current_user_can( 'publish_pages' ) ){ // Editor
echo 'B - Additional content for Editor and above';
if( current_user_can( 'manage_options' ) ){ // Administrator
echo 'C - Additional content for administrator ';
}
}
}
which will ADD output based on user levels - so user 10 see user 6
content PLUS user 8
content PLUS user 10
content
Put in plain human language example one will show content for level 10 OR content for level 8 OR ..
while example 2 will show content for level 10 AND content for level 8 AND
..
Like said before - there are many many ways to use it , but it all depends on context .
Note : Since wp 3.0 the user_level system was deprecated . you will need to filter by Capabilities using the user level to role Conversion system
..
if( current_user_can( 'administrator' ) ){} // only if administrator
if( current_user_can( 'editor' ) ){} // only if editor
if( current_user_can( 'author' ) ){} // only if author
if( current_user_can( 'contributor' ) ){} // only if contributor
if( current_user_can( 'subscriber' ) ){} // only if subscriber