The Situation
Say you use the Software Licensing add-on for Easy Digital Downloads, and that you’re selling digital products that are not for WordPress (Software Licensing can parse readme files for WordPress downloads). Since you cannot choose to have Software Licensing parse a readme file to display a change log, you may be using the Change Log field to display a list of changes. The code in this post will allow you to display your change log, saved to the Change Log field, in your posts. It creates a shortcode that will pull the Change Log field for a given EDD download. I covered the process of creating a shortcode to pull custom field data in greater extent if you’re interested.
The Code
This shortcode grabs and returns the content of the _edd_sl_changelog custom field for an EDD product with the ID of whatever you pass in. For example: [edd_changelog download_id="0000"]
. Just remember to change 0000 to the appropriate ID.
<?php //* Mind this opening PHP tag | |
/** | |
* This snippet creates a shortcode that renders the content of a | |
* licensed download/product's change log in Easy Digital Downloads. | |
* | |
* Example: [edd_changelog download_id="0000"] (replace 0000 with the ID of a download post) | |
* | |
* @author Ren Ventura <EngageWP.com> | |
* @link https://www.engagewp.com/include-easy-digital-downloads-software-licensing-change-logs-posts/ | |
*/ | |
// Change Log Content | |
add_shortcode( 'edd_changelog', 'edd_changelog_callback' ); | |
function edd_changelog_callback( $atts ) { | |
// Available attributes | |
$shortcode_atts = array( | |
'download_id' => 0, | |
); | |
$shortcode_atts = shortcode_atts( $shortcode_atts, $atts ); | |
// Extract each att to a variable | |
extract( $shortcode_atts ); | |
// Return the changelog data | |
return get_post_meta( $download_id, '_edd_sl_changelog', true ); | |
} |
Leave a Reply