WordPress.org

Support

Support » Plugins and Hacks » Hacks » [Resolved] Images only for registered

[Resolved] Images only for registered

Viewing 5 replies - 1 through 5 (of 5 total)
  • You can use this code to display content according to user levels in your theme:

    global $user_ID; if( $user_ID ) { if( current_user_can('level_10') ) {
    
     // stuff only level 10 users can see
    
     } else {
    
     // stuff everyone else can see
    
     }
    }

    level_10 targets page admins. For all user levels check this page:
    http://codex.wordpress.org/User_Levels

    To check if a user is simply restricted you should use level_0

    you don`t understand me.
    I want to block images not only text

    Well you can use that php snippet to do almost anything. Here is what it would look like if you want your image to only display to logged in users. Note that this will only work in your template and not for posted content

    global $user_ID; if( $user_ID ) { if( current_user_can('level_0') ) {
    
     echo '<img src="intro10.jpg">';
    
     } else {
    
     echo 'you have to be logged in to see this picture';
    
     }
    }
    Moderator bcworkz

    @bcworkz

    This recent thread may help:
    http://wordpress.org/support/topic/lock-down-media-files?replies=6

    Disclaimer: My first suggestion in this thread is embarrassingly stupid, but the rest of the thread is useful.

    @felix, the WordPress community is trying to migrate away from controlling access by Levels, and even Roles, in favor of capabilities. When providing examples, please try to illustrate the use of functions such as current_user_can() by passing a capability as a parameter rather than a level, which is in fact deprecated.

    thanks guys!!!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] Images only for registered’ is closed to new replies.
Skip to toolbar