Support » Plugin: p5 : Plenty of Perishable Passwords for Protected Posts » Need to protect a custom post type

  • Resolved mvmedia

    (@mvmedia)


    Hi Cyril,
    Great plugin thank you for your efforts.
    I am trying to protect a custom post type. the post type results in a download page for a pdf and it was created using advanced custom fields plugin that was built into the theme. It does not protect the pdf or ask for a password.
    However if I instead of linking to the pdf in the custom field, link to a page that is protected and add a link there it works great. the problem is I need it to work from the custom post type directly.
    Here is a link to the custom post type with a password but it doesn’t work. http://staging.f-squaredinvestments.com/type/product-materials/
    Thank you so much.
    Mary-Ellen

    https://wordpress.org/plugins/p5/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Cyril Batillat

    (@cyrilbatillat)

    Hi Mary-Ellen,

    Not sure to have completely understood your situation. Anyway, I can tell you some advices :

    – Direct links to files (eg http://staging.f-squaredinvestments.com/wp-content/uploads/2014/06/FSquared_StyleSlide_032114-5.pdf) can’t be protected by P5 plugin. The plugin can only protect posts, pages, or custom posts

    – For custom posts to be protected, be sure that your theme includes this function :

    if ( post_password_required() ) {
        [... here, your protected content ...]
    }

    mvmedia

    (@mvmedia)

    Hi Cyril,
    thanks for getting back to me so soon. Sorry I was unclear.
    Here is the page that the custom post type is displayed on:
    http://staging.f-squaredinvestments.com/type/product-materials/
    if you click the title in the box that is displayed the result is a pdf download. But the box is a custom post type that has a link to the pdf but the link is not displayed the pdf itself is.
    I hope this is more clear.
    Thanks

    Plugin Author Cyril Batillat

    (@cyrilbatillat)

    Mary-Ellen,

    To protect the download link, please adjust the concerned template file :

    if ( post_password_required() ) {
        [here, the link to your PDF]
    } else {
        // Display password form
        echo get_the_password_form();
    }
    mvmedia

    (@mvmedia)

    I tried a couple of things with the above code and could not get it to work.
    here is the code that I have to work with:

    <div class=”single-download”>
    <? $url = get_field(‘resource_external_url’); ?>
    <?php $dl = get_field(‘resource_download’);

    if ($dl || $url) : ?>
    <span>” target=”_blank”>Download</span>
    <? endif; ?>

    Any ideas would be appreciated.
    Thanks so much.
    Mary-Ellen

    Plugin Author Cyril Batillat

    (@cyrilbatillat)

    Try something like this :

    <div class="single-download">
        <php
        $url = get_field('resource_external_url');
        $dl = get_field('resource_download');
        if ($dl || $url) :
            if ( post_password_required() ) {
                // Display password form
                echo get_the_password_form();
            } else {
                // [here, the link to your PDF]
                ?><a href="<?php $your_link_here ?>" target="_blank">Download</a><?php
            }
        endif; ?>
    </div>
    mvmedia

    (@mvmedia)

    Thanks for your help.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Need to protect a custom post type’ is closed to new replies.