-
-
Save thefrosty/5496695 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Easy Digital Downloads - Variable Pricing License Activation Limits | |
Plugin URL: http://easydigitaldownloads.com/extension/ | |
Description: Limit the number of license activations permitted based on variable prices | |
Version: 1.0.3 | |
Author: Pippin Williamson | |
Author URI: http://pippinsplugins.com | |
Contributors: mordauk | |
*/ | |
if ( defined( 'WP_LOCAL_DEV' ) && WP_LOCAL_DEV ) { | |
function extendd_edd_license_array_debug() { | |
if ( isset( $_GET['edd-license'] ) && 'true' === $_GET['edd-license'] ) { | |
$license_id = 7936; | |
$download_id = 7819; | |
$purchase_id = get_post_meta( $license_id, '_edd_sl_payment_id', true ); | |
$purchase_details = edd_get_payment_meta_cart_details( $purchase_id ); | |
echo '<pre>' . print_r( $purchase_details, true ) . '</pre>'; | |
exit; | |
} | |
} | |
add_action( 'init', 'extendd_edd_license_array_debug' ); | |
} | |
function extendd_edd_sl_license_at_limit( $return = false, $license_id = 0, $limit = 0, $download_id = 0 ) { | |
$purchase_id = get_post_meta( $license_id, '_edd_sl_payment_id', true ); | |
// $purchase_date = new DateTime( get_post_field( 'post_date', $purchase_id ) ); | |
// $limit_date = new DateTime( '2012-01-01' ); | |
// if ( $purchase_date < $limit_date ) { | |
// licenses purchased before January 1, 2013 are unlimited | |
// return false; | |
// } | |
$purchase_details = edd_get_payment_meta_cart_details( $purchase_id ); | |
$price_id = false; | |
if ( !$purchase_details ) | |
return $return; | |
if ( defined( 'WP_LOCAL_DEV' ) && WP_LOCAL_DEV ) | |
wp_mail( 'afrostyy@gmail.com', '[EDD] licence limit debug', 'Full purchase details: <pre>' . print_r( $purchase_details, true ) . '<pre>' ); | |
$item = array(); | |
foreach( $purchase_details as $item ) { | |
if ( $item['id'] == $download_id ) { | |
if ( ! empty( $item['item_number']['options'] ) && ! empty( $item['item_number']['options']['price_id'] ) ) { | |
$price_id = (int) $item['item_number']['options']['price_id']; | |
} | |
} | |
} | |
if ( $price_id !== false ) { | |
switch( $price_id ) { | |
case 0: | |
$limit = 1; // single site license | |
break; | |
case 1: | |
$limit = 5; // up to 5 sites | |
break; | |
case 2: | |
$limit = 0; // unlimited | |
break; | |
} | |
$site_count = absint( get_post_meta( $license_id, '_edd_sl_site_count', true ) ); | |
// check to make sure a limit is in place | |
if ( $limit > 0 ) { | |
if ( $site_count >= absint( $limit ) ) { | |
$return = true; // license is at limit | |
} | |
} | |
} | |
return $return; | |
} | |
add_filter( 'edd_sl_license_at_limit', 'extendd_edd_sl_license_at_limit', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment