-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add: Theme Updater * Fix: Changelog Display in Dashboard
- Loading branch information
1 parent
ff5c73e
commit 05f52cb
Showing
8 changed files
with
127 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
/** | ||
* Base\Updater\Component class | ||
* | ||
* @package Base | ||
*/ | ||
|
||
namespace Base\Updater; | ||
|
||
use Base\Component_Interface; | ||
use function Base\webapp; | ||
use function add_filter; | ||
use function get_template; | ||
use function wp_get_theme; | ||
use function get_bloginfo; | ||
|
||
/** | ||
* Class for improving updater among various core features. | ||
*/ | ||
class Component implements Component_Interface { | ||
|
||
/** | ||
* Gets the unique identifier for the theme component. | ||
* | ||
* @return string Component slug. | ||
*/ | ||
public function get_slug() : string { | ||
return 'updater'; | ||
} | ||
|
||
/** | ||
* Adds the action and filter hooks to integrate with WordPress. | ||
*/ | ||
public function initialize() { | ||
add_filter( 'site_transient_update_themes', array( $this, 'base_theme_updater' ) ); | ||
} | ||
|
||
/** | ||
* Theme Updater : $transient | ||
* | ||
*/ | ||
public function base_theme_updater( $transient ) { | ||
|
||
$stylesheet = get_template(); | ||
|
||
$theme = wp_get_theme(); | ||
$version = $theme->get( 'Version' ); | ||
|
||
if( false == $remote = get_transient( 'avanam-theme-update'.$version ) ) { | ||
|
||
// connect to a remote server where the update information is stored | ||
$remote = wp_remote_get( | ||
'https://avanam.org/updates/avanam.json', | ||
array( | ||
'timeout' => 10, | ||
'headers' => array( | ||
'Accept' => 'application/json' | ||
) | ||
) | ||
); | ||
|
||
if( | ||
is_wp_error( $remote ) | ||
|| 200 !== wp_remote_retrieve_response_code( $remote ) | ||
|| empty( wp_remote_retrieve_body( $remote ) ) | ||
) { | ||
return $transient; | ||
} | ||
|
||
$remote = json_decode( wp_remote_retrieve_body( $remote ) ); | ||
|
||
if( ! $remote ) { | ||
return $transient; | ||
} | ||
|
||
set_transient( 'avanam-theme-update'.$version, $remote, HOUR_IN_SECONDS ); | ||
|
||
} | ||
|
||
$data = array( | ||
'theme' => $stylesheet, | ||
'url' => $remote->details_url, | ||
'requires' => $remote->requires, | ||
'requires_php' => $remote->requires_php, | ||
'new_version' => $remote->version, | ||
'package' => $remote->download_url, | ||
); | ||
|
||
if( | ||
$remote | ||
&& version_compare( $version, $remote->version, '<' ) | ||
&& version_compare( $remote->requires, get_bloginfo( 'version' ), '<' ) | ||
) { | ||
|
||
$transient->response[ $stylesheet ] = $data; | ||
|
||
} else { | ||
|
||
$transient->no_update[ $stylesheet ] = $data; | ||
|
||
} | ||
|
||
return $transient; | ||
|
||
} | ||
} |
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
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
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
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