Display Custom Fields ONLY to Authenticated Users

Support General Display Custom Fields ONLY to Authenticated Users

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #35881
    TTI LicensingTTI Licensing
    Participant

    Is there a way to display a custom field only to authenticated users regardless of role? We have some fields in security docs that we would like to display to our employees but not to the world. Most of the other custom fields are OK for public display.

    For example:

    https://itrules.tti.tamu.edu/control/access-enforcement/

    In this doc, the Agency Implementation (in yellow) should only display to users that are authenticated (e.g., logged in).

    #35894
    Long NguyenLong Nguyen
    Moderator

    Hi David,

    Before outputting the field value, you can use the code to check if the user logged in or not or check the user role ...

    if ( is_user_logged_in() ) {
        echo rwmb_meta( 'field_id' );
    } else {
        echo 'Welcome, visitor!';
    }

    Read more on the documentation https://developer.wordpress.org/reference/functions/is_user_logged_in/

    #35929
    TTI LicensingTTI Licensing
    Participant

    If I created this in the custom field area of Metabox, where would this code go? Is there a place in the custom field to put php code?

    #35936
    Long NguyenLong Nguyen
    Moderator

    Hi David,

    The code is used to output the field value, you need to add it to the template file in the theme folder (for example). Read more on the documentation https://docs.metabox.io/displaying-fields-with-code/

    #35939
    TTI LicensingTTI Licensing
    Participant

    Got it. But I created the template with Elementor. Is there a template file created by Elementor and if so where is it? Or is the template stored in the database?

    #35946
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You might need to contact Elementor support to ask to implement the code to output the field value. Or refer to this documentation to create a custom shortcode and add it to Elementor builder.
    https://docs.metabox.io/extensions/meta-box-group/#outputing-group-with-page-builders

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.