awesomemotive / EDD-License-handler

License / updater handler for Easy Digital Downloads extensions
55 stars 29 forks source link

Make `class EDD_License` extendable #5

Closed michael-cannon closed 6 years ago

michael-cannon commented 11 years ago

I'd like to see the class EDD_License made more reusable so that we can easily adjust the method auto_updater update URL with our own. Then in turn, integrating EDD Software Licensing becomes really a quick affair.

To make class EDD_License extensible, I think simply changing private function auto_updater to protected function auto_updater will suffice. Then we can create simple extensions class with our own update URL.

Therefore, in then in my plugin I do…

include_once dirname( __FILE__ ) . '/lib/TWP_License_Handler.php';
$eddsr_license = new TWP_License( __FILE__, 'Testimonials Widget Premium', Testimonials_Widget_Premium::VERSION, 'Michael Cannon' );

File TWP_License_Handler.php looks like…

class TWP_License extends EDD_License {
        protected function auto_updater() {
            // Setup the updater
            $edd_updater = new EDD_SL_Plugin_Updater( 'https://example.com', $this->file, array(
                    'version'   => $this->version,
                    'license'   => $this->license,
                    'item_name' => $this->item_name,
                    'author'    => $this->author
                )
            );
        }
}
michael-cannon commented 11 years ago

Alternately, as I figure out from looking at ways to fork this and make it easier.

  1. Turn the update URL into a protected variable like protected $update_url = 'https://easydigitaldownloads.com';. Then in the private function auto_updater() we call $this->update_url instead.
  2. We do like 1, but add a 6th parameter to function __construct( $_file, $_item_name, $_version, $_author, $_optname = null ) as in function __construct( $_file, $_item_name, $_version, $_author, $_optname = null, $_update_url = 'https://easydigitaldownloads.com' ) or $_update_url = null.

At the end of day, I'm looking to make license key handling more consistent and reliable for Easy Digital Downloads premium plugins as well as reduce the amount of repeated coding.

pippinsplugins commented 11 years ago

Oh yeah, this is great!