Trouble with X and WordPress default Password Protection

Hello,

Been searching around quite a bit and I still can’t seem to figure this out. I have X theme running on a dev site, and we are trying to password protect one page http://developingtestserver.ca/painted/owners/ - great, shouldn’t be a problem right? However, it is running a modified template file - which if you’re curious, can be found at this dropbox link: https://www.dropbox.com/s/4nownd8vf23xrwz/template-blank-1.php?dl=0

The problem is that when I set the page to password protected within WordPress (as it is currently), it does not work and all the content can be viewed. Where am I going wrong? I feel like this is hopefully going to be obvious for someone who knows what they are doing.

I can confirm that setting other pages to password protected within Wordpress seems to have no issue. And the template file is just based off of one of the default templates with X that I wasn’t using for this build. I modified it so that I could use use some ACF functionality, hopefully that doesn’t push me beyond the scope of support.

Thanks so much for your time, it is greatly appreciated.

Hi @CapturingMoods,

Thanks for reaching out.

Wordpress password protected page should work regardless of the template. It works on top of them, perhaps you have internal caching on your site? I saw similar cases and it’s due to cache, it served the cached page (when it was still not protected).

And please provide your admin login credentials in the secure note and I’ll check if it happens on other pages.

Thanks!

Hi @Rad,

Thanks so much for your response! I have added a the login credentials in a secure note on the original post. I did check and confirm that the other pages work fine password protected; it’s just this one page that has issues.

Looking forward to any help you can provide, it’s greatly appreciated.

Hello @CapturingMoods,

I have checked your page template and the error is in your template. Of course, the contents will be displayed even if you have provided a password. You do not have any condition when to display the contents that’s why. To resolve your issue, please have your template updated and use this:

<?php
 
// =============================================================================
// VIEWS/INTEGRITY/TEMPLATE-BLANK-1.PHP (Container | Header, Footer)
// -----------------------------------------------------------------------------
// A blank page for creating unique layouts.
// =============================================================================
 
get_header();
 
?>
 
<div class="x-main full" role="main">
 
        <article id="post-452" class="post-452 page type-page status-publish hentry no-post-thumbnail">
 
			<div class="entry-content content">
 
 			
			<?php // If post password required and it doesn't match the cookie.
	        if ( post_password_required( $post ) ) :
	                return get_the_password_form( $post );
	        else : ?>	

				<div id="cs-content" class="cs-content" >
					<div class="e452-1 x-section" id="header-banner" >
						<div class="x-bg" aria-hidden="true" data-x-element="bg" >
							<div class="x-bg-layer-lower-image" style="background-image: url('http://developingtestserver.ca/painted/wp-content/uploads/2019/02/49-careers-hero.jpg'); background-repeat: no-repeat; background-position: bottom; background-size: cover;" ></div>
						</div>
						<div class="e452-2 x-container max width" >
							<div class="e452-3 x-column x-sm x-1-1" >
								<div class="e452-4 x-text" >
									<h1>Owners</h1>
									<p>Here you will find relevant uploads.</p>
								</div>
							</div>
						</div>
					</div>
					<div class="e452-5 x-section body-content2" >
						<div id="job-styles">
							<?php while ( have_posts() ) : the_post(); ?>
							<?php
				 
				          // check if the repeater field has rows of data
				          if( have_rows('posting') ):
				 
				              // loop through the rows of data
				              while ( have_rows('posting') ) : the_row();
				 
				                  // display a sub field value
				                  ?>
							<div class="e452-6 x-container max width floating-box" >
								<div class="e452-7 x-column x-sm x-1-1" >
									<div class="x-bg" aria-hidden="true" data-x-element="bg" ></div>
									<h1 style="font-size:200%;">
										<?php the_sub_field('title'); ?>
									</h1>
									<h2>Information:</h2>
									<p>
										<?php the_sub_field('blurb_info'); ?>
									</p>
									<a href="
										<?php the_sub_field('file-upload'); ?>">
										<div class="downloads-button">
											<p class="email-job">Download</p>
										</div>
									</a>
								</div>
							</div>
							<?php
				              endwhile;
				 
				          else :
				 
				              // no rows found
				 
				          endif;
				 
				          ?>
							<?php endwhile; ?>
						</div>
					</div>
				</div>

			<?php endif; ?>


			</div>
		</article>
</div>
 
 
 
<?php get_footer(); ?>

Please let us know how it goes.

Hi @RueNel,

Thanks so much for your response! This has helped move things along, I’m not very good with my understanding of WordPress. There is still an odd issue however:

The page now hides the content (yay!) but does not generate a password form. It is just blank under the header:
http://developingtestserver.ca/painted/owners/

As a test, I can confirm other pages work fine when password protected:
http://developingtestserver.ca/painted/amenities/

(btw the password for both pages is “password”)

Is it possible to provide further assistance?

Thanks so much for your time, I really appreciate your help.

Hi @CapturingMoods,

I check and can see you have incompatible versions of the theme and cornerstone. This could be the one causing the issue.

Please update your theme and cornerstone to latest versions.

X 6.5.4, Cornerstone 3.5.3

_

Remember to clear all caches when updating so that the code from the latest release is always in use. This will help you to avoid any potential errors.

_

Hope that helps

Hi @paul.r,

Thanks for your reply! I have now updated to the latest versions of X Theme, Cornerstone and Wordpress. The issue sadly still persists. Any other thoughts? I haven’t edited anything that should be effecting this…

Thanks so much for your time, it’s very much appreciated.

Hi @CapturingMoods,

I’ve figured out the issue. We shouldn’t return the get_the_password_form function, use echo instead:

if ( post_password_required() ) :
	                echo get_the_password_form();
	        else : ?>

The full code should be:

<?php

// =============================================================================
// VIEWS/INTEGRITY/TEMPLATE-BLANK-1.PHP (Container | Header, Footer)
// -----------------------------------------------------------------------------
// A blank page for creating unique layouts.
// =============================================================================

get_header();

?>

<div class="x-main full" role="main">

        <article id="post-452" class="post-452 page type-page status-publish hentry no-post-thumbnail">

			<div class="entry-content content">


			<?php // If post password required and it doesn't match the cookie.
	        if ( post_password_required() ) :
	                echo get_the_password_form();
	        else : ?>

				<div id="cs-content" class="cs-content" >
					<div class="e452-1 x-section" id="header-banner" >
						<div class="x-bg" aria-hidden="true" data-x-element="bg" >
							<div class="x-bg-layer-lower-image" style="background-image: url('http://developingtestserver.ca/painted/wp-content/uploads/2019/02/49-careers-hero.jpg'); background-repeat: no-repeat; background-position: bottom; background-size: cover;" ></div>
						</div>
						<div class="e452-2 x-container max width" >
							<div class="e452-3 x-column x-sm x-1-1" >
								<div class="e452-4 x-text" >
									<h1>Owners</h1>
									<p>Here you will find relevant uploads.</p>
								</div>
							</div>
						</div>
					</div>
					<div class="e452-5 x-section body-content2" >
						<div id="job-styles">
							<?php while ( have_posts() ) : the_post(); ?>
							<?php

				          // check if the repeater field has rows of data
				          if( have_rows('posting') ):

				              // loop through the rows of data
				              while ( have_rows('posting') ) : the_row();

				                  // display a sub field value
				                  ?>
							<div class="e452-6 x-container max width floating-box" >
								<div class="e452-7 x-column x-sm x-1-1" >
									<div class="x-bg" aria-hidden="true" data-x-element="bg" ></div>
									<h1 style="font-size:200%;">
										<?php the_sub_field('title'); ?>
									</h1>
									<h2>Information:</h2>
									<p>
										<?php the_sub_field('blurb_info'); ?>
									</p>
									<a href="
										<?php the_sub_field('file-upload'); ?>">
										<div class="downloads-button">
											<p class="email-job">Download</p>
										</div>
									</a>
								</div>
							</div>
							<?php
				              endwhile;

				          else :

				              // no rows found

				          endif;

				          ?>
							<?php endwhile; ?>
						</div>
					</div>
				</div>

			<?php endif; ?>


			</div>
		</article>
</div>



<?php get_footer(); ?>

For more information, please take a look at this:

https://developer.wordpress.org/reference/functions/get_the_password_form/

Regards!

Hi @thai,

That got it! Thanks so much for your help; everyone in this thread has been amazing. Thank you so much.

You’re more than welcome, glad we could help.

Cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.