WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display Link To Only Specific Role/Capability? (6 posts)

  1. jazfotodesign
    Member
    Posted 3 years ago #

    *Is there a way to display links by specific role or capabilities?*

    http://www.floridaicam.com/

    I have made user levels with User Role Editor

    I gave user role 'Year1' privileges to read and level_0 and 'Year2' privileges to read and level_1

    I'm using User Login Widget and I have edited the log out section to show links.

    I want to show different links to users at that specific role.

    This is the code where the links appear

    }else{
    
    	        global $userdata;
    
    	        if(isset($before_title)) echo $before_title;
    
    	    	echo "Welcome : ". $userdata->display_name;
    
    	        if(isset($after_title)) echo $after_title;
    
    		?>
    
    <form name="logoutform" id="logoutform" action="<?php echo site_url('wp-login.php?action=logout&redirect_to='.site_url('/index.php'), 'logout_post') ?>" method="post">
    
    	<ul><li><a href="http://www.floridaicam.org/student-access">myFICAM</a></li>
    
    <li><a href="http://www.floridaicam.com/calendar">Academic Calender</a></li>
    <br><br>
    	<li><a href="<?php echo wp_logout_url(site_url('index.php'));?>">LogOut</a></li></ul>
    
    </form>

    and this is the code I tried inserting where the break tags are but it shot out an error.

    <?php
    if ( current_user_can( 'level_0' ) ) { ?>
    link
    <?php } ?>

    *Is there a way to display links by specific role or capabilities?*

  2. jazfotodesign
    Member
    Posted 3 years ago #

    or just show different content on same page to different levels

  3. jazfotodesign
    Member
    Posted 3 years ago #

    bump

  4. jazfotodesign
    Member
    Posted 3 years ago #

    ended up using,

    <?php
    if(current_user_can('level_0')) : ?>
    <div class="messages">
    level 0 content
    </div>
    <?php endif; ?>
    
    <?php
    if(current_user_can('level_1')) : ?>
    <div class="messages">
    level 0 content
    </div>
    <?php endif; ?>
  5. nyckidd
    Member
    Posted 3 years ago #

    i used your code but it did not work...did you get a workaround ?

  6. jazfotodesign
    Member
    Posted 3 years ago #

    works fine, you will need user role editor to make user roles with just the levels you want, for example I made one with level_0 and level_1 as I only have 2 different types of roles. screenshot

    i'm working on plug-in for this to make user roles easily and shortcodes.

    <?php
    if(current_user_can('level_0')) : ?>
    level 0 content for user role 1
    <?php endif; ?>
    
    <?php
    if(current_user_can('level_1')) : ?>
    level 1 content for user role 2
    <?php endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic