Skip to content

Commit

Permalink
V1.1.1 - Auto Update Version
Browse files Browse the repository at this point in the history
  • Loading branch information
gbissland committed Nov 25, 2024
1 parent 8652c90 commit bca8fb0
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 17 deletions.
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,26 @@ All notable changes to the FirehawkCRM Tributes Enhancement Suite will be docume
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.0] - 2024-11-22
## v1.1.1 - Auto-Update Feature Release

### What's New
- Added GitHub-based automatic updates
- Plugin updates can now be managed directly from the WordPress dashboard
- Update notifications will show release notes and version details

### Technical Details
- Implemented GitHub releases integration for version control
- Added automatic version checking against GitHub repository
- Integrated with WordPress native update system
- Added error logging for update process debugging

### Notes
- No settings changes required
- Updates will appear in your regular WordPress updates dashboard
- Requires no additional configuration


## [1.1.0] - 2024-11-23
### Added
- Initial release combining three separate plugins
- Performance and loading optimisation features
Expand Down
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ fcrm-tributes-enhancement-suite/
│ ├── class-fcrm-optimisation.php # Performance optimisation module
│ ├── class-fcrm-styling.php # Custom styling module
│ └── class-fcrm-loader.php # Loading animation module
│ └── class-github-updater.php # Auto-update from Github module
├── README.md # Documentation
├── LICENSE
└── fcrm-tributes-enhancement-suite.php # Main plugin file
Expand Down Expand Up @@ -214,12 +215,15 @@ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file

## Changelog

### 1.1.0
- Initial release combining three separate plugins into the one suite.
- Features include:
- Performance and loading optimisations.
- Custom styling from admin with a colour picker.
- Loading animation for tribute grids.
- Added unified admin interface.
- Improved page detection for loading scripts.
- Flower delivery disabled by default.
### v1.1.1 (2024-11-25) - Auto-Update Version
- Added automatic updates via WordPress dashboard
- Integrated GitHub releases for version control
- Update notifications now include release notes
- No configuration required for update functionality

### v1.1.0 (Initial Public Release)
- Performance optimization features
- Custom styling interface
- Loading animation functionality
- WordPress 6.0+ compatibility
- PHP 8.0+ support
20 changes: 15 additions & 5 deletions fcrm-tributes-enhancement-suite.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,37 @@
* Plugin Name: FireHawkCRM Tributes - Enhancement Suite
* Plugin URI: https://github.com/weavedigitalstudio/fcrm-tributes-enhancement-suite/
* Description: An enhancement suite for the FireHawkCRM Tributes plugin, including performance optimisations, custom styling from admin, and loading animations.
* Version: 1.1.0
* Version: 1.1.1
* Author: Weave Digital Studio, Gareth Bissland
* Author URI: https://weave.co.nz/
* License: MIT
* License URI: https://opensource.org/licenses/MIT
* GitHub Plugin URI: weavedigitalstudio/fcrm-tributes-enhancement-suite/
* Primary Branch: main
* Text Domain: fcrm-enhancement-suite
* Requires at least: 6.0
* Requires PHP: 8.0
*/

namespace FCRM\EnhancementSuite;

// Load the updater class
require_once plugin_dir_path(__FILE__) . 'includes/class-github-updater.php';

// Initialize the updater
if (class_exists('GitHubPluginUpdater')) {
new GitHubPluginUpdater(
__FILE__,
'weavedigitalstudio/fcrm-tributes-enhancement-suite'
);
}

// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}

// Plugin constants
define('FCRM_ENHANCEMENT_VERSION', '1.0.0');
define('FCRM_ENHANCEMENT_VERSION', '1.1.1');
define('FCRM_ENHANCEMENT_FILE', __FILE__);
define('FCRM_ENHANCEMENT_PATH', plugin_dir_path(__FILE__));
define('FCRM_ENHANCEMENT_URL', plugin_dir_url(__FILE__));
Expand Down
4 changes: 2 additions & 2 deletions includes/class-fcrm-styling.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ protected function init(): void {
*/
protected function get_default_value(string $key): mixed {
$defaults = [
'primary-color' => '#000000',
'secondary-color' => '#FFFFFF',
'primary-color' => '#FFFFFF',
'secondary-color' => '#000000',
'primary-button' => '#007BFF',
'primary-button-text' => '#FFFFFF',
'primary-button-hover' => '#0056B3',
Expand Down
138 changes: 138 additions & 0 deletions includes/class-github-updater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php
/**
* GitHub Plugin Updater
*
* Enables automatic updates from GitHub releases for WordPress plugins.
* Requires plugin header to include "GitHub Plugin URI".
*/

if (!class_exists('GitHubPluginUpdater')) {
class GitHubPluginUpdater {
private $file;
private $plugin;
private $basename;
private $active;
private $github_response;
private $github_url;
private $authorize_token;

public function __construct($file, $github_url, $authorize_token = null) {
$this->file = $file;
$this->github_url = $github_url;
$this->authorize_token = $authorize_token;
$this->basename = plugin_basename($file);

// Load plugin data
$this->plugin = get_file_data($this->file, array(
'Name' => 'Plugin Name',
'PluginURI' => 'Plugin URI',
'Description' => 'Description',
'Author' => 'Author',
'AuthorURI' => 'Author URI',
'Version' => 'Version',
));

add_filter('pre_set_site_transient_update_plugins', array($this, 'modify_transient'), 10, 1);
add_filter('plugins_api', array($this, 'plugin_popup'), 10, 3);
add_filter('upgrader_post_install', array($this, 'after_install'), 10, 3);
}

private function get_repository_info() {
if (is_null($this->github_response)) {
$request_uri = sprintf('https://api.github.com/repos/%s/releases/latest', $this->github_url);

$args = array(
'headers' => array(
'User-Agent' => 'WordPress-GitHub-Updater' // GitHub API requires a User-Agent
),
);

if ($this->authorize_token) {
$args['headers']['Authorization'] = "Bearer {$this->authorize_token}";
}

$response = wp_remote_get($request_uri, $args);

if (is_wp_error($response)) {
error_log('GitHub Plugin Updater: Failed to fetch repository info: ' . $response->get_error_message());
return false;
}

$body = wp_remote_retrieve_body($response);
$decoded = json_decode($body);

if (isset($decoded->tag_name)) {
$this->github_response = $decoded;
} else {
error_log('GitHub Plugin Updater: Invalid response from GitHub API');
}
}
}

public function modify_transient($transient) {
if (property_exists($transient, 'checked')) {
if ($checked = $transient->checked) {
$this->get_repository_info();

if (isset($this->github_response->tag_name) && version_compare($this->github_response->tag_name, $checked[$this->basename], 'gt')) {
$plugin = array(
'url' => $this->plugin['PluginURI'],
'slug' => current(explode('/', $this->basename)),
'package' => $this->github_response->zipball_url,
'new_version' => $this->github_response->tag_name
);

$transient->response[$this->basename] = (object) $plugin;
}
}
}

return $transient;
}

public function plugin_popup($result, $action, $args) {
if ($action !== 'plugin_information') {
return $result;
}

if (!empty($args->slug) && $args->slug === current(explode('/', $this->basename))) {
$this->get_repository_info();

if (isset($this->github_response->tag_name)) {
$plugin = array(
'name' => $this->plugin['Name'],
'slug' => $this->basename,
'version' => $this->github_response->tag_name,
'author' => $this->plugin['Author'],
'author_profile' => $this->plugin['AuthorURI'],
'last_updated' => $this->github_response->published_at,
'homepage' => $this->plugin['PluginURI'],
'short_description' => $this->plugin['Description'],
'sections' => array(
'Description' => $this->plugin['Description'],
'Updates' => $this->github_response->body,
),
'download_link' => $this->github_response->zipball_url
);

return (object) $plugin;
}
}
return $result;
}

public function after_install($response, $hook_extra, $result) {
global $wp_filesystem;

$install_directory = plugin_dir_path($this->file);
$wp_filesystem->move($result['destination'], $install_directory);
$result['destination'] = $install_directory;

if (is_plugin_active($this->basename)) {
activate_plugin($this->basename);
}

return $result;
}
}
}

0 comments on commit bca8fb0

Please sign in to comment.