Can is_user_logged_in be combined with jquery somehow to add/remove fields wrapped in a certain class?

More specifically:

  • I want to wrap the users' phone and email in class "private".
  • Then if the user viewing the page is logged in, they can see those two fields in the User Directory and on the User page.

I don't want to just hide these fields via 'display: none;' (since they'd still be in the source).

1 Answer 1


The way you suggest doing this, it won't ever be secure. If I understand you, just disabling Javascript would spoil the security.

What you'd need to do is run a script that uses an AJAX request to query for and then add data to the page, but only if the user is logged in. That would fail safe if Javascript were disabled.

However, that is also a very labor/server intensive way to do this. My suggestion would be to conditionally add the data to the page via PHP before the page is rendered at all.

  • Can you point me to how it's done (add the data before the page is rendered)? Thanks!
    – Phantasmix
    Apr 22, 2014 at 2:08
  • The only reason I mentioned jquery is because I found a similar topic here but with a simpler request (append a class). So, certainly not set on using jquery.
    – Phantasmix
    Apr 22, 2014 at 2:09
  • I don't know in what context this needs to work. What page? Where is the code you need to alter? Etc? If you can edit the question to provide the necessary details I'll see what I can do.
    – s_ha_dum
    Apr 22, 2014 at 2:29
  • Thank you, @s_ha_dum . I'm still figuring out the best way to display the user profiles. Once that's settled, I'll come back and update this post.
    – Phantasmix
    Apr 22, 2014 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.