Skip to content

Commit 07a5ffd

Browse files
committed
refactor: convert to Composer library with rate-limit mitigation
- Add composer.json with PSR-4 autoload (soderlind/wordpress-github-updater) - Split class into src/GitHubUpdater.php and src/GitHub_Plugin_Updater.php - Add check_period param (default 6h) and throttling (72h when update known) - Add auth_token param for private repos / higher rate limits - Move workflow templates to .github/workflows/ - Add .gitattributes for export-ignore - Add CHANGELOG.md BREAKING: Package structure changed from single file to PSR-4 layout
1 parent 4e7ec43 commit 07a5ffd

File tree

139 files changed

+13060
-242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+13060
-242
lines changed

.gitattributes

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Export-ignore: exclude from Composer packages / releases
2+
.git* export-ignore
3+
.github/ export-ignore
4+
.vscode/ export-ignore
5+
tests/ export-ignore
6+
docs/ export-ignore
7+
8+
# Workflow templates (kept for reference, not for library users)
9+
manually-build-zip.yml export-ignore
10+
on-release-add.zip.yml export-ignore
11+
12+
# Dev files
13+
phpunit.xml export-ignore
14+
phpunit.xml.dist export-ignore
15+
phpcs.xml export-ignore
16+
.editorconfig export-ignore
17+
CHANGELOG.md export-ignore
18+
19+
# Normalize line endings
20+
* text=auto
21+
*.php text eol=lf
22+
*.json text eol=lf
23+
*.md text eol=lf
24+
*.yml text eol=lf

CHANGELOG.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [2.0.0] - 2026-04-05
9+
10+
### Added
11+
12+
- **Composer package**: Install via `composer require soderlind/wordpress-github-updater`.
13+
- **Rate-limit mitigation**:
14+
- Configurable `check_period` parameter (default: 6 hours).
15+
- Throttled checks when update already known (72 hours).
16+
- Optional `auth_token` parameter for GitHub authentication (increases rate limit from 60 to 5000 requests/hour).
17+
- **API error logging**: Logs GitHub API errors via `puc_api_error` hook when `WP_DEBUG` is enabled.
18+
- **PSR-4 autoloading**: Classes in `src/` directory.
19+
20+
### Changed
21+
22+
- **BREAKING**: Package structure changed from single file to PSR-4 layout (`src/GitHubUpdater.php`, `src/GitHub_Plugin_Updater.php`).
23+
- `GitHubUpdater::init()` signature extended with two new optional parameters: `check_period` and `auth_token`.
24+
- Workflow templates moved to `.github/workflows/`.
25+
- Default check interval reduced from 12 hours to 6 hours.
26+
27+
### Deprecated
28+
29+
- `GitHub_Plugin_Updater` class — use `GitHubUpdater::init()` directly.
30+
31+
## [1.0.0] - 2024-03-01
32+
33+
### Added
34+
35+
- Initial release.
36+
- `GitHubUpdater::init()` static API.
37+
- `GitHub_Plugin_Updater` wrapper class with config array constructor.
38+
- Release asset filtering via `name_regex`.
39+
- Branch selection support.
40+
- GitHub Actions workflow templates for release builds.
41+
42+
[2.0.0]: https://github.com/soderlind/wordpress-plugin-github-updater/compare/1.0.0...2.0.0
43+
[1.0.0]: https://github.com/soderlind/wordpress-plugin-github-updater/releases/tag/1.0.0

README.md

Lines changed: 87 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
11
# WordPress Plugin GitHub Updater
22

3-
Reusable GitHub updater helper for WordPress plugins, built on top of `yahnis-elsts/plugin-update-checker`.
3+
Composer library for handling WordPress plugin updates from GitHub repositories. Built on `yahnis-elsts/plugin-update-checker` with built-in rate-limit mitigation.
44

55
## Features
66

7-
- Automatic plugin updates from GitHub.
7+
- **Automatic updates** from GitHub releases or branch commits.
8+
- **Rate-limit mitigation**: Configurable check intervals (default 6h) and throttling (72h when update already known).
9+
- **GitHub token support** for private repos and higher API limits (60 → 5000 requests/hour).
810
- Release-asset filtering using regex.
911
- Branch selection (default: `main`).
10-
- Canonical static API (`GitHubUpdater::init`) plus backward-compatible wrapper (`GitHub_Plugin_Updater`).
12+
- Canonical static API (`GitHubUpdater::init`) plus backward-compatible wrapper.
1113
- Error handling with `WP_DEBUG` logging.
1214

13-
## Requirements
14-
15-
- WordPress plugin context (`ABSPATH` must be defined).
16-
- Composer dependency: `yahnis-elsts/plugin-update-checker` (v5+).
17-
- A public GitHub repository with releases or branch updates.
18-
19-
Install dependency:
15+
## Installation
2016

2117
```bash
22-
composer require yahnis-elsts/plugin-update-checker
18+
composer require soderlind/wordpress-github-updater
2319
```
2420

25-
## Quick Start (Canonical API)
21+
This automatically includes `yahnis-elsts/plugin-update-checker` as a dependency.
2622

27-
Copy `class-github-plugin-updater.php` into your plugin and initialize like this:
23+
## Requirements
2824

29-
```php
30-
if ( ! class_exists( \Soderlind\WordPress\GitHubUpdater::class ) ) {
31-
require_once __DIR__ . '/class-github-plugin-updater.php';
32-
}
25+
- PHP 7.4+
26+
- WordPress plugin context (`ABSPATH` must be defined).
27+
- A GitHub repository with releases or branch updates.
3328

34-
\Soderlind\WordPress\GitHubUpdater::init(
35-
github_url: 'https://github.com/username/plugin-name',
36-
plugin_file: __FILE__,
37-
plugin_slug: 'plugin-name',
38-
name_regex: '/plugin-name\.zip/',
39-
branch: 'main',
29+
## Quick Start
30+
31+
```php
32+
use Soderlind\WordPress\GitHubUpdater;
33+
34+
GitHubUpdater::init(
35+
github_url: 'https://github.com/username/plugin-name',
36+
plugin_file: __FILE__,
37+
plugin_slug: 'plugin-name',
38+
name_regex: '/plugin-name\.zip/',
39+
branch: 'main',
40+
check_period: 6, // Hours between checks (default: 6)
41+
auth_token: '', // Optional GitHub token
4042
);
4143
```
4244

@@ -48,7 +50,20 @@ Positional equivalent:
4850
__FILE__,
4951
'plugin-name',
5052
'/plugin-name\.zip/',
51-
'main'
53+
'main',
54+
6, // check_period
55+
'' // auth_token
56+
);
57+
```
58+
59+
### With GitHub Token (for private repos or higher rate limits)
60+
61+
```php
62+
GitHubUpdater::init(
63+
github_url: 'https://github.com/username/private-plugin',
64+
plugin_file: __FILE__,
65+
plugin_slug: 'private-plugin',
66+
auth_token: defined('MY_PLUGIN_GITHUB_TOKEN') ? MY_PLUGIN_GITHUB_TOKEN : '',
5267
);
5368
```
5469

@@ -61,15 +76,19 @@ Positional equivalent:
6176
'https://github.com/username/plugin-name',
6277
__FILE__,
6378
'plugin-name',
64-
'main'
79+
'main',
80+
6, // check_period
81+
'' // auth_token
6582
);
6683

6784
\Soderlind\WordPress\GitHub_Plugin_Updater::create_with_assets(
6885
'https://github.com/username/plugin-name',
6986
__FILE__,
7087
'plugin-name',
7188
'/plugin-name\.zip/',
72-
'main'
89+
'main',
90+
6, // check_period
91+
'' // auth_token
7392
);
7493
```
7594

@@ -84,43 +103,49 @@ Positional equivalent:
84103
| `plugin_slug` | Yes | - | Plugin slug used by WordPress |
85104
| `name_regex` | No | `''` | Regex to match release asset zip filename |
86105
| `branch` | No | `'main'` | Branch to track |
106+
| `check_period` | No | `6` | Hours between update checks. Set to `0` to disable automatic checks. |
107+
| `auth_token` | No | `''` | GitHub personal access token for private repos or higher rate limits |
108+
109+
### Rate-Limit Mitigation
87110

88-
Notes:
111+
This library includes built-in protection against GitHub API timeouts/overload:
89112

90-
- When `name_regex` is empty, release-asset filtering is disabled.
91-
- `init` registration is deferred to WordPress `init` to be safe regardless of load timing.
113+
1. **Configurable check interval**: Default is 6 hours (vs. upstream default of 12h). Adjust via `check_period`.
114+
2. **Throttled checks**: When an update is already known, checks are reduced to every 72 hours.
115+
3. **Token authentication**: Provide a GitHub token to increase rate limits from 60 to 5000 requests/hour.
116+
4. **Error logging**: API errors are logged when `WP_DEBUG` is enabled.
92117

93118
## Recommended Integration Pattern
94119

95-
From your main plugin file, mirror the vmfa pattern:
120+
From your main plugin file:
96121

97122
```php
98-
if ( ! class_exists( \Soderlind\WordPress\GitHubUpdater::class ) ) {
99-
require_once __DIR__ . '/class-github-plugin-updater.php';
100-
}
101-
102-
\Soderlind\WordPress\GitHubUpdater::init(
103-
github_url: 'https://github.com/owner/repo',
104-
plugin_file: MY_PLUGIN_FILE,
105-
plugin_slug: 'my-plugin',
106-
name_regex: '/my-plugin\.zip/',
107-
branch: 'main',
123+
// Autoloaded via Composer
124+
use Soderlind\WordPress\GitHubUpdater;
125+
126+
GitHubUpdater::init(
127+
github_url: 'https://github.com/owner/repo',
128+
plugin_file: __FILE__,
129+
plugin_slug: 'my-plugin',
130+
name_regex: '/my-plugin\.zip/',
131+
branch: 'main',
132+
check_period: 6,
108133
);
109134
```
110135

111-
## Workflow Setup
136+
## Workflow Templates
112137

113-
This repository includes two workflow templates:
138+
This repository includes two workflow templates in `.github/workflows/`:
114139

115-
- `on-release-add.zip.yml` (release-triggered build + upload)
116-
- `manually-build-zip.yml` (manual build/upload for a provided tag)
140+
- `on-release-add.zip.yml` — Release-triggered build + upload
141+
- `manually-build-zip.yml` — Manual build/upload for a provided tag
117142

118143
Copy them into your plugin repository at `.github/workflows/`.
119144

120145
### Workflow Checklist
121146

122147
1. Set `PLUGIN_ZIP` to your plugin zip file (example: `my-plugin.zip`).
123-
2. Keep `composer install --no-dev --optimize-autoloader` so the updater dependency is packaged.
148+
2. Keep `composer install --no-dev --optimize-autoloader` so dependencies are packaged.
124149
3. Keep the verification step that checks `vendor/yahnis-elsts/plugin-update-checker` exists in the zip.
125150
4. Ensure `name_regex` in PHP matches your zip filename convention.
126151

@@ -140,11 +165,26 @@ If `plugin-update-checker` is not in `vendor/`, updater setup fails. In `WP_DEBU
140165

141166
### GitHub API rate limits
142167

143-
Unauthenticated GitHub requests are rate-limited. Keep failed lookup caching enabled in your updater flow and avoid frequent forced checks in production.
168+
The library includes built-in rate-limit mitigation:
169+
170+
- **Check interval**: By default, checks only every 6 hours.
171+
- **Throttling**: When an update is already available, checks reduce to every 72 hours.
172+
- **Token auth**: Pass a GitHub token via `auth_token` to increase limits from 60 to 5000 requests/hour.
173+
174+
If you still hit rate limits, increase `check_period` or add a GitHub token.
144175

145176
### Private repositories
146177

147-
This wrapper is designed for public GitHub releases. For private repositories, instantiate plugin-update-checker directly and configure authentication with that library.
178+
Pass your GitHub personal access token via the `auth_token` parameter:
179+
180+
```php
181+
GitHubUpdater::init(
182+
github_url: 'https://github.com/username/private-repo',
183+
plugin_file: __FILE__,
184+
plugin_slug: 'private-plugin',
185+
auth_token: MY_GITHUB_TOKEN,
186+
);
187+
```
148188

149189
## Real-World Reference
150190

0 commit comments

Comments
 (0)