Commit 8c7867bb authored by John James Jacoby's avatar John James Jacoby

Abstract out admin page, for theme plugins.

parent 478a58ef
......@@ -39,7 +39,7 @@ class Swifter_Theme_Updater_Admin extends Flox_Theme_Updater {
__( 'Swifter Licenses', 'swifter' ),
__( 'Swifter Licenses', 'swifter' ),
'manage_options',
$this->license(),
$this->admin_page,
array( $this, 'license_page' )
);
}
......
......@@ -27,6 +27,7 @@ class Flox_Licensed_Product {
protected $author = null;
protected $download_id = null;
protected $renew_url = null;
protected $admin_page = null;
/**
* Initialize the class
......@@ -41,17 +42,19 @@ class Flox_Licensed_Product {
'version' => '',
'author' => '',
'download_id' => '',
'renew_url' => ''
'renew_url' => '',
'admin_page' => ''
) );
// Set config arguments
$this->remote_api_url = esc_url_raw( $r['remote_api_url'] );
$this->slug = sanitize_key( $r['slug'] );
$this->name = urlencode( $r['name'] );
$this->name = $r['name'];
$this->version = $r['version'];
$this->author = $r['author'];
$this->download_id = $r['download_id'];
$this->renew_url = $r['renew_url'];
$this->admin_page = $r['admin_page'];
// Hooks
$this->init();
......@@ -110,7 +113,7 @@ class Flox_Licensed_Product {
$this->license(),
$this->name,
array( $this, 'license_section' ),
$this->license()
$this->admin_page
);
// Key field
......@@ -118,7 +121,7 @@ class Flox_Licensed_Product {
$this->license_key(),
__( 'License Key', 'flox' ),
array( $this, 'license_field' ),
$this->license(),
$this->admin_page,
$this->license(),
array()
);
......@@ -131,6 +134,11 @@ class Flox_Licensed_Product {
);
}
/**
* Stub license section method
*/
public function license_menu() {}
/**
* Stub license section method
*/
......@@ -211,7 +219,7 @@ class Flox_Licensed_Product {
$license_data = $this->get_api_response( array(
'edd_action' => 'activate_license',
'license' => $this->get_license(),
'item_name' => $this->name
'item_name' => urlencode( $this->name )
) );
// $response->license will be either "active" or "inactive"
......@@ -229,7 +237,7 @@ class Flox_Licensed_Product {
$license_data = $this->get_api_response( array(
'edd_action' => 'deactivate_license',
'license' => $this->get_license(),
'item_name' => $this->name
'item_name' => urlencode( $this->name )
) );
// $license_data->license will be either "deactivated" or "failed"
......@@ -281,7 +289,7 @@ class Flox_Licensed_Product {
$license_data = $this->get_api_response( array(
'edd_action' => 'check_license',
'license' => $this->get_license(),
'item_name' => $this->name,
'item_name' => urlencode( $this->name ),
'url' => home_url()
) );
......@@ -390,7 +398,7 @@ class Flox_Licensed_Product {
$update_data = $this->get_api_response( array(
'edd_action' => 'get_version',
'license' => $this->license,
'name' => $this->name,
'name' => urlencode( $this->name ),
'slug' => $this->slug,
'author' => $this->author
) );
......@@ -457,26 +465,56 @@ class Flox_Licensed_Product {
/** Option Keys ***********************************************************/
/**
* Return the license key
*
* @return string
*/
protected function license() {
return $this->slug . '_licenses';
}
/**
* Return the licence key key
*
* @return string
*/
protected function license_key() {
return $this->slug . '_license_key';
}
/**
* Return the transient nonce key
*
* @return string
*/
protected function transient_nonce_key() {
return $this->slug . '_item_nonce';
}
/**
* Return the transient message key
*
* @return string
*/
protected function transient_message_key() {
return $this->slug . '_license_message';
}
/**
* Return the transient response key
*
* @return string
*/
protected function transient_response_key() {
return $this->slug . '_update_response';
}
/**
* Return the status key
*
* @return string
*/
protected function status_key() {
return $this->slug . '_license_key_status';
}
......
......@@ -25,6 +25,16 @@ class Flox_Plugin_Updater extends Flox_Licensed_Product {
*/
protected $license = null;
/**
* @var string The name of the plugin loader file
*/
protected $plugin_file = null;
/**
* @var string The basename of the plugin
*/
protected $basename = null;
/**
* Construct & initialize the object
*
......@@ -35,10 +45,12 @@ class Flox_Plugin_Updater extends Flox_Licensed_Product {
parent::__construct( $args );
// Populate variables
$this->license = $this->get_license();
$this->license = $this->get_license();
$this->plugin_file = $args['plugin_file'];
$this->basename = plugin_basename( $this->plugin_file );
$this->slug = basename( $args['plugin_file'], '.php' );
$this->name = plugin_basename( $args['plugin_file'] );
// Override slug
//$this->slug = basename( $this->plugin_file, '.php' );
// Set up hooks.
$this->init();
......@@ -53,7 +65,7 @@ class Flox_Plugin_Updater extends Flox_Licensed_Product {
add_action( 'load-update-core.php', array( $this, 'delete_update_transient' ) );
add_action( 'load-plugins.php', array( $this, 'delete_update_transient' ) );
add_action( 'load-plugins.php', array( $this, 'load_plugins_screen' ) );
add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ) );
add_action( 'after_plugin_row_' . $this->basename, array( $this, 'show_update_notification' ) );
add_action( 'admin_init', array( $this, 'show_changelog' ) );
// Filters
......@@ -64,6 +76,18 @@ class Flox_Plugin_Updater extends Flox_Licensed_Product {
add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
}
/**
* Handle a few things when the themes page is loaded
*/
public function load_plugins_screen() {
// Ensure thickbox styling and scripts are primed
add_thickbox();
// Prepare for theme update nag
//add_action( 'admin_notices', array( $this, 'update_nag' ) );
}
/**
* Check for Updates at the defined API endpoint and modify the update array.
*
......
......@@ -137,8 +137,9 @@ unset( $_inc_dir );
// Setup the updater
new Swifter_Theme_Updater_Admin( array(
'remote_api_url' => 'https://store.flox.io/',
'name' => 'Swifter',
'name' => 'Swifter Theme',
'slug' => 'swifter',
'version' => '1.0.0',
'author' => 'The Flox Team',
'admin_page' => 'swifter_licenses'
) );
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment