WordPress.org

Forums

Members
[resolved] Using Widget Logic to hide widget by Role (5 posts)

  1. Rhand
    Member
    Posted 3 years ago #

    using Members I created a new role. Now I want to show or hide certain widgets based on the WP Role. How do I do this?

    I tried if ( current_user_can( 'role' ) ) but it does not seem to work. This:

    <?php
    if ( current_user_can( 'energy' ) )
    echo "Yeah!" ;
    else
    echo "Nope";
    ?>

    does work in a PHP Widget only there the widget will be shown at all times, just with a different content. If I cannot use this code in Widget Logic with the Role created by Members I might have to go for simple PHP in a PHP widget. But in that case certain special widgets can no longer be used unless I add the code to the template.

    http://wordpress.org/extend/plugins/members/

  2. alanft
    Member
    Posted 3 years ago #

    for the widget logic just use

    current_user_can( 'role' )

  3. Rhand
    Member
    Posted 3 years ago #

    Thanks for that. Do believe widget logic requires a is_ ... doesn't it?

  4. alanft
    Member
    Posted 3 years ago #

    no it doesn't. where were you thinking of adding that?

  5. Rhand
    Member
    Posted 3 years ago #

    Well, I guess I just made a coding error then. As far as I understand now, all PHP will be accepted as long as it is properly coded, correct Alan?

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Members
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic