WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Images only for registered (6 posts)

  1. mareczkos
    Member
    Posted 1 year ago #

    I`m using Page Restrict. I can hide posts and subpages.
    But i want add images (gallery) that are available for registered users.
    For example, if you are not registered user you can`t see this image http://www.marek.landuch.com/wp-content/uploads/2013/03/intro10.jpg, and you are automaticly forwarding to login panel

  2. Felix
    Member
    Posted 1 year ago #

    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

  3. mareczkos
    Member
    Posted 1 year ago #

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

  4. Felix
    Member
    Posted 1 year ago #

    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';
    
     }
    }
  5. bcworkz
    Member
    Posted 1 year ago #

    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.

  6. mareczkos
    Member
    Posted 1 year ago #

    thanks guys!!!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.