awesome9 / 更新

WordPress 更新管理器。

安装: 12

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

语言:Shell

1.0.4 2024-09-05 18:06 UTC

This package is auto-updated.

Last update: 2024-09-05 18:09:13 UTC


README

Awesome9 Latest Stable Version PHP from Packagist Total Downloads License

📃 关于更新

这。这个包提供在WordPress插件中运行更新例程的便捷性。它提供检查当前已安装插件版本、确定需要应用哪些更新以及按顺序应用这些更新的方法。

💾 安装

composer require awesome9/updates

🕹 使用

首先,您需要创建一个扩展 Updates 的具体类。

您需要创建一个新的类,该类扩展 Updates 类并实现抽象方法。

use Awesome9\Updates\Updates;

class MyPluginUpdates extends Updates {

    public function get_updates(): array {
        return [
            '1.0.1' => '/updates/update-1.0.1.php',
            '1.0.2' => '/updates/update-1.0.2.php',
        ];
    }

    public function get_folder(): string {
        return plugin_dir_path( __FILE__ ) . 'updates/';
    }

    public function get_version(): string {
        return '1.0.2'; // Replace with your plugin's current version
    }

    public function get_option_name(): string {
        return 'awesome9_plugin_version'; // Option name to store the version in the database
    }
}

现在,在您插件的主文件中,初始化更新管理器并绑定钩子

$my_plugin_updates = new MyPluginUpdates();
$my_plugin_updates->hooks();

假设您的插件结构如下所示

my-plugin/
└── updates/
   ├── update-1.1.0.php
   └── update-1.1.1.php

更新文件可能看起来像这样

<?php
/**
 * Update routine
 *
 * @since 1.1.0
 */

/**
 * Update new roles and capabilities
 *
 * @since 1.1.0
 *
 * @return void
 */
function awesome9_update_1_1_0_remove_role() {
	remove_role( 'awesome9_manager' );
	remove_role( 'awesome9_employee' );
}

awesome9_update_1_1_0_remove_role();

📖 更新日志

查看更新日志文件