Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #16676

    Hello, I was wondering if there is a way to password protect pages with a dynamic template in them. I can add a password to the page but when I go onto that page, it goes through and does not really block anything. I have a client that is selling photos and he needs to be able to add passwords to pages for his pictures he is selling. Any help would be great for this, thank you so much. Also, I am using the Abundance theme as well. Thanks!

    #92435

    Hi dont4getdustin,

    I’m not sure how to do this customization. Let me tag the rest of the support.

    Regards,

    Ismael

    #92436

    Open up includes/helper-templates.php and replace following code (basically the entire post_page element function):

    function post_page($element)
    {
    extract($element['saved_value'][0]);
    $output = "";

    switch($dynamic_which_post_page)
    {
    case'post': $query_id = $dynamic_post_id; $type ='post'; break;
    case'page': $query_id = $dynamic_page_id; $type ='page'; break;
    case'self': $query_id = $this->post_id; $type = get_post_type( $this->post_id ); break;
    }

    $query_post = array( 'p' => $query_id, 'posts_per_page'=>1, 'post_type'=> $type );
    $additional_loop = new WP_Query($query_post);

    if($additional_loop->have_posts())
    {
    $output .= "<div class='post-entry post-entry-dynamic '>";
    $output .= "<div class='entry-content'>";

    while ($additional_loop->have_posts())
    {
    $additional_loop->the_post();

    if($dynamic_which_post_page != 'self' && $query_id != $this->post_id)
    {
    global $more;
    $more = 0;
    }

    if($dynamic_which_post_page_title == 'yes')
    {
    $output .= "<h1 class='post-title'>".get_the_title()."</h1>";
    }

    if(!$additional_loop->post->post_excerpt || $query_id == $this->post_id)
    {
    $content = get_the_content('<span class="inner_more">'.__('Read more →','avia_framework').'</span>');
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]>', $content);
    }
    else
    {
    $content = apply_filters('the_excerpt', get_the_excerpt());
    $content .= '<p><a class="more-link" href="'. get_permalink().'"><span class="inner_more">'.__('Read more →','avia_framework').'</span></a></p>';
    }

    $output.= $content;
    $contact_page_id = avia_get_option('email_page');

    //wpml prepared
    if (function_exists('icl_object_id'))
    {
    $contact_page_id = icl_object_id($contact_page_id, 'page', true);
    }

    if($contact_page_id == $query_id)
    {
    ob_start();
    get_template_part( 'includes/contact-form' );
    $output .= ob_get_contents() ;
    ob_end_clean();
    }
    }

    $output .= "</div></div>";
    }

    wp_reset_query();

    return $output;
    }

    with:

    function post_page($element)
    {
    extract($element['saved_value'][0]);
    $output = "";

    switch($dynamic_which_post_page)
    {
    case'post': $query_id = $dynamic_post_id; $type ='post'; break;
    case'page': $query_id = $dynamic_page_id; $type ='page'; break;
    case'self': $query_id = $this->post_id; $type = get_post_type( $this->post_id ); break;
    }

    $query_post = array( 'p' => $query_id, 'posts_per_page'=>1, 'post_type'=> $type );
    $additional_loop = new WP_Query($query_post);

    if($additional_loop->have_posts())
    {
    $output .= "<div class='post-entry post-entry-dynamic '>";
    $output .= "<div class='entry-content'>";

    while ($additional_loop->have_posts())
    {
    $additional_loop->the_post();

    if($dynamic_which_post_page != 'self' && $query_id != $this->post_id)
    {
    global $more;
    $more = 0;
    }

    if(!post_password_required())
    {
    if($dynamic_which_post_page_title == 'yes')
    {
    $output .= "<h1 class='post-title'>".get_the_title()."</h1>";
    }

    if(!$additional_loop->post->post_excerpt || $query_id == $this->post_id)
    {
    $content = get_the_content('<span class="inner_more">'.__('Read more →','avia_framework').'</span>');
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]>', $content);
    }
    else
    {
    $content = apply_filters('the_excerpt', get_the_excerpt());
    $content .= '<p><a class="more-link" href="'. get_permalink().'"><span class="inner_more">'.__('Read more →','avia_framework').'</span></a></p>';
    }

    $output.= $content;
    $contact_page_id = avia_get_option('email_page');

    //wpml prepared
    if (function_exists('icl_object_id'))
    {
    $contact_page_id = icl_object_id($contact_page_id, 'page', true);
    }

    if($contact_page_id == $query_id)
    {
    ob_start();
    get_template_part( 'includes/contact-form' );
    $output .= ob_get_contents() ;
    ob_end_clean();
    }
    }
    else
    {
    $output .= get_the_password_form();
    }
    }

    $output .= "</div></div>";
    }

    wp_reset_query();

    return $output;
    }

    #92437

    Thanks for the help, I did update it but it did not work. I put a password on the page with the dynamic template on it but when I went to the page, it went on through without having to put a password in there. Is there another step that I should do to that?

    #92438

    Hi,

    Dude’s code works for me. What are the elements of your template?

    Please try clearing all cookies and cache or use a different browser because the first time around I tested it without the template and entered a password, so when I added the template for the second test, at first it didn’t show the password field, but once I cleared the cookies, the password field showed up again.

    Also when switching between the code window and Dude’s pasted code make sure you are grabbing the second block of code and not the first (another mistake I frequently made).

    Thanks,

    Nick

    #92439

    I deleted my cookies and catches and still nothing. I have a page that I am selling a product from a category so I made a page with a dynamic template to show only that category. Still, it goes through without the need to set a password. I also made sure that i selected the second line of text was what I changed it too as well.

    #92440

    Hey!

    I corrected the code above and replaced:

    echo get_the_password_form();

    with:

    $output .=  get_the_password_form();

    Please try it again.

    Regards,

    Peter

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Password protect for dynamic templates’ is closed to new replies.