Protect ACF added in a page's template under a membership

I am using a custom single.php with an ACF flexible content field. I only want to protect that, so basically I need a PHP version of the shortcode:

[ms-protect-content id="626"]some protected content[/ms-protect-content]

I've tried following solutions:

<?php echo do_shortcode( '[ms-protect-content id="626"]' ); ?>
<?php include (TEMPLATEPATH . '/inc/flex.php' ); ?>
<?php echo do_shortcode( '[/ms-protect-content]' ); ?>

But it doesn't work unfortunately, and I also tried:

<?php echo do_shortcode( '[ms-protect-content id="626"]'.include (TEMPLATEPATH . '/inc/flex.php' ).'[/ms-protect-content]' ); ?>

Which worked from the shortcode point of view, but not the include.

What PHP we need to add so we could use to protect one or multiple parts of the template from within the template file?

Please advise

  • Dimitris

    Hello there Marcus

    First of all, the use of
    <?php echo do_shortcode( '[/ms-protect-content]' ); ?>
    can't work, as do_shortcode() can't be split up in multiple lines.

    I tested in my end something like:

    <?php
    	$var = '<h1>TITLE</h1>';
    	echo do_shortcode( '[ms-protect-content]' . $var . '[/ms-protect-content]' );
    ?>

    and worked well, so it should be something in the template file that messes that.
    As long as this file returns plain HTML, it should be working good.

    Could you please try the following workaround instead?

    ob_start();
    include (TEMPLATEPATH . '/inc/flex.php' );
    $var = ob_get_clean();
    echo do_shortcode( '[ms-protect-content id="626"]' . $var . '[/ms-protect-content]' );

    Thank you,
    Dimitris :slight_smile:

  • Marcus

    Awesome ...that worked perfectly ...I can now protect specific content.

    I can't use the 'enable protection' option in the posts, as that disables the entire post from being seen and I want the header, titles, intro custom fields etc.

    In fact ..just in case it helps for the future, I am using ACF flexible content, so I had to duplicate that field group for protected content ....easier explained in this screencast: http://grab.mogmachine.com/1m1n1c2v0n0q

    Thanks again for your help.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.