Last active
September 3, 2016 02:31
-
-
Save joelstransky/48c79879f86ce40d995455ab8c0aa11e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="content-main"> | |
<?php | |
// check if the flexible content field has rows of data | |
if( have_rows('flexible_blocks') ): | |
// loop through the rows of data | |
while ( have_rows('flexible_blocks') ) : $row = the_row(); | |
switch (get_row_layout()) { | |
case 'inserted_content': | |
global $post; | |
$post = get_post( get_sub_field('inserted_item') ); | |
setup_postdata( $post ); | |
?> | |
<article <?php post_class(); ?>> | |
<div class="aggregate-main"> | |
<?php vpa_render_post_object( $post ); ?> | |
</div> | |
</article> | |
<?php | |
break; | |
default: | |
# code... | |
break; | |
} | |
endwhile; | |
else : | |
// no layouts found | |
endif; | |
?> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function vpa_render_post_object( $post ) { | |
if( apply_filters( 'dcdc/render_post_object/before', $post ) ) { | |
return; | |
} | |
setup_postdata( $post ); | |
get_template_part('templates/content', $post->post_type != 'post' ? $post->post_type : get_post_format($post)); | |
wp_reset_postdata(); | |
} | |
add_filter( 'dcdc/render_post_object/before', 'vpa_on_before_post_object' ); | |
function vpa_on_before_post_object( $post ) { | |
if ( ! vpa_is_approved( $post ) ) { | |
echo '<div class="well"><p>Sorry, you are not allowed to see ' . $post->post_title . '</p></div>'; | |
return true; | |
} | |
return false; | |
} | |
function vpa_is_approved( $post = null ) { | |
$_post = get_post( $post ); | |
global $vpa_levels; | |
$acf_level = get_field('access_level', $_post->ID); | |
if ( in_array((int)$acf_level, $vpa_levels)) { | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment