automagicwp/updater 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

automagicwp/updater

最新稳定版本:3.1.0

Composer 安装命令:

composer require automagicwp/updater

包简介

A simple and lightweight package to update your WordPress plugins from AutomagicWP.

README 文档

README

A simple and lightweight updater for WordPress plugins hosted on AutomagicWP. It hooks into WordPress's built-in update mechanism to check for new versions and display the standard update notice in the admin area.

Important

This updater requires your plugin to be hosted on AutomagicWP.com. Your plugin header must include Update URI: https://www.automagicwp.com.

Minimum requirements

  • PHP: 8.0 or later
  • WordPress: 6.0 or later
  • Access to your plugin's source code.
  • Optional: Composer for managing PHP dependencies

Installation

Via Composer

composer require automagicwp/updater

Manual

Copy the file in src/ into your plugin and require it:

require_once 'path/to/PluginUpdater.php';

Usage

Instantiate PluginUpdater inside your plugin. The defaults point at automagicwp.com so you only need to provide file and id for the standard setup:

<?php
/**
 * Plugin Name: My Plugin
 * Version:     1.0.0
 * Update URI:  https://www.automagicwp.com
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

require_once __DIR__ . '/vendor/autoload.php';

use AutomagicWP\Updater\PluginUpdater;

add_action( 'init', function () {
    new PluginUpdater( array(
        'file'   => __FILE__,
        'id'     => 'plugin_abc123',   // Plugin ID from the AutomagicWP dashboard
        'secret' => 'your-api-key',    // Optional: required for private plugins
    ) );
} );

All options

Option Required Default Description
file Yes Path to the main plugin file (__FILE__)
id Yes Plugin ID from the AutomagicWP dashboard
secret No API key or license key. Required for private plugins and white-label branding.
api_url No https://www.automagicwp.com/api/v1/plugin/update Update check endpoint
config_url No https://www.automagicwp.com/api/v1/plugin/config Branding config endpoint
hostname No automagicwp.com Must match the Update URI header
telemetry No true Send anonymous site info (WP version, PHP version) with update checks

Replace plugin_abc123 with the Plugin ID shown in your AutomagicWP dashboard under Settings.

White-label branding

Agencies distributing a single plugin to multiple client sites can create licenses in the AutomagicWP dashboard (Settings → White-label Licenses). Each license has:

  • Its own API key (revocable per site)
  • Client name — shown in the plugin admin UI instead of the canonical plugin name
  • Primary colour / foreground colour — brand colours for the admin UI
  • Metadata — free-form JSON for any extra fields (logo URL, support email, feature flags, etc.)

Fetching branding config

Pass the license key as the secret option, then call get_config() anywhere in your plugin:

$updater = new PluginUpdater( array(
    'file'   => __FILE__,
    'id'     => 'plugin_abc123',
    'secret' => get_option( 'my_plugin_license_key' ),
) );

$config = $updater->get_config();

if ( $config ) {
    $client_name   = $config->clientName            ?? 'My Plugin';
    $primary_color = $config->primaryColor          ?? '#2563eb';
    $fg_color      = $config->primaryForegroundColor ?? '#ffffff';

    // Access free-form metadata
    $logo_url      = $config->metadata->logo_url      ?? '';
    $support_email = $config->metadata->support_email ?? '';
    $report_from   = $config->metadata->report_from   ?? '';
    $report_footer = $config->metadata->report_footer ?? '';

    // Feature flags stored in metadata
    $features      = (array) ( $config->metadata->features ?? array() );
    $multi_country = $features['multi_country'] ?? false;
}

Response shape

{
  "clientName": "Acme Corp",
  "primaryColor": "#1A56DB",
  "primaryForegroundColor": "#ffffff",
  "metadata": {
    "logo_url": "https://acme.com/logo.svg",
    "support_email": "help@acme.com",
    "report_from": "Acme SEO <noreply@acme.com>",
    "report_footer": "Powered by Acme · acme.com",
    "features": {
      "multi_country": true,
      "vehicle_compatibility": false,
      "content_creation": false
    },
    "countries": {
      "NL": { "weight": 1.0, "frequency": "daily" },
      "DE": { "weight": 0.8, "frequency": "weekly" }
    }
  }
}

All fields are nullable — always provide defaults in your plugin code.

Caching

get_config() caches the response in a WordPress transient for 5 minutes to avoid a remote call on every admin page load. To force a fresh fetch (e.g. after saving a settings page):

$config = $updater->get_config( force: true );

Providing a license key settings field

Your plugin's settings page should let the site owner paste their license key:

add_action( 'admin_init', function () {
    register_setting( 'my_plugin_settings', 'my_plugin_license_key' );

    add_settings_field(
        'license_key',
        'License Key',
        function () {
            $key = get_option( 'my_plugin_license_key', '' );
            echo '<input type="password" name="my_plugin_license_key"
                         value="' . esc_attr( $key ) . '" class="regular-text">';
        },
        'my-plugin',
        'my_plugin_license_section'
    );
} );

统计信息

  • 总下载量: 35
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2026-02-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固