wplatest/updater

一个简单轻量级的包,用于从私有仓库更新您的WordPress插件和主题。

1.4.10 2024-09-16 07:53 UTC

This package is auto-updated.

Last update: 2024-09-16 07:54:41 UTC


README

这是一个简单的WordPress插件更新器。它允许您通过WPLatest.co API检查更新,并在有更新时在WordPress管理区域显示通知。

重要

此插件更新器旨在与托管在WPLatest.co上的插件一起使用。但是,您可以修改它以与任何其他API一起使用。

最低要求

  • PHP: 8.0 或更高版本
  • WordPress: 6.0 或更高版本
  • 访问您的插件源代码。
  • 可选:Composer用于管理PHP依赖项

安装

要将此更新器集成到您的插件中,您需要通过Composer要求它或将其文件复制到您的插件中。

通过Composer

composer require wplatest/updater

手动

src目录中的文件复制到您的插件中。然后,在您的插件中要求该文件。

require_once 'path/to/updater.php';

使用方法

在您的插件中实例化PluginUpdater类,并为其提供必要的配置选项。以下是一个基本示例,您可以根据需要调整

<?php

/**
 * Plugin Name:       Example Plugin
 *
 * @package ExamplePlugin
 */

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

// Include the Composer autoloader in your plugin.
require_once 'vendor/autoload.php';

use WpLatest\Updater\PluginUpdater;

/**
 * Include the updater class.
 */
class ExamplePlugin {

	/**
	 * Base constructor.
	 */
	public function __construct() {
		add_action( 'init', array( $this, 'initialise' ) );
	}

	/**
	 * Initialize the updater.
	 */
	public function initialise() {
		$options = array(
			'file'      => __FILE__,
			'id'        => 'your-plugin-id-from-wplatest-co',
			'secret'	=> 'your-plugin-secret-from-wplatest-co',
			// Optional configuration, you don't need to set these if you're using the WPLatest.co API.
			'api_url'   => 'https://api.yoursite.com',
			// corresponds with the "Update URI" field in your plugin's header.
			'hostname'  => 'yoursite.com',
			'telemetry' => true,
		);

    	new PluginUpdater( $options );
	}
}

$wp_latest_test_plugin = new ExamplePlugin();

'your-plugin-id-from-wplatest-co'替换为WPLatest.co提供的您的插件的实际ID。