Skip to content

WordPress plugin to demonstrate how `GitHubUpdater` can enable WordPress to check for and update a custom plugin that's hosted in either a public or private repository on GitHub.

ryansechrest/github-updater-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Updater Demo

WordPress plugin to demonstrate how GitHubUpdater can enable WordPress to check for and update a custom plugin that's hosted in either a public or private repository on GitHub.

Getting Started

  1. Copy GitHubUpdater.php into your plugin
  2. Update namespace to match your plugin
  3. Require GitHubUpdater.php in your plugin
  4. Instantiate GitHubUpdater in your plugin

Setup

How to add and configure GitHubUpdater for your plugin.

Instantiate GitHubUpdater (Required)

Instantiate GitHubUpdater and pass in the absolute path to your root plugin file.

$gitHubUpdater = new GitHubUpdater(__FILE__);

For example, __FILE__ might resolve to:

/var/www/domains/example.org/wp-content/plugins/<pluginDir>/<pluginSlug>.php

Configure: Production Branch (Optional)

If your production branch is not the default main, then specify it:

$gitHubUpdater->setBranch('master');

Configure: Personal Access Token (Optional)

If your GitHub repository is private, then set your access token:

$gitHubUpdater->setAccessToken('github_pat_XXXXXXXXX');

It's not recommended to hardcode a token like you see above.

Either define a constant in wp-config.php:

define( 'GITHUB_ACCESS_TOKEN', 'github_pat_XXXXXXXXXX' );

And then pass in the constant:

$gitHubUpdater->setAccessToken(GITHUB_ACCESS_TOKEN);

Or save your access token in wp_options and pass it via get_option():

$gitHubUpdater->setAccessToken(get_option('github_access_token'));

Configure: Tested WordPress Version (Optional)

Specify the highest version of WordPress you've tested your plugin on:

$gitHubUpdater->setTestedWpVersion('6.5.2');

This only impacts the compatibility message on Dashboard > Updates.

Add GitHubUpdater (Required)

Add all necessary hooks to WordPress to keep your plugin updated moving forward:

$gitHubUpdater->add();

This should be the last method call after GitHubUpdater has been configured.

If you want a deep dive into how GitHubUpdater works, check out this blog post.

About

WordPress plugin to demonstrate how `GitHubUpdater` can enable WordPress to check for and update a custom plugin that's hosted in either a public or private repository on GitHub.

Topics

Resources

Stars

Watchers

Forks

Languages