WordPress.org

Ready to get started?Download WordPress

Forums

Widget Logic
Only show widget to contributor role (3 posts)

  1. robansell
    Member
    Posted 1 year ago #

    Hi There

    What a great plugin - thank-you! Just one quick question, what would the logic code be if I just want to show a particular widget when a user with the "contributor role" is logged in?

    Your help would be much appreciated.

    Kind regards,
    Rob

    http://wordpress.org/plugins/widget-logic/

  2. robansell
    Member
    Posted 1 year ago #

    I think that I got it!

    current_user_can('level_1')

    Is this correct?

    Regards
    Rob

  3. alanft
    Member
    Plugin Author

    Posted 1 year ago #

    yep, that should work. But levels are on their way out. officially 'deprecated' meaning support will be dropped in a future WP release. I think the recommended way would be to use capabilities like

    current_user_can('edit_posts')

    which normally is true for contributors, authors, editors, admins etc. If you want to be specific you could tie it down to just contributors with

    current_user_can('edit_posts') && !current_user_can('edit_published_posts')

    Alternatively you could use this non-standard function appthemes_check_user_role() to check by named role
    http://docs.appthemes.com/tutorials/wordpress-check-user-role-function/

    Hope that helps

    http://codex.wordpress.org/Roles_and_Capabilities#Contributor

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.