Browse Source

Illustratr: Add page password protection for portfolio page (#6013)

* Illustratr: Lint the code formatting for the incoming fix

* Illustratr: Add page password protection for portfolio items on the portfolio page
Wojtek Naruniec 3 years ago
parent
commit
c93241fb78
1 changed files with 67 additions and 50 deletions
  1. 67 50
      illustratr/page-templates/portfolio-page.php

+ 67 - 50
illustratr/page-templates/portfolio-page.php

@@ -10,35 +10,47 @@ get_header(); ?>
 	<div id="primary" class="content-area">
 		<main id="main" class="site-main" role="main">
 
-		<?php if ( ! get_theme_mod( 'illustratr_hide_portfolio_page_content' ) ) : ?>
-			<?php while ( have_posts() ) : the_post(); ?>
-
-				<?php if ( '' != get_the_post_thumbnail() ) : ?>
-					<div class="entry-thumbnail">
-						<?php the_post_thumbnail( 'illustratr-featured-image' ); ?>
-					</div><!-- .entry-thumbnail -->
-				<?php endif; ?>
-
+			<?php if ( post_password_required() ) : ?>
 				<?php the_title( '<header class="page-header"><h1 class="page-title">', '</h1></header>' ); ?>
-
 				<div class="page-content">
-					<?php
-						the_content();
-						wp_link_pages( array(
-							'before'      => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'illustratr' ) . '</span>',
-							'after'       => '</div>',
-							'link_before' => '<span>',
-							'link_after'  => '</span>',
-						) );
-					?>
+					<?php the_content(); ?>
 				</div><!-- .page-content -->
+			<?php else : ?>
 
-				<?php edit_post_link( __( 'Edit', 'illustratr' ), '<div class="entry-meta"><span class="edit-link">', '</span></div>' ); ?>
+				<?php if ( ! get_theme_mod( 'illustratr_hide_portfolio_page_content' ) ) : ?>
+					<?php
+					while ( have_posts() ) :
+						the_post();
+						?>
+
+						<?php if ( '' != get_the_post_thumbnail() ) : ?>
+						<div class="entry-thumbnail">
+							<?php the_post_thumbnail( 'illustratr-featured-image' ); ?>
+						</div><!-- .entry-thumbnail -->
+					<?php endif; ?>
+
+						<?php the_title( '<header class="page-header"><h1 class="page-title">', '</h1></header>' ); ?>
+
+					<div class="page-content">
+						<?php
+							the_content();
+							wp_link_pages(
+								array(
+									'before'      => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'illustratr' ) . '</span>',
+									'after'       => '</div>',
+									'link_before' => '<span>',
+									'link_after'  => '</span>',
+								)
+							);
+						?>
+					</div><!-- .page-content -->
 
-			<?php endwhile; // end of the loop. ?>
-		<?php endif; ?>
+						<?php edit_post_link( __( 'Edit', 'illustratr' ), '<div class="entry-meta"><span class="edit-link">', '</span></div>' ); ?>
 
-			<?php
+					<?php endwhile; // end of the loop. ?>
+				<?php endif; ?>
+
+				<?php
 				if ( get_query_var( 'paged' ) ) :
 					$paged = get_query_var( 'paged' );
 				elseif ( get_query_var( 'page' ) ) :
@@ -48,56 +60,61 @@ get_header(); ?>
 				endif;
 
 				$posts_per_page = get_option( 'jetpack_portfolio_posts_per_page', '10' );
-				$args = array(
+				$args           = array(
 					'post_type'      => 'jetpack-portfolio',
 					'posts_per_page' => $posts_per_page,
 					'paged'          => $paged,
 				);
-				$project_query = new WP_Query ( $args );
-				if ( post_type_exists( 'jetpack-portfolio' ) && $project_query -> have_posts() ) :
-			?>
+				$project_query  = new WP_Query( $args );
+				if ( post_type_exists( 'jetpack-portfolio' ) && $project_query->have_posts() ) :
+					?>
 
-				<div class="portfolio-wrapper">
+					<div class="portfolio-wrapper">
 
 					<?php /* Start the Loop */ ?>
-					<?php while ( $project_query -> have_posts() ) : $project_query -> the_post(); ?>
+						<?php
+						while ( $project_query->have_posts() ) :
+							$project_query->the_post();
+							?>
 
-						<?php get_template_part( 'content', 'portfolio' ); ?>
+							<?php get_template_part( 'content', 'portfolio' ); ?>
 
-					<?php endwhile; ?>
+						<?php endwhile; ?>
 
-				</div><!-- .portfolio-wrapper -->
+					</div><!-- .portfolio-wrapper -->
 
-				<?php
+					<?php
 					illustratr_paging_nav( $project_query->max_num_pages );
 					wp_reset_postdata();
-				?>
+					?>
 
-			<?php else : ?>
+				<?php else : ?>
 
-				<section class="no-results not-found">
-					<header class="page-header">
-						<h1 class="page-title"><?php _e( 'Nothing Found', 'illustratr' ); ?></h1>
-					</header><!-- .page-header -->
+					<section class="no-results not-found">
+						<header class="page-header">
+							<h1 class="page-title"><?php _e( 'Nothing Found', 'illustratr' ); ?></h1>
+						</header><!-- .page-header -->
 
-					<div class="page-content">
-						<?php if ( current_user_can( 'publish_posts' ) ) : ?>
+						<div class="page-content">
+							<?php if ( current_user_can( 'publish_posts' ) ) : ?>
 
-							<p><?php printf( __( 'Ready to publish your first project? <a href="%1$s">Get started here</a>.', 'illustratr' ), esc_url( admin_url( 'post-new.php?post_type=jetpack-portfolio' ) ) ); ?></p>
+								<p><?php printf( __( 'Ready to publish your first project? <a href="%1$s">Get started here</a>.', 'illustratr' ), esc_url( admin_url( 'post-new.php?post_type=jetpack-portfolio' ) ) ); ?></p>
 
-						<?php else : ?>
+							<?php else : ?>
 
-							<p><?php _e( 'It seems we can&rsquo;t find what you&rsquo;re looking for. Perhaps searching can help.', 'illustratr' ); ?></p>
-							<?php get_search_form(); ?>
+								<p><?php _e( 'It seems we can&rsquo;t find what you&rsquo;re looking for. Perhaps searching can help.', 'illustratr' ); ?></p>
+								<?php get_search_form(); ?>
 
-						<?php endif; ?>
-					</div><!-- .page-content -->
-				</section><!-- .no-results -->
+							<?php endif; ?>
+						</div><!-- .page-content -->
+					</section><!-- .no-results -->
+
+				<?php endif; ?>
 
-			<?php endif; ?>
+			<?php endif; // end post_password_required() ?>
 
 		</main><!-- #main -->
 	</div><!-- #primary -->
 
 <?php get_sidebar(); ?>
-<?php get_footer(); ?>
+<?php get_footer(); ?>