Skip to content

Commit

Permalink
Updated the auto-updater to dynamically take the version number.
Browse files Browse the repository at this point in the history
  • Loading branch information
Neychok committed Jul 5, 2023
1 parent b854826 commit 058c3db
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 52 deletions.
4 changes: 2 additions & 2 deletions dxsf-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Plugin Name: DXSF Proxy
* Plugin URI: https://devrix.com
* Description: Stability Framework Proxy Plugin
* Version: 2.3.0
* Version: 2.3.1
* Author: DevriX
* Author URI: https://devrix.com
* License: GPL-2.0+
Expand All @@ -34,7 +34,7 @@
* For the versioning of the plugin is used SemVer - https://semver.org
* Rename this for every new plugin and update it as you release new versions.
*/
define( 'DXSF_PROXY_VERSION', '2.3.0' );
define( 'DXSF_PROXY_VERSION', '2.3.1' );

if ( ! defined( 'DXSF_PROXY_DIR' ) ) {
define( 'DXSF_PROXY_DIR', plugin_dir_path( __FILE__ ) );
Expand Down
90 changes: 47 additions & 43 deletions includes/classes/updater/class-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,45 @@ public function __construct() {
$this->cache_allowed = false;
}

public function request() {
public function get_remote_version() {

$remote = get_transient( $this->cache_key );
$remote_version = get_transient( $this->cache_key );

if( false === $remote || ! $this->cache_allowed ) {
if( false === $remote_version || ! $this->cache_allowed ) {

// read the info.json file in the same folder
$remote = file_get_contents( DXSF_PROXY_DIR . '/includes/classes/updater/info.json' );
$remote = wp_remote_get(
'https://raw.githubusercontent.com/DevriX/dxsf-proxy/master/dxsf-proxy.php',
array(
'timeout' => 10,
'headers' => array(
'Accept' => 'application/json'
)
)
);

// $remote = wp_remote_get(
// 'https://rudrastyh.com/wp-content/uploads/updater/info.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 false;
}

// if(
// is_wp_error( $remote )
// || 200 !== wp_remote_retrieve_response_code( $remote )
// || empty( wp_remote_retrieve_body( $remote ) )
// ) {
// return false;
// }
$remote = wp_remote_retrieve_body( $remote );

set_transient( $this->cache_key, $remote, DAY_IN_SECONDS );
preg_match( '/^\s*\* Version:\s*(.*)$/im', $remote, $matches );

}
if( empty( $matches[1] ) ) {
return false;
}

$remote_version = $matches[1];

$remote = json_decode( $remote );
set_transient( $this->cache_key, $remote_version, DAY_IN_SECONDS );

return $remote;
}

return $remote_version;

}

Expand All @@ -67,49 +72,49 @@ function info( $res, $action, $args ) {
}

// get updates
$remote = $this->request();
$remote_version = $this->get_remote_version();

if( ! $remote ) {
if( ! $remote_version ) {
return $res;
}

$res = new \stdClass();

$res->name = $remote->name;
$res->slug = $remote->slug;
$res->version = $remote->version;
$res->author = $remote->author;
$res->download_link = $remote->download_url;
$res->trunk = $remote->download_url;
$res->name = 'DXSF Proxy';
$res->slug = $this->plugin_slug;
$res->version = $remote_version;
$res->author = 'DevriX';
$res->download_link = 'https://github.com/DevriX/dxsf-proxy/releases/latest/download/dxsf-wordpress-proxy.zip';
$res->trunk = 'https://github.com/DevriX/dxsf-proxy/releases/latest/download/dxsf-wordpress-proxy.zip';

return $res;

}

public function update( $transient ) {

if ( empty($transient->checked ) ) {
if ( empty( $transient->checked ) ) {
return $transient;
}

$remote = $this->request();
$remote_version = $this->get_remote_version();

if (
$remote
&& version_compare( $this->version, $remote->version, '<' )
$remote_version
&& version_compare( $this->version, $remote_version, '<' )
) {

$res = new \stdClass();
$res->slug = $this->plugin_slug;
$res->plugin = plugin_basename( DXSF_PROXY_DIR . '/dxsf-proxy.php' ); // misha-update-plugin/misha-update-plugin.php
$res->new_version = $remote->version;
$res->package = $remote->download_url;
$res->new_version = $remote_version;
$res->author = 'DevriX';
$res->download_link = 'https://github.com/DevriX/dxsf-proxy/releases/latest/download/dxsf-wordpress-proxy.zip';
$res->trunk = 'https://github.com/DevriX/dxsf-proxy/releases/latest/download/dxsf-wordpress-proxy.zip';

$transient->response[ $res->plugin ] = $res;
}
}

return $transient;

}

public function purge( $upgrader, $options ) {
Expand All @@ -122,6 +127,5 @@ public function purge( $upgrader, $options ) {
// just clean the cache when new plugin version is installed
delete_transient( $this->cache_key );
}

}
}
7 changes: 0 additions & 7 deletions includes/classes/updater/info.json

This file was deleted.

0 comments on commit 058c3db

Please sign in to comment.