- Notifications
You must be signed in to change notification settings - Fork0
soderlind/wordpress-plugin-gitHub-updater
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A reusable WordPress plugin updater class that enables automatic updates from GitHub repositories. Built on top of theyahnis-elsts/plugin-update-checker library.
- ✅Automatic updates from GitHub releases and branches
- ✅Release asset filtering with regex patterns
- ✅Custom branch support for development/staging
- ✅Simple static factory methods for easy setup
- ✅Built-in error handling and debug logging
- ✅Flexible configuration options
Copyclass-github-plugin-updater.php to your plugin directory and include it:
if ( !class_exists('Soderlind\WordPress\GitHub_Plugin_Updater' ) ) {require_once'class-github-plugin-updater.php';}// Basic setup (most common)$updater = \Soderlind\WordPress\GitHub_Plugin_Updater::create('https://github.com/username/plugin-name',__FILE__,'plugin-name');
That's it! Your plugin will now check for updates from the specified GitHub repository.
| Parameter | Required | Description | Example |
|---|---|---|---|
github_url | Yes | GitHub repository URL | 'https://github.com/username/plugin-name' |
plugin_file | Yes | Path to main plugin file | __FILE__ |
plugin_slug | Yes | Plugin slug for WordPress | 'my-awesome-plugin' |
branch | No | Git branch to check for updates (default:'master') | 'main','develop' |
name_regex | No | Regex pattern for release assets | '/plugin-name\.zip/' |
enable_release_assets | No | Whether to enable release assets | true if name_regex provided |
Note: When
branchis set tomaster, the updater prioritizes releases and tags before falling back to the branch itself.
$updater = \Soderlind\WordPress\GitHub_Plugin_Updater::create('https://github.com/username/plugin-name',__FILE__,'plugin-name');
$updater = \Soderlind\WordPress\GitHub_Plugin_Updater::create('https://github.com/username/plugin-name',__FILE__,'plugin-name','develop'// Branch name);
$updater = \Soderlind\WordPress\GitHub_Plugin_Updater::create_with_assets('https://github.com/username/plugin-name',__FILE__,'plugin-name','/plugin-name\.zip/'// Regex pattern for zip file);
$updater =new \Soderlind\WordPress\GitHub_Plugin_Updater(['github_url' =>'https://github.com/username/plugin-name','plugin_file' =>__FILE__,'plugin_slug' =>'plugin-name','branch' =>'main','name_regex' =>'/plugin-name-v[\d\.]+\.zip/','enable_release_assets' =>true,]);
To automatically create release assets, add this workflow to your repository at.github/workflows/on-release-add.zip.yml:
name:On Release, Build release zipon:release:types:[published]jobs:build:name:Build release zipruns-on:ubuntu-latestpermissions:contents:writesteps: -name:Checkoutuses:actions/checkout@v4 -name:Build pluginrun:composer install --no-dev -name:Archive Releaseuses:thedoctor0/zip-release@b57d897cb5d60cb78b51a507f63fa184cfe35554with:type:'zip'filename:'your-plugin-name.zip'# Change thisexclusions:'*.git* .editorconfig composer* *.md package.json package-lock.json' -name:Releaseuses:softprops/action-gh-release@c95fe1489396fe8a9eb87c0abf8aa5b2ef267fdaenv:GITHUB_TOKEN:${{ secrets.GITHUB_TOKEN }}with:files:your-plugin-name.zip# Change thistag_name:${{ github.event.release.tag_name }}
- Update
filenameandfilesto match your plugin name - Modify
exclusionsto include/exclude specific files - Adjust the build step for your project needs (npm, webpack, etc.)
This creates downloadable assets at URLs like:
https://github.com/username/plugin-name/releases/latest/download/plugin-name.zip// In your main plugin filedefine('MY_PLUGIN_FILE',__FILE__ );require_onceplugin_dir_path(__FILE__ ) .'class-github-plugin-updater.php';$updater = \Soderlind\WordPress\GitHub_Plugin_Updater::create('https://github.com/myusername/my-awesome-plugin',MY_PLUGIN_FILE,'my-awesome-plugin');
$updater = \Soderlind\WordPress\GitHub_Plugin_Updater::create('https://github.com/company/enterprise-plugin',__FILE__,'enterprise-plugin','develop'// Use development branch);
$updater = \Soderlind\WordPress\GitHub_Plugin_Updater::create_with_assets('https://github.com/company/premium-plugin',__FILE__,'premium-plugin','/premium-plugin-v[\d\.]+\.zip/'// Match versioned zip files);
If you need to avoid naming conflicts, extend or wrap the class:
namespaceYourCompany\YourPlugin;class Your_Plugin_Updaterextends \Soderlind\WordPress\GitHub_Plugin_Updater {// Inherit all functionality, customize as needed}
namespaceYourCompany\YourPlugin;class Your_Plugin_Updater {private$updater;publicfunction__construct() {$this->updater = \Soderlind\WordPress\GitHub_Plugin_Updater::create('https://github.com/yourcompany/your-plugin',YOUR_PLUGIN_FILE,'your-plugin' ); }}
- Use constants for plugin file paths:
define( 'MY_PLUGIN_FILE', __FILE__ ) - Prefer static factory methods like
::create()for simpler setup - Test thoroughly with different branches and release patterns
- Document your configuration for future reference
- Consider namespacing to avoid conflicts with other plugins
The updater includes built-in error handling:
- Parameter validation on initialization
- Exception graceful handling during update checks
- Debug logging when
WP_DEBUGis enabled - Graceful degradation if updater setup fails
This updater requires theyahnis-elsts/plugin-update-checker library:
composer require yahnis-elsts/plugin-update-checker
Or download manually from:https://github.com/YahnisElsts/plugin-update-checker
MIT (same as the original library)
About
A reusable WordPress plugin updater class that enables automatic updates from GitHub repositories
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.