Skip to content

Commit 2199b8f

Browse files
authored
Merge pull request #20 from soderlind/refactor/plugin-updater
chore: bump version to 1.6.0, refactor plugin updater
2 parents 6f0f29e + a147a8f commit 2199b8f

6 files changed

Lines changed: 86 additions & 161 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.6.0] - 2026-02-09
9+
10+
### Changed
11+
12+
- Replaced inline plugin updater with shared `class-github-updater.php`
13+
814
## [1.5.1] - 2025-06-25
915

1016
### Fixed

class-github-updater.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* GitHub Plugin Updater
4+
*
5+
* Minimal wrapper around yahnis-elsts/plugin-update-checker for GitHub-hosted
6+
* WordPress plugins. Defers the actual update-checker setup to the `init` action
7+
* so it works regardless of when the calling plugin loads the file.
8+
*
9+
* @package Soderlind\WordPress
10+
* @version 1.0.0
11+
* @author Per Soderlind
12+
* @license GPL-2.0-or-later
13+
* @link https://github.com/soderlind/wordpress-plugin-github-updater
14+
*/
15+
16+
namespace Soderlind\WordPress;
17+
18+
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
19+
20+
// Prevent direct access.
21+
defined( 'ABSPATH' ) || exit;
22+
23+
/**
24+
* Sets up automatic plugin updates from a GitHub repository.
25+
*/
26+
final class GitHubUpdater {
27+
28+
/**
29+
* Initialize the GitHub update checker.
30+
*
31+
* @param string $github_url Full GitHub repository URL (e.g. 'https://github.com/owner/repo').
32+
* @param string $plugin_file Absolute path to the main plugin file (__FILE__).
33+
* @param string $plugin_slug Plugin slug used by WordPress (e.g. 'my-plugin').
34+
* @param string $name_regex Optional regex to filter release assets (e.g. '/my-plugin\.zip/').
35+
* @param string $branch Branch to track (default 'main').
36+
*/
37+
public static function init(
38+
string $github_url,
39+
string $plugin_file,
40+
string $plugin_slug,
41+
string $name_regex = '',
42+
string $branch = 'main',
43+
): void {
44+
add_action( 'init', static function () use ( $github_url, $plugin_file, $plugin_slug, $name_regex, $branch ): void {
45+
try {
46+
$checker = PucFactory::buildUpdateChecker( $github_url, $plugin_file, $plugin_slug );
47+
$checker->setBranch( $branch );
48+
49+
if ( '' !== $name_regex ) {
50+
$checker->getVcsApi()->enableReleaseAssets( $name_regex );
51+
}
52+
} catch ( \Exception $e ) {
53+
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
54+
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
55+
error_log( 'GitHubUpdater (' . $plugin_slug . '): ' . $e->getMessage() );
56+
}
57+
}
58+
} );
59+
}
60+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vmfa-editorial-workflow",
3-
"version": "1.5.1",
3+
"version": "1.6.0",
44
"description": "Role-based folder access, move restrictions, and Inbox workflow for Virtual Media Folders.",
55
"author": "Per Soderlind",
66
"license": "GPL-2.0-or-later",

readme.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: media, folders, workflow, editorial, permissions
44
Requires at least: 6.8
55
Tested up to: 6.9
66
Requires PHP: 8.3
7-
Stable tag: 1.5.1
7+
Stable tag: 1.6.0
88
License: GPL-2.0-or-later
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -95,6 +95,9 @@ Existing media is not affected. The workflow only applies to new uploads and exp
9595

9696
== Changelog ==
9797

98+
= 1.6.0 =
99+
* Changed: Replaced inline plugin updater with shared `class-github-updater.php`
100+
98101
= 1.5.1 =
99102

100103
**Fixed**

src/php/Update/GitHubPluginUpdater.php

Lines changed: 0 additions & 148 deletions
This file was deleted.

vmfa-editorial-workflow.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Virtual Media Folders - Editorial Workflow
44
* Plugin URI: https://github.com/soderlind/vmfa-editorial-workflow
55
* Description: Role-based folder access, move restrictions, and Inbox workflow for Virtual Media Folders.
6-
* Version: 1.5.1
6+
* Version: 1.6.0
77
* Requires at least: 6.8
88
* Requires PHP: 8.3
99
* Tested up to: 6.9
@@ -26,24 +26,28 @@
2626
defined( 'ABSPATH' ) || exit;
2727

2828
// Plugin constants.
29-
define( 'VMFA_EDITORIAL_WORKFLOW_VERSION', '1.5.1' );
29+
define( 'VMFA_EDITORIAL_WORKFLOW_VERSION', '1.6.0' );
3030
define( 'VMFA_EDITORIAL_WORKFLOW_FILE', __FILE__ );
3131
define( 'VMFA_EDITORIAL_WORKFLOW_PATH', plugin_dir_path( __FILE__ ) );
3232
define( 'VMFA_EDITORIAL_WORKFLOW_URL', plugin_dir_url( __FILE__ ) );
3333

34-
// Initialize GitHub updater.
34+
// Autoload Composer dependencies.
3535
if ( file_exists( VMFA_EDITORIAL_WORKFLOW_PATH . 'vendor/autoload.php' ) ) {
3636
require_once VMFA_EDITORIAL_WORKFLOW_PATH . 'vendor/autoload.php';
37-
require_once VMFA_EDITORIAL_WORKFLOW_PATH . 'src/php/Update/GitHubPluginUpdater.php';
38-
Update\GitHubPluginUpdater::create_with_assets(
39-
'https://github.com/soderlind/vmfa-editorial-workflow',
40-
__FILE__,
41-
'vmfa-editorial-workflow',
42-
'/vmfa-editorial-workflow\.zip/',
43-
'main'
44-
);
4537
}
4638

39+
// Update checker via GitHub releases.
40+
if ( ! class_exists( \Soderlind\WordPress\GitHubUpdater::class ) ) {
41+
require_once __DIR__ . '/class-github-updater.php';
42+
}
43+
\Soderlind\WordPress\GitHubUpdater::init(
44+
github_url: 'https://github.com/soderlind/vmfa-editorial-workflow',
45+
plugin_file: VMFA_EDITORIAL_WORKFLOW_FILE,
46+
plugin_slug: 'vmfa-editorial-workflow',
47+
name_regex: '/vmfa-editorial-workflow\.zip/',
48+
branch: 'main',
49+
);
50+
4751
/**
4852
* Initialize the plugin.
4953
*

0 commit comments

Comments
 (0)