WordPress.org

Forums

hide text from users of a certain role (2 posts)

  1. TomJohnson
    Member
    Posted 1 year ago #

    I want to make it so users who are contributors see certain information, but users who are subscribers do not see the information. In other words, I want the text to be conditional based on the logged-in user.

    I can do this with styles, showing and hiding based on conditions. For example:


    <?php
    if ( current_user_can('contributor') ) {

    echo '<style>';
    echo '.internal {display:normal;}';
    echo '</style>';
    }

    elseif (current_user_can('subscriber')) {

    echo '<style>';
    echo '.internal {display:none;}';
    echo '</style>';
    }

    ?>

    However, if you look in the source, a subscriber can still see the hidden text.

    How do I remove code from even being processed server side?

  2. Mario Peshev
    Member
    Posted 1 year ago #

    What stops you from using the conditional statements around the content you want to display, instead of using it to display CSS changes only?

    I.e. use the current_user_can calls around the dynamic content that you need to display accordingly.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags