Home / Admin / Display Vendor-Submitted data as Restricted Content.
Duplicate Snippet

Embed Snippet on Your Site

Display Vendor-Submitted data as Restricted Content.

Automatically output content submitted by FES Vendors wrapped in the [edd_restrict] shortcode.

Code Preview
php
<?php
/**
 * This function demonstrates how to automatically display a field of content with the meta key 'my_prefix_restricted_content' (submitted 
 * through FES) to the content of the Product in question while wrapped in the edd_restrict shortcode.
 * Note: you can re-use this chunk for any field from your Submission form by swapping "my_prefix_restricted_content" with your field's custom meta_key.
 * An example of why you might use this: If you want to unlock/show a Vimeo/Youtube video only to customers who've purchased the product. 
 * For example, if you are setting up a video rental website, you could use this to display videos to customers after they purchase.
 *
 * To add a corresponding field to your Vendor Submission form, <br />
 * In EDD FES > Submission Form, add a field for the video URL with the meta_key set to "my_prefix_restricted_content".
 *
 * @since	1.0.0
 * @param	string $content The content that will be shown for this post.
 * @return	string $content The content that will be shown for this post.
 */
<?php
/*
 * Plugin Name: Easy Digital Downloads - Display Vendor-Submitted data as Restricted Content.
 * Description: Automatically output content submitted by FES Vendors wrapped in the [edd_restrict] shortcode.
 * Author: Phil Johnston
 * Author URI: https://easydigitaldownloads.com/
 * Version: 1.0
 */
/**
 * This function demonstrates how to automatically display a field of content with the meta key 'my_prefix_restricted_content' (submitted * through FES) to the content of the Product in question while wrapped in the edd_restrict shortcode.
 * Note: you can re-use this chunk for any field from your Submission form by swapping "my_prefix_restricted_content" with your field's custom meta_key.
 * An example of why you might use this: If you want to unlock/show a Vimeo/Youtube video only to customers who've purchased the product. 
 * For example, if you are setting up a video rental website, you could use this to display videos to customers after they purchase.
 * To add a corresponding field to your Vendor Submission form, <br />
 * In EDD FES > Submission Form, add a field for the video URL with the meta_key set to "my_prefix_restricted_content".
 *
 * @since	1.0.0
 * @param	string $content The content that will be shown for this post.
 * @return	string $content The content that will be shown for this post.
 */
function my_prefix_display_locked_video( $the_content ) {
	$id = get_the_ID();
	if ( 'download' !== get_post_type( $id ) ) {
		return $the_content;
	}
	$restricted_content = get_post_meta( $id, 'my_prefix_restricted_content', true );
	if ( ! $restricted_content ) {
		return $the_content;
	}
	
	$shortcode  = '[edd_restrict id="' . $id . '"]';
	$shortcode .= wp_oembed_get( $restricted_content );
	$shortcode .= '[/edd_restrict]';
	
	return $the_content . do_shortcode( $shortcode );
}
add_filter( 'the_content', 'my_prefix_display_locked_video' );

Comments

Add a Comment