Commit bac4cbf5 authored by John James Jacoby's avatar John James Jacoby

Update base class & theme class

parent 453966f6
......@@ -45,6 +45,11 @@ class Flox_Licensed_Product {
*/
protected $name = '';
/**
* @var string Usually __FILE__ of caller
*/
protected $file = '';
/**
* @var string Product version
*/
......@@ -82,6 +87,7 @@ class Flox_Licensed_Product {
'sslverify' => $this->sslverify,
'slug' => $this->slug,
'name' => $this->name,
'file' => $this->file,
'version' => $this->version,
'author' => $this->author,
'download_id' => $this->download_id,
......@@ -105,6 +111,7 @@ class Flox_Licensed_Product {
$this->remote_api_url = esc_url_raw( $r['remote_api_url'] );
$this->slug = sanitize_key( $r['slug'] );
$this->name = $r['name'];
$this->file = $r['file'];
$this->version = $r['version'];
$this->author = $r['author'];
$this->download_id = $r['download_id'];
......@@ -127,7 +134,10 @@ class Flox_Licensed_Product {
$option_key = 'update_option_' . $this->license_key();
// Ensure license key update is handled
add_action( $option_key, array( $this, 'activate_license' ), 10, 2 );
add_action( $option_key, array( $this, 'activate_license' ), 10, 2 );
// Manipulate the wordpress.org update request
add_filter( 'http_request_args', array( $this, 'prevent_wporg_update_check' ), 5, 2 );
}
/**
......@@ -154,8 +164,9 @@ class Flox_Licensed_Product {
'license' => $this->get_license(),
'remote_api_url' => $this->remote_api_url,
'slug' => $this->slug,
'version' => $this->version,
'name' => $this->name,
'file' => $this->file,
'version' => $this->version,
'author' => $this->author
) );
}
......@@ -203,7 +214,12 @@ class Flox_Licensed_Product {
}
/**
* Stub license section method
* Stub wordpress.org update preventitive method
*/
public function prevent_wporg_update_check( $args = array(), $url = '' ) { }
/**
* Stub license menu method
*/
public function license_menu() {}
......@@ -517,12 +533,21 @@ class Flox_Licensed_Product {
* @return bool
*/
protected function is_update_available( $update_data = false ) {
// Maybe fetch update data
if ( false === $update_data ) {
$update_data = $this->check_for_update();
}
$update_available = version_compare( $this->version, $update_data->new_version, '<' );
// Assume no update
$update_available = false;
// Maybe compare to remote API version
if ( ! empty( $update_data->new_version ) ) {
$update_available = version_compare( $this->version, $update_data->new_version, '<' );
}
// Cast & return
return (bool) $update_available;
}
......
......@@ -52,11 +52,8 @@ class Flox_Theme_Updater extends Flox_Licensed_Product {
add_action( 'load-themes.php', array( $this, 'load_themes_screen' ) );
// Filters
add_filter( 'site_transient_update_themes', array( $this, 'maybe_update_transient' ) );
add_filter( 'delete_site_transient_update_themes', array( $this, 'delete_update_transient' ) );
// Disable wporg requests
add_filter( 'http_request_args', array( $this, 'noop_wporg_request' ), 5, 2 );
add_filter( 'pre_set_site_transient_update_themes', array( $this, 'maybe_update_transient' ) );
add_filter( 'delete_site_transient_update_themes', array( $this, 'delete_update_transient' ) );
}
/** Public ****************************************************************/
......@@ -146,8 +143,12 @@ class Flox_Theme_Updater extends Flox_Licensed_Product {
/**
* Prevent requests to wordpress.org repository for this theme and any
* decendants of it.
*
* @param array $args
* @param string $url
* @return array
*/
public function noop_wporg_request( $args = array(), $url = '' ) {
public function prevent_wporg_update_check( $args = array(), $url = '' ) {
// Bail if not wordpress.org theme update request
if ( 0 !== strpos( $url, 'https://api.wordpress.org/themes/update-check/1.1/' ) ) {
......
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