Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A reusable WordPress plugin updater class that enables automatic updates from GitHub repositories

NotificationsYou must be signed in to change notification settings

soderlind/wordpress-plugin-gitHub-updater

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

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.

Features

  • 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

Table of Contents

Quick Start

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.

Configuration

Parameters

ParameterRequiredDescriptionExample
github_urlYesGitHub repository URL'https://github.com/username/plugin-name'
plugin_fileYesPath to main plugin file__FILE__
plugin_slugYesPlugin slug for WordPress'my-awesome-plugin'
branchNoGit branch to check for updates (default:'master')'main','develop'
name_regexNoRegex pattern for release assets'/plugin-name\.zip/'
enable_release_assetsNoWhether to enable release assetstrue if name_regex provided

Note: Whenbranch is set tomaster, the updater prioritizes releases and tags before falling back to the branch itself.

Initialization Methods

1. Basic Setup

$updater = \Soderlind\WordPress\GitHub_Plugin_Updater::create('https://github.com/username/plugin-name',__FILE__,'plugin-name');

2. Custom Branch

$updater = \Soderlind\WordPress\GitHub_Plugin_Updater::create('https://github.com/username/plugin-name',__FILE__,'plugin-name','develop'// Branch name);

3. With Release Assets

$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);

4. Full Configuration

$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,]);

GitHub Workflow Setup

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 }}

Customization Tips

  • Updatefilename andfiles to match your plugin name
  • Modifyexclusions to 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

Usage Examples

Real-World Implementations

Basic Plugin Setup

// 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');

Development Branch Updates

$updater = \Soderlind\WordPress\GitHub_Plugin_Updater::create('https://github.com/company/enterprise-plugin',__FILE__,'enterprise-plugin','develop'// Use development branch);

Release Assets with Pattern Matching

$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);

Advanced Usage

Custom Class Names

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}

Plugin-Specific Wrapper

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'        );    }}

Best Practices

  • 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

Error Handling

The updater includes built-in error handling:

  • Parameter validation on initialization
  • Exception graceful handling during update checks
  • Debug logging whenWP_DEBUG is enabled
  • Graceful degradation if updater setup fails

Dependencies

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

License

MIT (same as the original library)

About

A reusable WordPress plugin updater class that enables automatic updates from GitHub repositories

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp