• I am looking for a way to display certain content on the /user/ profile page based on the role of the user rather than the role of the person viewing it. Currently I see a way to set certain elements to hide or display based on the role of the viewer but I want to have public profiles that show to an person logged in or not and have different elements show if the user profile being viewed is one role and other elements if they are another role. Possible?

Viewing 2 replies - 16 through 17 (of 17 total)
  • That code you posted would work if correct for WP roles not UM user roles which are not the same thing. It’s also meaningless if not associated to a function filter or action.

    It is entirely possible to do what the OP wants without adding a line of code to WP. I have 3 roles running on my website (4 if you consider a guest one) and they can only see the sections of content that they have permissions for. The key is creating permissions (or capabilities).

    What I posted adds no code to WordPress. It’s taken from the codex. It doesn’t need anything special. For example, if one created a custom profile page with several table rows containing the fields, surrounding them with the opening and closing php braces of the conditional (if) will prevent them from being displayed t those not with the assigned role.

    I just tried it with roles and capabilities set by the Members plugin by Justin Tadlock, with no issues.

    current_user_can documentation: https://codex.wordpress.org/Function_Reference/current_user_can

Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘Display profile content based on role of user profile’ is closed to new replies.