Title: Documents behind login
Last modified: August 16, 2024

---

# Documents behind login

 *  Resolved [wilbert schaapman](https://wordpress.org/support/users/wilbertschaapmancom/)
 * (@wilbertschaapmancom)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/documents-behind-login/)
 * I have created a custom post type called “tijdschriften,” which displays PDFs.
   These PDFs need to be visible only to logged-in users. How can I correctly configure
   the rights in Pods to ensure that only authorized users can access the PDFs, 
   and that the links to the PDFs are not publicly accessible?
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fdocuments-behind-login%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Author [Jory Hogeveen](https://wordpress.org/support/users/keraweb/)
 * (@keraweb)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/documents-behind-login/#post-17956937)
 * Hi [@wilbertschaapmancom](https://wordpress.org/support/users/wilbertschaapmancom/)
 * Pods only has settings for visibility in the admin. In regards to the frontend
   you would need to create your own logic for this.
 * In case you use Pods blocks etc. you could use a helper function.
 * Only logged in users:
 *     ```wp-block-code
       function yourCustomHelperName( $value ) {    if ( ! is_user_logged_in() ) {        return '';    }    return $value;}
       ```
   
 * You can use this in any location where custom helpers are supported in Pods.
   
   See: [https://docs.pods.io/displaying-pods/magic-tags/#Passing_values_through_callbacks_and_filters](https://docs.pods.io/displaying-pods/magic-tags/#Passing_values_through_callbacks_and_filters)
 * How are you currently displaying these fields?
 * Cheers, Jory
    -  This reply was modified 2 years, 1 month ago by [Jory Hogeveen](https://wordpress.org/support/users/keraweb/).
 *  Thread Starter [wilbert schaapman](https://wordpress.org/support/users/wilbertschaapmancom/)
 * (@wilbertschaapmancom)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/documents-behind-login/#post-17956959)
 * I am using a page where i created a content grid, using beaver builder content
   grid.
   On this page the pdfs are shown.The page is only vissable for login users.
 *  Plugin Author [Jory Hogeveen](https://wordpress.org/support/users/keraweb/)
 * (@keraweb)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/documents-behind-login/#post-17957486)
 * Hi [@wilbertschaapmancom](https://wordpress.org/support/users/wilbertschaapmancom/)
 * Do you mean the PDF’s themselves are posts? Or are they fields from a post?
   Otherwise
   said: should the page not show any results at all for visitors or should it display
   the posts but without the PDF link?
 * If they are posts then you’d need to use custom PHP code or a plugin to restrict
   access. There are many membership/access plugins available, both free and premium.
 * If it’s just related to the page content (eg: custom fields) then my previous
   answer could help.
   Alternatively, since you use the Beaver Builder: the Beaver
   Themer allows conditionals per module/row: [https://docs.wpbeaverbuilder.com/beaver-themer/1.4/developer/conditional-logic-apis/](https://docs.wpbeaverbuilder.com/beaver-themer/1.4/developer/conditional-logic-apis/)
   This might also be an option to look at.
 * In any case, Pods doesn’t include a built in access management UI for it’s fields
   or content.
 * Cheers, Jory
 *  Plugin Support [pd](https://wordpress.org/support/users/pdclark/)
 * (@pdclark)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/documents-behind-login/#post-17958664)
 * In addition to Jory’s notes on the differences between hiding a link versus hiding
   access to a file — it’s notable that many of WordPress’s default behaviors for
   files cause files to be more likely to be published than not.
 * Plugins meant for the purpose of securing access to files may be a better fit,
   such as [https://wordpress.org/plugins/prevent-direct-access/](https://wordpress.org/plugins/prevent-direct-access/)
   or [https://wordpress.org/plugins/user-private-files/](https://wordpress.org/plugins/user-private-files/)
   or other similar solutions.
 * The key thing is that the WordPress Media Library is heavily geared towards publishing
   content. Plugins for private access take different approaches, such as limiting
   even the direct download links to a certain users for certain periods of time
   or hiding access from search engines.
 *  Thread Starter [wilbert schaapman](https://wordpress.org/support/users/wilbertschaapmancom/)
 * (@wilbertschaapmancom)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/documents-behind-login/#post-17961216)
 * Thank you for your tips. That was exactly my concern—the page was behind a login,
   but the links to the files are public.
 *  Thread Starter [wilbert schaapman](https://wordpress.org/support/users/wilbertschaapmancom/)
 * (@wilbertschaapmancom)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/documents-behind-login/#post-17961243)
 * [@keraweb](https://wordpress.org/support/users/keraweb/), how can i use the function
   to protect the file in my overview
 *     ```wp-block-code
       <a href="[pods]{@tijdschrift_pdf}[/pods]" target="blank"><div class="ws-tijdschriften">     <div class="ws-images">[wpbb post:featured_image size="medium" display="tag" linked="no"]</div>    <div class="ws-text">[wpbb post:title]</div></div></a>
       ```
   
 *  Plugin Support [pd](https://wordpress.org/support/users/pdclark/)
 * (@pdclark)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/documents-behind-login/#post-17963895)
 * Add a display callback function using a Code Snippets plugin, as a plugin file,
   or in the theme’s functions.php:
 *     ```wp-block-code
       <?php/** * Display a link to a file if a user is logged in. * The file URL will still be publicly accessible once known. */function link_if_logged_in( $file_url ) {    global $wp;    if ( empty( $file_url ) ) {        // If field is blank, output nothing.        return '';    }    if ( ! is_user_logged_in() ) {        // If user is logged out, link to login.        return sprintf(            '<a href="%s">Log in to download</a>',            wp_login_url(                add_query_arg( $wp->query_vars, site_url( $wp->request ) )            )        );    }    // If user is logged in, link to file.    return sprintf(        '<a href="%s" target="_blank">Download</a>',        esc_url( $file_url )    );
       ```
   
 * Authorize the function for use in templates by adding it to `Pods Admin > Settings
   > Display callbacks allowed`, e.g., `esc_attr,esc_html,link_if_logged_in`
 * Use the callback in a template:
 *     ```wp-block-code
       [pods]{@tijdschrift_pdf,link_if_logged_in}[/pods]
       ```
   
 * …will display:
    - Nothing if the field is blank.
    - A link to `/wp-login.php` with a redirect back to the current page if the 
      user is logged out.
    - A link to the file with text `Download`, opened in a new window using `_blank`
      if the user is logged in.
 *  Plugin Support [pd](https://wordpress.org/support/users/pdclark/)
 * (@pdclark)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/documents-behind-login/#post-17963929)
 * The same effect / similar function including the Beaver Builder shortcodes for
   image and title:
 *     ```wp-block-code
       [pods]{@tijdschrift_pdf,link_if_logged_in}[/pods]<?php/** * Display a link to a file if a user is logged in. * The file URL will still be publicly accessible once known. */function link_if_logged_in( $file_url ) {    global $wp;    if ( empty( $file_url ) ) {        // If field is blank, output nothing.        return '';    }    $image = apply_shortcodes( '[wpbb post:featured_image size="medium" display="tag" linked="no"]' );    $title = apply_shortcodes( '[wpbb post:title]' );    $template = <<<'LINK'<a href="%s" target="_blank">    <div class="ws-tijdschriften">         <div class="ws-images">%s</div>        <div class="ws-text">%s</div>    </div></a>LINK;    if ( ! is_user_logged_in() ) {        // If user is logged out, link to login.        return sprintf(            $template,            esc_url( wp_login_url( add_query_arg( $wp->query_vars, site_url( $wp->request ) ) ) ),            $image,            'Zum Herunterladen anmelden: ' . $title        );    }    // If user is logged in, link to file.    return sprintf(        $template,        esc_url( $file_url ),        $image,        'Herunterladen ' . $title    );}
       ```
   
 * …where usage would be:
 *     ```wp-block-code
       [pods]{@tijdschrift_pdf,link_if_logged_in}[/pods]
       ```
   

Viewing 8 replies - 1 through 8 (of 8 total)

 The topic ‘Documents behind login’ is closed to new replies.

 * ![](https://ps.w.org/pods/assets/icon.svg?rev=3286397)
 * [Pods - Custom Content Types and Fields](https://wordpress.org/plugins/pods/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/pods/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/pods/)
 * [Active Topics](https://wordpress.org/support/plugin/pods/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/pods/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/pods/reviews/)

 * 8 replies
 * 3 participants
 * Last reply from: [pd](https://wordpress.org/support/users/pdclark/)
 * Last activity: [2 years, 1 month ago](https://wordpress.org/support/topic/documents-behind-login/#post-17963929)
 * Status: resolved