WordPress Plugin Updates From GitHub Releases

Your own WordPress plugins never show updates when they live on GitHub instead of WordPress.org. Every new version means downloading a zip, uploading it by hand on each client site and hoping nobody skips one. If a GitHub Actions workflow already builds a release zip for every tag, WordPress can pick that zip up by itself.

This snippet connects the two. WordPress 5.8 added the Update URI plugin header and the update_plugins_{$hostname} filter. Any plugin with Update URI: https://github.com/owner/repo then gets the normal “There is a new version available” notice, the Update now link and auto-updates, all fed from that repo’s latest GitHub release. You don’t need an updater library or a separate update server.

The snippet

Put it in an mu-plugin, a small helper plugin or a Scripts Organizer PHP block. It runs on every site that should receive the updates. It is not part of the plugin being updated, so one copy covers all your GitHub-hosted plugins.

<?php
/**
 * Updates for plugins whose header says: Update URI: https://github.com/owner/repo
 * Reads the latest GitHub release and uses its <plugin-folder>.zip asset.
 */

add_filter( 'update_plugins_github.com', 'dpc_github_release_update', 10, 4 );

function dpc_github_release_update( $update, $plugin_data, $plugin_file, $locales ) {
    if ( $update ) {
        return $update; // Another handler already answered for this plugin.
    }

    $repo = dpc_github_repo_from_uri( (string) ( $plugin_data['UpdateURI'] ?? '' ) );
    $slug = dirname( (string) $plugin_file );
    if ( '' === $repo || '.' === $slug ) {
        return $update; // Unknown repo, or a single-file plugin without a folder.
    }

    $release = dpc_github_latest_release( $repo );
    if ( empty( $release['tag_name'] ) ) {
        return $update;
    }

    $version = ltrim( $release['tag_name'], 'vV' );
    if ( ! preg_match( '/^\d+(\.\d+){0,3}([.-][0-9A-Za-z.-]+)?$/', $version ) ) {
        return $update;
    }

    // Only accept <slug>.zip uploaded to this exact repo's releases.
    $prefix  = strtolower( 'https://github.com/' . $repo . '/releases/download/' );
    $package = '';
    foreach ( $release['assets'] as $asset ) {
        if ( $slug . '.zip' === $asset['name'] && str_starts_with( strtolower( $asset['url'] ), $prefix ) ) {
            $package = $asset['url'];
            break;
        }
    }
    if ( '' === $package ) {
        return $update;
    }

    return array(
        'slug'    => $slug,
        'version' => $version,
        'url'     => esc_url_raw( 'https://github.com/' . $repo ),
        'package' => esc_url_raw( $package ),
    );
}

function dpc_github_repo_from_uri( string $uri ): string {
    $parts = wp_parse_url( $uri );
    if ( empty( $parts['host'] ) || 'github.com' !== strtolower( $parts['host'] ) ) {
        return '';
    }
    $path = trim( (string) ( $parts['path'] ?? '' ), '/' );

    return preg_match( '#^[A-Za-z0-9-]+/[A-Za-z0-9._-]+$#', $path ) ? $path : '';
}

function dpc_github_latest_release( string $repo ): array {
    $key    = 'dpc_gh_' . md5( strtolower( $repo ) );
    $cached = get_site_transient( $key );
    if ( is_array( $cached ) ) {
        return $cached;
    }

    $headers = array(
        'Accept'               => 'application/vnd.github+json',
        'X-GitHub-Api-Version' => '2022-11-28',
    );
    if ( defined( 'DPC_GITHUB_TOKEN' ) && DPC_GITHUB_TOKEN ) {
        $headers['Authorization'] = 'Bearer ' . DPC_GITHUB_TOKEN;
    }

    $response = wp_remote_get(
        'https://api.github.com/repos/' . $repo . '/releases/latest',
        array( 'timeout' => 10, 'headers' => $headers )
    );

    $release = array();
    if ( ! is_wp_error( $response ) && 200 === wp_remote_retrieve_response_code( $response ) ) {
        $body = json_decode( wp_remote_retrieve_body( $response ), true );
        if ( is_array( $body ) && ! empty( $body['tag_name'] ) && empty( $body['draft'] ) && empty( $body['prerelease'] ) ) {
            $assets = array();
            foreach ( (array) ( $body['assets'] ?? array() ) as $asset ) {
                $assets[] = array(
                    'name' => (string) ( $asset['name'] ?? '' ),
                    'url'  => (string) ( $asset['browser_download_url'] ?? '' ),
                );
            }
            $release = array(
                'tag_name' => (string) $body['tag_name'],
                'assets'   => $assets,
            );
        }
    }

    // Cache hits for 6 hours, failures for 1 hour, to stay under GitHub's rate limit.
    set_site_transient( $key, $release, $release ? 6 * HOUR_IN_SECONDS : HOUR_IN_SECONDS );

    return $release;
}

Then add the header to each plugin you want updated. The repo name and the plugin’s folder name should match, because the snippet looks for <folder>.zip:

<?php
/**
 * Plugin Name: Acme Widget
 * Version:     1.2.0
 * Update URI:  https://github.com/acme/acme-widget
 */

The release zip (GitHub Actions)

WordPress needs a zip whose top-level folder is the plugin slug. GitHub’s automatic “Source code” zip uses repo-tag as the folder, which installs the update as a second copy of the plugin. So upload a proper asset instead. This workflow builds one on every v* tag:

name: Release zip
on:
  push:
    tags: ['v*']
permissions:
  contents: write
jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm
      - run: npm ci
      - run: npm run build
      - name: Build plugin zip
        run: |
          SLUG="${GITHUB_REPOSITORY#*/}"
          mkdir -p "dist/$SLUG"
          rsync -a --exclude='.git*' --exclude=node_modules --exclude=dist ./ "dist/$SLUG/"
          cd dist && zip -rq "$SLUG.zip" "$SLUG"
      - name: Publish release
        env:
          GH_TOKEN: ${{ github.token }}
        run: gh release create "$GITHUB_REF_NAME" "dist/${GITHUB_REPOSITORY#*/}.zip" --title "$GITHUB_REF_NAME" --generate-notes

For more on the release step itself, see GitHub Action to create a release. If the build uses @wordpress/scripts, WordPress Enqueue Script Example for wp-scripts Builds covers loading the compiled files.

How it works

  • When WordPress checks for plugin updates, it reads each plugin’s Update URI. Plugins pointing to a host other than WordPress.org are sent to update_plugins_{hostname}, here update_plugins_github.com.
  • dpc_github_latest_release() calls GitHub’s releases/latest endpoint. That endpoint skips drafts and pre-releases. The function keeps only the tag and asset names and caches them in a site transient.
  • The tag (v1.2.0 → 1.2.0) becomes the new version. Core compares it with the installed Version header and shows the update only when it is higher.
  • The download URL is accepted only if it is named <slug>.zip and sits under https://github.com/owner/repo/releases/download/. A compromised or misconfigured release can’t point WordPress at a random host.

Customise it

  • Rate limits: unauthenticated API calls are limited to 60 per hour per IP. On shared hosting, add define( 'DPC_GITHUB_TOKEN', '...' ); to wp-config.php with a fine-grained, read-only token.
  • Cache time: change 6 * HOUR_IN_SECONDS. To force a fresh check, delete the dpc_gh_* site transients (for example wp transient delete --all --network on multisite, or without --network on single sites).
  • Different asset name: change the $slug . '.zip' comparison, but keep the URL prefix check.

Gotchas

  • Public repos only. Downloading assets from a private repo needs the token on the download request too, plus a redirect to signed S3 URLs. That is out of scope here.
  • The “View version details” link still asks WordPress.org about the plugin, so for these plugins it shows an error. The update itself works.
  • Tag and header must agree. If you tag v1.3.0 but forget to bump Version: in the plugin, the site keeps offering the same update after it installs.

Prefer not to maintain this yourself? Hoster ships updates for private and client plugins from your own site and pulls the latest release from GitHub.

Snippet poll. Should this snippet be in the Scripts Organizer library for one-click import? 10 votes put it there.

0 of 10 votes

// newsletter

Three tested WordPress snippets a week

Blocks, security, performance, Tailwind, PHP and React. Copy, paste, ship. You’ll also get DPlugins product updates. No spam, and you can unsubscribe anytime.

// newsletter

Three tested WordPress snippets a week

Blocks, security, performance, Tailwind, PHP and React. Copy, paste, ship. You'll also get DPlugins product updates. No spam, and you can unsubscribe anytime.