• Resolved javanpa

    (@javanpa)


    I’ve added a membership plugin to my site (Paid Memberships Pro), and just about everything is working as expected. That being said, the featured video attached to a post still shows up on the page even if it is a protected page and the user isn’t logged in. I’m assuming that’s because the featured videos sit outside of the standard “content area” on the page. I have some shortcodes (or PHP code) that can be wrapped around the content in the theme but wanted to know what you thought the best way to go about this would be.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Theme Author Ben Sibley

    (@bensibley)

    Thanks for using Tracks!

    Does the plugin offer an alternate method for protecting content besides using shortcodes? For instance, an option to mark the post as private or make an entire post type private.

    Thread Starter javanpa

    (@javanpa)

    Ben,

    I ended up just using a redirect for now so the content of the post didn’t display at all. There wasn’t a clean way to do what I wanted from the membership side. That being said…

    I’m still looking in to a more elegant solution for manipulating the featured video. I’ve dug through the code and have found my way to the ct_tracks_pro_output_featured_video() function in licenses/functions/video.php. From everything I can tell, the hook on line 290 (add_filter( 'ct_tracks_featured_image', 'ct_tracks_pro_output_featured_video', 20 );) should be what supersedes the featured-image variable in ct_tracks_featured_image() in functions.php. I’ve tried adding an html comment just before the <div> tag in the featured-image variable but it just never seems to show up in my code.

    What am I missing? Where does the actual embed code for the featured video come from if not from that function? Ultimately I would like to wrap a membership checker around the featured video in the code but can’t seem to find where that final output comes from. If you could point me in a direction, that would be very helpful. Thanks.

    Jordan

    Theme Author Ben Sibley

    (@bensibley)

    At the end of the ct_tracks_pro_output_featured_video function, the $featured_image variable is set to contain the markup for the video, like this:

    $featured_image = '<div class="featured-video">' . wp_oembed_get( esc_url( $featured_video ) ) . '</div>';

    WordPress uses oEmbed for most video platforms, so the wp_oembed_get() function returns the markup that WP generates for us. You’ll want to wrap that line with the membership check function to control whether the video is output or not. If your check returns false, the Featured Image will be output instead – I hope that’s okay.

    Thread Starter javanpa

    (@javanpa)

    That’s what I thought should work, but for some reason it isn’t. This is my current modification to that function:

    function ct_tracks_pro_output_featured_video( $featured_image ){
    
    	if ( trim( get_option( 'ct_tracks_featured_videos_license_key_status' ) ) != 'valid' )
    		return $featured_image;
    
    	// get the post object
    	global $post;
    
    	// check for a featured video
    	$featured_video = get_post_meta( $post->ID, 'ct_tracks_video_key', true );
    
    	if( $featured_video ) {
    
    		// get the display setting (post or blog)
    		$display_blog = get_post_meta( $post->ID, 'ct_tracks_video_display_key', true );
    
    		// post and setting is post or both, or if the blog and setting is blog or both, or if a page
    		if(
    			( is_singular() && ( $display_blog == 'post' || $display_blog == 'both' ) )
    			|| ( ( is_home() || is_archive() || is_search() ) && ( $display_blog == 'blog' || $display_blog == 'both' ) )
    			|| is_singular('page')
    		) {
    			$featured_image = '<!-- Jordan Was Here --><div class="featured-video">' . wp_oembed_get( esc_url( $featured_video ) ) . '</div>';
    		}
    	}
    
    	return $featured_image;
    }

    When viewing a post that has a featured image, and that featured image is displayed, this is the html output of that section:

    <div class="post-1727 post type-post status-publish format-standard hentry category-member-podcasts pmpro-level-required pmpro-level-1 pmpro-has-access entry has-video full-without-featured odd excerpt-1">
    	<div class="featured-video"><iframe src="https://player.vimeo.com/video/263140521?app_id=122963" width="500" height="281" frameborder="0" title="Ep25 - MPLS Part 1" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>	<div class="entry-meta">
    			<span class="date">April 5, 2018</span>

    My modified $featured_image output is nowhere to be seen. Thoughts?

    Theme Author Ben Sibley

    (@bensibley)

    Maybe the HTML comment is getting filtered out? Can you try something more dramatic like this just to test it:

    $featured_image = 'Jordan Was Here';

    Although now that I think about it, I don’t think you’ll need to edit that string. You can do something like this instead:

    function ct_tracks_pro_output_featured_video( $featured_image ){
    
    	if ( trim( get_option( 'ct_tracks_featured_videos_license_key_status' ) ) != 'valid' )
    		return $featured_image;
    
    	// get the post object
    	global $post;
    
    	// check for a featured video
    	$featured_video = get_post_meta( $post->ID, 'ct_tracks_video_key', true );
    
    	if( $featured_video ) {
    
    		// get the display setting (post or blog)
    		$display_blog = get_post_meta( $post->ID, 'ct_tracks_video_display_key', true );
    
    		// post and setting is post or both, or if the blog and setting is blog or both, or if a page
    		if(
    			( is_singular() && ( $display_blog == 'post' || $display_blog == 'both' ) )
    			|| ( ( is_home() || is_archive() || is_search() ) && ( $display_blog == 'blog' || $display_blog == 'both' ) )
    			|| is_singular('page')
    		) {
    if ( is_user_logged_in() ) {
    			$featured_image = '<div class="featured-video">' . wp_oembed_get( esc_url( $featured_video ) ) . '</div>';
    }
    		}
    	}
    
    	return $featured_image;
    }

    In this code, we’re using is_user_logged_in() to check if the user is logged in and setting the Featured Image equal to the video if they are. Otherwise, we make no modification so the image is output instead (if there is one).

    I’m guessing your plugin has conditional checks available that are more advanced than is_user_logged_in(), but that is a good starting point.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Membership Plugin Not Protecting Featured Video’ is closed to new replies.