Skip to content

Instantly share code, notes, and snippets.

@jack-arturo
Last active February 11, 2025 04:43
Show Gist options
  • Save jack-arturo/dc495409d0645cfd4b97ce678bcf8600 to your computer and use it in GitHub Desktop.
Save jack-arturo/dc495409d0645cfd4b97ce678bcf8600 to your computer and use it in GitHub Desktop.
EDD Account Customization Shortcodes
<?php
// Excuse the mess :D
// we also make use of the [purchase_history] and [edd_subscriptions] shortcodes
function edd_account_content_hook_licenses( $output ) {
ob_start();
?>
<?php $license_keys = edd_software_licensing()->get_license_keys_of_user(); ?>
<div class="edd-licenses">
<?php if ( $license_keys ) : ?>
<?php foreach ( $license_keys as $license ) : ?>
<div class="single-edd-license box-shadow">
<?php $payment_id = edd_software_licensing()->get_payment_id( $license->ID ); ?>
<h5 class="edd_sl_item_name" style="font-weight: bold; margin-bottom: 15px;">
<?php echo edd_software_licensing()->get_download_name( $license->ID ); ?>
<?php if ( $price_id = edd_software_licensing()->get_price_id( $license->ID ) ) : ?>
<span class="edd_sl_key_sep">&nbsp;&ndash;&nbsp;</span>
<span class="edd_sl_key_price_option"><?php echo edd_get_price_option_name( edd_software_licensing()->get_download_id( $license->ID ), $price_id ); ?></span>
<?php endif; ?>
</h5>
<span class="edd_sl_license_key_wrapper">
<input type="text" readonly="readonly" class="edd_sl_license_key" value="<?php echo esc_attr( edd_software_licensing()->get_license_key( $license->ID ) ); ?>" />
</span>
<table class="license-details">
<tr>
<td>
<span class="edd_sl_status_label"><?php _e( 'Status:', 'edd_sl' ); ?>&nbsp;</span>
<span class="edd_sl_license_status edd-sl-<?php echo edd_software_licensing()->get_license_status( $license->ID ); ?>">
<?php echo ucwords( edd_software_licensing()->get_license_status( $license->ID ) ); ?>
</span>
<div class="edd_sl_item_expiration">
<span class="edd_sl_expires_label edd_sl_expiries_label"><?php 'expired' === edd_software_licensing()->get_license_status( $license->ID ) ? _e( 'Expired:', 'edd_sl' ) : _e( 'Expires:', 'edd_sl' ); ?>&nbsp;</span>
<?php if ( edd_software_licensing()->is_lifetime_license( $license->ID ) ) : ?>
<?php _e( 'Never', 'edd_sl' ); ?>
<?php else : ?>
<?php echo date_i18n( 'F j, Y', edd_software_licensing()->get_license_expiration( $license->ID ) ); ?>
<?php endif; ?>
</div>
<span class="edd_sl_limit_label"><?php _e( 'Activations:', 'edd_sl' ); ?>&nbsp;</span>
<span class="edd_sl_limit_used"><?php echo edd_software_licensing()->get_site_count( $license->ID ); ?></span>
<span class="edd_sl_limit_sep">&nbsp;/&nbsp;</span>
<span class="edd_sl_limit_max"><?php echo edd_software_licensing()->license_limit( $license->ID ); ?></span>
</td>
<td class="right">
<?php if ( ! edd_software_licensing()->force_increase() ) : ?>
<a href="
<?php
echo esc_url(
add_query_arg(
array(
'license_id' => $license->ID,
'action' => 'manage_licenses',
'payment_id' => $payment_id,
),
get_permalink( edd_get_option( 'purchase_history_page' ) )
)
);
?>
"><?php _e( 'Manage Sites', 'edd_sl' ); ?></a>
<?php endif; ?>
<?php if ( edd_sl_license_has_upgrades( $license->ID ) && 'expired' !== edd_software_licensing()->get_license_status( $license->ID ) ) : ?>
<br />
<a href="
<?php
echo esc_url(
add_query_arg(
array(
'view' => 'upgrades',
'license_id' => $license->ID,
'action' => 'manage_licenses',
'payment_id' => $payment_id,
),
get_permalink( edd_get_option( 'purchase_history_page' ) )
)
);
?>
"><?php _e( 'View Upgrades', 'edd_sl' ); ?></a>
<?php elseif ( edd_sl_license_has_upgrades( $license->ID ) && 'expired' == edd_software_licensing()->get_license_status( $license->ID ) ) : ?>
<br />
<span class="edd_sl_no_upgrades"><?php _e( 'Renew to upgrade', 'edd_sl' ); ?></span>
<?php endif; ?>
<?php if ( edd_sl_renewals_allowed() ) : ?>
<?php if ( 'expired' === edd_software_licensing()->get_license_status( $license->ID ) ) : ?>
<br />
<a href="<?php echo edd_software_licensing()->get_renewal_url( $license->ID ); ?>" title="<?php esc_attr_e( 'Renew license', 'edd_sl' ); ?>"><?php _e( 'Renew license', 'edd_sl' ); ?></a>
<?php elseif ( ! edd_software_licensing()->is_lifetime_license( $license->ID ) && edd_software_licensing()->can_extend( $license->ID ) ) : ?>
<br />
<a href="<?php echo edd_software_licensing()->get_renewal_url( $license->ID ); ?>" title="<?php esc_attr_e( 'Extend license', 'edd_sl' ); ?>"><?php _e( 'Extend license', 'edd_sl' ); ?></a>
<?php endif; ?>
<?php endif; ?>
<br/>
<?php do_action( 'edd_sl_license_key_details', $license->ID ); ?>
</td>
</tr>
</table>
</div>
<?php endforeach; ?>
<?php else : ?>
<p>You currently have no licenses.</p>
<?php endif; ?>
</div>
<?php
return ob_get_clean();
}
add_shortcode( 'wpfusion_accounts_licenses', 'edd_account_content_hook_licenses' );
function edd_account_content_hook_downloads( $output ) {
ob_start();
?>
<?php $purchases = edd_get_users_purchases(); ?>
<?php if ( $purchases ) : ?>
<?php $key = edd_get_payment_key( $purchases[0]->ID ); ?>
<?php $purchase_data = edd_get_payment_meta( $purchases[0]->ID ); ?>
<?php $download_url = edd_get_download_file_url( $key, $purchase_data['email'], 0, 207 ); // third param is 0 when using the github updater, 1 when using normal ?>
<?php
// Check if active
$active = false;
$licenses = edd_software_licensing()->get_license_keys_of_user( get_current_user_id(), 207 );
foreach ( $licenses as $license ) {
if ( $license->get_display_status() == 'Active' || $license->get_display_status() == 'Inactive' ) {
$active = true;
}
}
?>
<br />
<a class="btn btn-action" href="<?php echo $download_url; ?>">Download WP Fusion <?php echo get_post_meta( 207, '_edd_sl_version', true ); ?></a>
<p style="margin: 10px 0 0"><a href="https://wpfusion.com/documentation/faq/changelog/">View Changelog</a></p>
<h3 class="downloads-header">Pro Addons</h3>
<!-- Check if eligible for Pro downloads -->
<?php $addons_enabled = false; ?>
<?php foreach ( $purchases as $purchase ) : ?>
<?php $purchase_data = edd_get_payment_meta( $purchase->ID ); ?>
<?php
if ( ! empty( $purchase_data['downloads'] ) && $purchase_data['downloads'][0]['options']['price_id'] != 1 ) {
$addons_enabled = true;}
?>
<?php endforeach; ?>
<?php if ( $addons_enabled == false ) : ?>
<div class="alert alert-info">Addons are available for Plus and Professional level license holders. You can click <strong>View Upgrades</strong> under your license key (above) to see upgrade options.</div>
<?php endif; ?>
<?php if ( $active == false ) : ?>
<div class="alert alert-info">Your license is inactive. Please renew your license to download plugins.</div>
<?php endif; ?>
<table id="edd-pro-addons" class="edd-table">
<thead>
<tr>
<th>Name</th>
<th>Version</th>
<th>Changelog</th>
<th>Download</th>
</tr>
</thead>
<?php
$addons = get_posts(
array(
'post_type' => 'download',
'posts_per_page' => 20,
'post_status' => 'private',
'download_category' => 'addons',
'order' => 'ASC',
)
);
?>
<?php foreach ( $addons as $addon ) : ?>
<tr>
<td><a href="<?php echo home_url(); ?>/documentation/#addons"><?php echo $addon->post_excerpt; ?></td>
<td><?php echo get_post_meta( $addon->ID, '_edd_sl_version', true ); ?></td>
<td><a href="<?php the_field( 'changelog_url', $addon->ID ); ?>">View Changelog</a></td>
<td>
<?php if ( $addons_enabled == true && $active == true ) : ?>
<a href="<?php echo home_url(); ?>/?edd_action=addon_download&addon=<?php echo $addon->ID; ?>">Download</a>
<?php else : ?>
<span class="addon-dash">&ndash;</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<?php
return ob_get_clean();
}
add_shortcode( 'wpfusion_accounts_download', 'edd_account_content_hook_downloads' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment