Skip to content

Instantly share code, notes, and snippets.

@bearded-avenger
Last active September 5, 2024 01:42
Show Gist options
  • Select an option

  • Save bearded-avenger/6323993 to your computer and use it in GitHub Desktop.

Select an option

Save bearded-avenger/6323993 to your computer and use it in GitHub Desktop.
Easy Digital Downloads - Changelog Shortcode (pass the EDD download ID and output a button that opens the changelog in a lightbox) - Completely un-styled and ready to abuse
/*
Use: [changelog id=""]
Atts: "id" is the id of the download in EDD
*/
add_shortcode('changelog','edd_changelog_sc'));
function edd_changelog_sc($atts,$content = null) {
$defaults = array(
'id' => '',
'label' => '+ Changelog',
'margintop' => '10%',
);
$atts = shortcode_atts($defaults,$atts);
?>
<style>
#changelog-sc-blackout {
display: none;
z-index: 1040;
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: #000;
opacity: 0.8;
}
#changelog {
display: none;
background: white;
z-index:1041;
width:594px;
position: absolute;
top: 0;
margin-left: auto;
margin-right:auto;
padding:20px;
box-sizing:border-box;
-webkit-box-shadow:0 0 4px rgba(0,0,0,0.6);
-moz-box-shadow:0 0 4px rgba(0,0,0,0.6);
box-shadow:0 0 4px rgba(0,0,0,0.6);
}
#changelog-sc {
margin-bottom:20px;
}
#changelog-sc-close {
z-index: 1042;
color: #333;
top: 7px;
right: 12px;
position: absolute;
font-size: 1.6em;
}
</style>
<script>
jQuery(document).ready(function(){
var div = jQuery('#changelog');
var wrap = jQuery('#changelog-sc');
var blackout = jQuery('#changelog-sc-blackout');
var close = jQuery('#changelog-sc-close');
jQuery(div).hide();
jQuery('.changelog-sc-trigger').click(function(e){
e.preventDefault();
jQuery(blackout).fadeIn().show();
jQuery(div).fadeIn().show();
});
jQuery(close).click(function(e){
e.preventDefault();
jQuery(div).fadeOut().hide();
jQuery(blackout).fadeOut().hide();
});
});
</script>
<?php
$changelog = get_post_meta( $atts['id'], '_edd_sl_changelog', true );
$out = sprintf('<a href="#changelog" class="changelog-sc-trigger">%s</a>',$atts['label']);
$out .= sprintf('<div id="changelog" style="margin-top:%s;"><a href="#"id="changelog-sc-close">&#215;</a>%s</div>',$atts['margintop'],apply_filters('the_content',$changelog));
return '<div class="changelog-sc">'.$out.'<div id="changelog-sc-blackout"></div></div>';
}
@SiteSpot

Copy link
Copy Markdown

Thanks!

@ruessyahoo

ruessyahoo commented Oct 19, 2020 •

Copy link
Copy Markdown

Great work! However, for those who are finding that the EDD Reviews plugin box is also added below the changelog content after popping up, change:
apply_filters('the_content',$changelog)
to just
$changelog

Also, if you want nice line breaks that match up to your changelog format, change:
$changelog = get_post_meta( $atts['id'], '_edd_sl_changelog', true );
to
$changelog = nl2br(get_post_meta( $atts['id'], '_edd_sl_changelog', true ));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment