• Resolved gcarnegie

    (@gcarnegie)


    I want to be able to add a column to tables which is ONLY viewable to certain user roles. The information isn’t super sensitive so I’m thinking the simplest way is just by manipulating the column width to zero or whatever, when a certain user role is detected.
    The functino for detecting the user role is straighforward and found on the web:
    function wcmo_get_current_user_roles() {
    if( is_user_logged_in() ) {
    $user = wp_get_current_user();
    $roles = ( array ) $user->roles;
    return $roles[0];
    } else {
    return array();
    }
    }
    but I’m unsure which php file contains the code which displays the table.

    Can you let me know which file to edit please?
    thanks
    Guy

Viewing 1 replies (of 1 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    Something similar is possible using a TablePress Extension that can hide rows/columns from logged-out visitors, see https://www.ads-software.com/support/topic/hiding-columns-based-on-users-being-logged-in/

    This could serve as foundation for a check as you plan it. You would just have to adjust the check for whether the user has the desired role (or better: If he has a certain capability, using the WordPress PHP function current_user_can(). This might even be easier and quicker.)

    Regards,
    Tobias

Viewing 1 replies (of 1 total)
  • The topic ‘show/hide columns based on user role’ is closed to new replies.