Skip to content

Commit

Permalink
Updates some items.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Lannoy committed Nov 18, 2024
1 parent e2764ad commit 11c08c1
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 12 deletions.
5 changes: 1 addition & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Compatibility with WordPress 6.6 & 6.7.

### Changed
- Better rendering for advanced settings.a

### Fixed
- a
- Better rendering for advanced settings.

### Removed
- As Databeam project has been abandoned, all corresponding hooks and libraries have been removed.
Expand Down
109 changes: 105 additions & 4 deletions includes/plugin/class-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
*/
class Updater {

private $name = POKM_PRODUCT_NAME;
private $slug = POKM_SLUG;
private $version = POKM_VERSION;

/**
* Initializes the class, set its properties and performs
* post-update processes if needed.
Expand All @@ -45,13 +49,20 @@ public function __construct() {
} else {
$this->update( $old );
// phpcs:ignore
$message = sprintf( esc_html__( '%1$s has been correctly updated from version %2$s to version %3$s.', 'keys-master' ), POKM_PRODUCT_NAME, $old, POKM_VERSION );
$message = sprintf( esc_html__( '%1$s has been correctly updated from version %2$s to version %3$s.', 'keys-master' ), POKM_PRODUCT_NAME, $old, POKM_VERSION );
\DecaLog\Engine::eventsLogger( POKM_SLUG )->notice( $message );
// phpcs:ignore
$message .= ' ' . sprintf( __( 'See <a href="%s">what\'s new</a>.', 'keys-master' ), admin_url( 'admin.php?page=pokm-settings&tab=about' ) );
}
Nag::add( 'update', 'info', $message );
}
if ( ! ( defined( 'POO_SELFUPDATE_BYPASS' ) && POO_SELFUPDATE_BYPASS ) ) {
//add_filter( 'plugins_api', [ $this, 'info' ], 20, 3 );
//add_filter( 'site_transient_update_plugins', [ $this, 'info_update' ] );
//add_action( 'upgrader_process_complete', [ $this, 'info_reset' ], 10, 2 );
}


}

/**
Expand All @@ -66,7 +77,8 @@ private function install() {
/**
* Performs post-update processes.
*
* @param string $from The version from which the plugin is updated.
* @param string $from The version from which the plugin is updated.
*
* @since 1.0.0
*/
private function update( $from ) {
Expand All @@ -79,13 +91,102 @@ private function update( $from ) {
/**
* Get the changelog.
*
* @param array $attributes 'style' => 'markdown', 'html'.
* @param array $attributes 'style' => 'markdown', 'html'.
* 'mode' => 'raw', 'clean'.
*
* @return string The output of the shortcode, ready to print.
* @since 1.0.0
*/
public function sc_get_changelog( $attributes ) {
$md = new Markdown();
return $md->get_shortcode( 'CHANGELOG.md', $attributes );
return $md->get_shortcode( 'CHANGELOG.md', $attributes );
}

/**
* Acquires infos about update
*
* @return object The remote info.
*/
private function gather_info(){
$remote = get_transient( 'update-' . $this->slug );
if( false === $remote ) {
$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;
}
set_transient( 'update-' . $this->slug, $remote, DAY_IN_SECONDS );
}
$remote = json_decode( wp_remote_retrieve_body( $remote ) );
return $remote;


/*
$res->name = $this->name;
$res->slug = $this->slug;
$res->version = $remote->version;
$res->tested = $remote->tested;
$res->requires = $remote->requires;
$res->author = $remote->author;
$res->author_profile = $remote->author_profile;
$res->requires_php = $remote->requires_php;
$res->last_updated = $remote->last_updated;
$res->sections = array(
'description' => $remote->sections->description,
'installation' => $remote->sections->installation,
'changelog' => $remote->sections->changelog
);
$res->download_link = $remote->download_url;
$res->trunk = $remote->download_url;*/
}

/**
* Updates infos transient
*
* @param Transient $transient The transient to update.
*
* @return Transient The updated transient.
*/
public function info_update( $transient ) {
if ( empty( $transient->checked ) ) {
return $transient;
}
$remote = $this->gather_info();
if ( $remote && version_compare( $this->version, $remote->version, '<' ) && version_compare( $remote->requires, get_bloginfo( 'version' ), '<=' ) && version_compare( $remote->requires_php, PHP_VERSION, '<' ) ) {
$res = new stdClass();
$res->slug = $this->slug;
$res->plugin = plugin_basename( __FILE__ );
$res->new_version = $remote->version;
$res->tested = $remote->tested;
$res->package = $remote->download_url;
$transient->response[ $res->plugin ] = $res;
}

return $transient;
}

/**
* Reset update infos
*
* @param Plugin_Upgrader $upgrader Upgrader instance.
* @param array $options Array of bulk item update data.
*/
public function info_reset( $upgrader, $options ) {
if ( 'update' === $options['action'] && 'plugin' === $options['type'] ) {
delete_transient( 'update-' . $this->slug );
}
}
}
2 changes: 1 addition & 1 deletion init.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
define( 'POKM_PRODUCT_SHORTNAME', 'keys-master' );
define( 'POKM_PRODUCT_ABBREVIATION', 'keysmaster' );
define( 'POKM_SLUG', 'keys-master' );
define( 'POKM_VERSION', '2.1.0-rc1' );
define( 'POKM_VERSION', '2.1.0' );
define( 'POKM_CODENAME', '"-"' );
define( 'POKM_CDN_AVAILABLE', true );

2 changes: 1 addition & 1 deletion keys-master.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Plugin Name: Keys Master
* Plugin URI: https://perfops.one/keys-master
* Description: Powerful application passwords manager for WordPress with role-based usage control and full analytics reporting capabilities.
* Version: 2.0.0
* Version: 2.1.0
* Requires at least: 6.2
* Requires PHP: 8.1
* Author: Pierre Lannoy / PerfOps One
Expand Down
4 changes: 2 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Contributors: PierreLannoy, hosterra
Tags: application password, authentication, rest-api, security, xml-rpc
Requires at least: 6.2
Requires PHP: 8.1
Tested up to: 6.5
Stable tag: 2.0.0
Tested up to: 6.7
Stable tag: 2.1.0
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand Down

0 comments on commit 11c08c1

Please sign in to comment.