affinite/updater

Affinite plugin updater for WordPress plugins (custom update server).

Installs: 4

Dependents: 0

Suggesters: 0

Security: 0

pkg:composer/affinite/updater

1.0.3 2025-12-24 13:42 UTC

This package is auto-updated.

Last update: 2025-12-24 13:42:43 UTC


README

A small WordPress-only library that enables updates for a plugin from a custom update server.

Requirements

  • PHP 8.0+
  • WordPress (admin context)

Installation

Packagist / private registry

composer require affinite/updater

Direct VCS repository

{
  "repositories": [
    { "type": "vcs", "url": "git@github.com:YOUR_ORG/affinite-updater.git" }
  ],
  "require": {
    "affinite/updater": "^1.0"
  }
}

Usage (inside your plugin)

Add this code to your plugin's main file:

<?php
use Affinite\Updater\Updater;

try {
    $plugin_slug = dirname( plugin_basename( __FILE__ ) );
    new Updater( $plugin_slug );
} catch ( \Exception $e ) {
    if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
        error_log( 'AffiniteUpdater initialization failed: ' . $e->getMessage() );
    }
}

The plugin_slug is automatically detected from the plugin folder name, so it works regardless of your main file name.

Plugin file detection

The updater automatically finds the plugin main file regardless of its name. It searches in the following order:

  1. Standard format: {slug}/{slug}.php (e.g., my-plugin/my-plugin.php)
  2. Index file: {slug}/index.php (if it contains a valid WordPress plugin header)
  3. WordPress plugin registry: Searches through all registered plugins to find the one matching the folder name

This means you can use any file name for your plugin main file, as long as:

  • The plugin folder name matches the slug you pass to Updater
  • The main file contains a valid WordPress plugin header (Plugin Name:)

Force check for updates

By default, update checks are cached for 1 hour. To force a fresh check (ignoring cache), use the forceCheck() method:

<?php
use Affinite\Updater\Updater;

$updater = new Updater('my-plugin-slug');

// Force a fresh update check (ignores cache)
$updateData = $updater->forceCheck();

if ($updateData) {
    // Process update data...
    echo 'Latest version: ' . $updateData->version;
}

Update server response

The update server is expected to return JSON for ?plugin=<slug> similar to:

{
  "name": "My Plugin",
  "version": "1.2.3",
  "author": "Affinite",
  "author_profile": "https://example.com",
  "requires": "6.0",
  "tested": "6.6",
  "requires_php": "8.0",
  "download_url": "https://example.com/my-plugin.zip",
  "sections": {
    "description": "…",
    "installation": "…",
    "changelog": "…"
  },
  "banners": {
    "low": "https://example.com/banner-772x250.jpg",
    "high": "https://example.com/banner-1544x500.jpg"
  },
  "is_valid_license": true
}

License

MIT. See LICENSE.