Skip to content

Commit

Permalink
Generate renewal links.
Browse files Browse the repository at this point in the history
  • Loading branch information
devinsays committed Oct 2, 2014
1 parent 4526754 commit 8698735
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
54 changes: 43 additions & 11 deletions updater/theme-updater-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class EDD_Theme_Updater_Admin {
protected $theme_slug = null;
protected $version = null;
protected $author = null;
protected $download_id = null;
protected $renew_url = null;
protected $strings = null;

/**
Expand All @@ -32,19 +34,22 @@ function __construct( $config = array(), $strings = array() ) {
'item_name' => '',
'license' => '',
'version' => '',
'author' => ''
'author' => '',
'download_id' => '',
'renew_url' => ''
) );
extract( $config );

// Set config arguments
$this->remote_api_url = $remote_api_url;
$this->item_name = $item_name;
$this->theme_slug = sanitize_key( $theme_slug );
$this->version = $version;
$this->author = $author;

// Populate config version fallback
if ( '' == $version ) {
$this->remote_api_url = $config['remote_api_url'];
$this->item_name = $config['item_name'];
$this->theme_slug = sanitize_key( $config['theme_slug'] );
$this->version = $config['version'];
$this->author = $config['author'];
$this->download_id = $config['download_id'];
$this->renew_url = $config['renew_url'];

// Populate version fallback
if ( '' == $config['version'] ) {
$theme = wp_get_theme( $this->theme_slug );
$this->version = $theme->get( 'Version' );
}
Expand Down Expand Up @@ -291,6 +296,33 @@ function deactivate_license() {
}
}

/**
* Constructs a renewal link
*
* @since 1.0.0
*/
function get_renewal_link() {

// If a renewal link was passed in the config, use that
if ( '' != $this->renew_url ) {
return $this->renew_url;
}

// If download_id was passed in the config, a renewal link can be constructed
$license_key = trim( get_option( $this->theme_slug . '_license_key', false ) );
if ( '' != $this->download_id && $license_key ) {
$url = esc_url( $this->remote_api_url );
$url .= '/checkout/?edd_license_key=' . $license_key . '&download_id=' . $this->download_id;
return $url;
}

// Otherwise return the remote_api_url
return $this->remote_api_url;

}



/**
* Checks if a license action was submitted.
*
Expand Down Expand Up @@ -342,7 +374,7 @@ function check_license() {
$expires = false;
if ( isset( $license_data->expires ) ) {
$expires = date_i18n( get_option( 'date_format' ), strtotime( $license_data->expires ) );
$renew_link = '<a href="' . esc_url( $this->remote_api_url) . '">' . $strings['renew'] . '</a>';
$renew_link = '<a href="' . esc_url( $this->get_renewal_link() ) . '">' . $strings['renew'] . '</a>';
}

// Get site counts
Expand Down
5 changes: 3 additions & 2 deletions updater/theme-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
'item_name' => 'Theme Name', // Name of theme
'theme_slug' => 'theme-slug', // Theme slug
'version' => '1.0.0', // The current version of this theme
'author' => 'Easy Digital Downloads' // The author of this theme
'author' => 'Easy Digital Downloads', // The author of this theme
'download_id' => '', // Optional, used for generating a license renewal link
'renew_url' => '' // Optional, allows for a custom license renewal link
),
// Strings should use theme textdomain
$strings = array(
'theme-license' => __( 'Theme License', 'textdomain' ),
'enter-key' => __( 'Enter your theme license key.', 'textdomain' ),
Expand Down

0 comments on commit 8698735

Please sign in to comment.