Using Pay Per View to Protect Groups of Custom Fields

Hello again all...

I begin a new post to hopefully alleviate confusion from previous threads on this topic. So far, I have not found a working solution, but feel I am close.

@arisath and @Michael Bissett are two who have been helping me in the past, so would appreciate their input if they have any. Also welcome anyone else who can help as well!

Here's the issue:

I'm trying to use the code given at the bottom of THIS PAGE to protect a grouping of custom fields and divs. I talked to @Michael Bissett in chat this morning and he assembled this code for me to try:

<?php
if ( function_exists( 'wpmudev_ppw_html' ) ) {
$html = '<div class="row top-spacer"><div class="col-md-8"><img class="img-responsive img-thumbnail" src="'.the_field('macro_map').'" /></div><div class="col-md-4"><h5>'. the_title() .'Resource Links</h5>'.the_field('symbol_news_links').'</div></div>'; // html code to be protected (required)
$id = 1; // An optional unique id if you are using the function more than once on a single page
$description = 'video'; // Optional description of the protected content
$price = '1.50'; // Optional price for a single view. If not set, price set in the post will be applied. If that is not set either, Unit Price in the Global Settings will be used.
echo wpmudev_ppw_html( $html, $id, $description, $price );
}
?>

<?php
function my_ppv_customization( ) {
global $ppw, $post;
if ( !is_object( $ppw ) || !is_object( $post ) ) return;
// Call this only for a post/page with ID 123. Change as required.
// If you omit this line, js and style files will be added to all of your pages and caching will be disabled. So it is recommended to keep and modify it for the pages you are using.
if ( $post->ID != 123 ) return;
$ppw->load_scripts_styles();
}
add_action( 'template_redirect', 'my_ppv_customization', 2 );
?>

I've been told it's important for me to note I am using the Advanced Custom Fields plug in instead of the core Wordpress functions. That is why "get_field" is in code as it's what ACF says to use.

Unfortunately the code above when copy/pasted into my template does not display correctly. I do not have errors, but the html does not render correctly. The img tags and < divs > are stripped.

I have attached two screenshots of the results. One is the visual results and the second is the code.

I am really on a tight deadline, so if I could get help on this quickly I would appreciate it so very much.

Thank you, God Bless...

  • Patrick

    Hey there @Running Alpha Admin

    Thanks for creating a new thread for this issue. I'll be sure to close any others that may still be open to prevent confusion.

    I believe the issue is in the concatenation of the tags & functions in the $html variable in your code.

    But it would take better eyes than mine to figure out exactly what to tweak. Perhaps my colleague @Vaughan could provide some insight here.

  • Running Alpha Admin

    @Vaughan Absolutely. I have attached the code.

    Update: attachment does seem to work. See below for page code:

    <?php get_header(); ?>
    <?php global $ppw; remove_filter( 'the_content', array( $ppw, 'content' ), 8 ); // Removes protection from post content. When changed to higher priotity doesnt work ?>
    
    <div class="container">
    <div class="row">
      <div class="col-md-12">
    
    <div class="row">
      <div class="col-md-9">
    
    		<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
          <article> 
    
    		<div class="post" id="post-<?php the_ID(); ?>">
    <div class="row"> <div class="col-md-12">	  <h2><?php the_title(); ?></h2> </div></div>
    
    <div class="row top-spacer">
      <div class="col-md-2">
       			<a class="pull-left" href="<?php echo the_permalink(); ?>">
    
                    <?php the_post_thumbnail('single-thumb', array('class' => 'img-thumbnail')); ?></a>
    
                    </div>
    
        <div class="col-md-10"><?php the_excerpt(); ?></div>    </div>
            <div class="row top-spacer">
      <div class="col-md-12">
      <!-- Symbol Table -->
    <div class="table-responsive">
      <table class="table">
     <thead><tr class="info"><th>Equity <span class="text-muted">(Symbol)</span></th><th>Bid Lines</th><th>Offering Lines</th><th>OPS <a href="#" data-toggle="tooltip" data-placement="top" title="Origin of Positive Sentiment"><small><span class="glyphicon glyphicon-info-sign"></span></small></a></th><th>Critical Mass Line</th></tr></thead>
    
     <tbody><tr class="grey"><td><!--Equity/Symbol--></td><td><table width="100%"><tr><td width="33%">1</td><td width="33%">2</td><td width="33%">3</td></tr></table></td><td><table width="100%"><tr><td>1</td><td>2</td><td>3</td></tr></table></td><td><!--OPS--></td><td><table width="100%"><tr><td>1</td><td>2</td><td>3</td></tr></table></td></tr>
    
    	<tr>
        <td>
      <?php the_title(); ?> <span class="text-muted">(<?php the_field('symbol'); ?>)</span>
    </td>
    
        	<td>
            <table width="100%">
                <tr><td width="33%"><p><span class="text-muted">$</span><?php the_field('bid_line_1'); ?></p></td><td width="33%"><p><span class="text-muted">$</span><?php the_field('bid_line_2'); ?></p></td><td width="33%"><p><span class="text-muted">$</span><?php the_field('bid_line_3'); ?></p></td></tr>   </table>
        </td>
    <td>
            <table width="100%">
                 <tr><td width="33%"><p><span class="text-muted">$</span><?php the_field('offering_line_1'); ?></p></td><td width="33%"><p><span class="text-muted">$</span><?php the_field('offering_line_2'); ?></p></td><td width="33%"><p><span class="text-muted">$</span><?php the_field('offering_line_3'); ?></p></td></tr>   </table>
        </td>
        <td><p><span class="text-muted">$</span><?php the_field('origin_of_positive_sentiment'); ?></p></td>
        <td> <table width="100%">
                <tr><td width="33%"><p><span class="text-muted">$</span><?php the_field('critical_mass_line_1'); ?></p></td><td width="33%"><p><span class="text-muted">$</span><?php the_field('critical_mass_line_2'); ?></p></td><td width="33%"><p><span class="text-muted">$</span><?php the_field('critical_mass_line_3'); ?></p></td></tr>   </table></td>
    
    </tr>
    </tbody>
    </table>
    </div>
    <!-- Symbol Table End-->
      </div>
      </div>
    
    <!--Level Shortcode Protection-->
    <?php
    global $post;
    echo do_shortcode('[level-leading100index]<div class="row top-spacer">
    <div class="col-md-12"> <p>'. $post->post_content . '</p> </div>
    </div>[/level-leading100index]'); ?>
    <!--Level Shortcode Protection-->
    
      <div class="row top-spacer"> 
    
        <div class="col-md-8"> <img class="img-responsive img-thumbnail" src="<?php the_field('macro_map'); ?>" /></div>
        <div class="col-md-4"> <h5> <?php the_title(); ?> Resource Links</h5><?php the_field('symbol_news_links'); ?></div>
        </div>
    
    <hr />
    <h2>Protected Content Below </h2>
    
    <!-- Testing ACF Shortcodes -->
      <div class="row top-spacer">
     <div class="col-md-8"><img class="img-responsive img-thumbnail" src="<?php echo do_shortcode( '[acf field="macro_map"]' ) ?>" /></div>
    
     <div class="col-md-4"> <h5> <?php the_title(); ?> Resource Links</h5><?php echo do_shortcode( '[acf field="symbol_news_links"]' ) ?></div>
        </div>
    
    <hr />
    <!-- Testing ACF Shortcodes --> 
    
    <!-- Pay Per View 1--> 
    
    <?php
    if ( function_exists( 'wpmudev_ppw_html' ) ) {
    $html = '<div class="row top-spacer"><div class="col-md-8"><img class="img-responsive img-thumbnail" src="'.the_field('macro_map').'" /></div><div class="col-md-4"><h5><?php the_title(); ?>Resource Links</h5>'.the_field('symbol_news_links').'</div></div>'; // html code to be protected (required)
    $id = 1; // An optional unique id if you are using the function more than once on a single page
    $description = 'video'; // Optional description of the protected content
    $price = '1.50'; // Optional price for a single view. If not set, price set in the post will be applied. If that is not set either, Unit Price in the Global Settings will be used.
    echo wpmudev_ppw_html( $html, $id, $description, $price );
    }
    ?>
    
    <?php
    function my_ppv_customization( ) {
    global $ppw, $post;
    if ( !is_object( $ppw ) || !is_object( $post ) ) return;
    // Call this only for a post/page with ID 123. Change as required.
    // If you omit this line, js and style files will be added to all of your pages and caching will be disabled. So it is recommended to keep and modify it for the pages you are using.
    if ( $post->ID != 123 ) return;
    $ppw->load_scripts_styles();
    }
    add_action( 'template_redirect', 'my_ppv_customization', 2 );
    ?> 
    
    <!-- Pay Per View 1-->  
    
    </article>
    	<?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
    
      </div> <!-- End col-md-9 -->
       <div class="col-md-3">
     <?php include("sidebar.php"); ?>
    
     </div>  <!-- End col-md-3 -->
    </div><!-- End row -->
    
    </div><!-- End Container -->
    <?php get_footer(); ?>
  • Running Alpha Admin

    Hi Again @Vaughan and @Patrick

    I THINK I have it working... it seems that way. I was actually working on another issue discussed at this link.

    I don't totally understand what @Vinod Dalvi was saying, but at the end he said switch the_field with get_field. So I thought maybe I could apply that logic to this case. When I switched those fields the images / links are rendered correctly, and when viewed as non-admin the pay per view button shows up :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.