Support » Plugins » Hacks » block content by User levels

  • Resolved greg_kaippert

    (@greg_kaippert)


    Good morning, folks! I need some help . I have three videos on my website. Necessary for the administrator to view all the client visualize only one, and the coach just one too. I’m using this little code below , but in the administrator can not view the video. And the shortcode ‘m inserting into an HTML section in my theme. When I login as administrator , instead of appearing all videos , it appears that I ‘m not allowed , ie is on the function of the shortcode for permission instead of picking up the shortcode to admin . Can anyone give such help there? If you have questions, explain better.

    ————————————————————
    /* shortcode para não cadastrados no site, esse funciona normal */

    add_shortcode( ‘visitante’, ‘shortcode_para_visitantes’ );

    function shortcode_para_visitantes( $atts, $content = null ) {
    if ( !is_user_logged_in() ) return ‘<p><span style=”font-size:20px;”>Você precisa estar cadastrado para mais informações.</span></p>’;
    }
    ————————————————————

    ————————————————————
    /*shortcode para membros administrador, esse que não está funcionando */

    add_shortcode( ‘miembro’, ‘shortcode_para_miembros’ );

    function shortcode_para_miembros( $atts, $content = null ) {
    if ( is_admin() && !is_null( $content ) )
    return $content;
    }
    ————————————————————

    ————————————————————
    /* shortcode para bloquear conteúdo para não administrador */

    add_shortcode( ‘permissao’, ‘shortcode_para_permissoes’ );

    function shortcode_para_permissoes( $atts, $content = null ) {
    if ( is_user_logged_in() && !is_admin() )
    return ‘<p><span style=”font-size:20px;”>Você não tem permissao para acesssar esse conteúdo.</span></p>’;
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    I think you are confused by the purpose of is_admin(). It has nothing to do with who is logged in, it returns true when the current page is on the back end. Thus for the front end it will be false for anyone, even admins.

    Instead use current_user_can(). Try to pass a capability to this function, not a role. You should certainly be able to identify a capability that only admin has. For a coach, if there is no unique capability right now, you could always assign a custom capability to the user or role.

    Thread Starter greg_kaippert

    (@greg_kaippert)

    Ok, that was it , I used current_user_can(‘administrator’). Thanks guy.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘block content by User levels’ is closed to new replies.